source: java2python/geniuswebtranslator/geniuswebsrc/geniusweb/bidspace/AllBidsList.java@ 874

Last change on this file since 874 was 854, checked in by wouter, 7 months ago

#264 more fixes

File size: 2.0 KB
Line 
1package geniusweb.bidspace;
2
3import java.math.BigInteger;
4import java.util.ArrayList;
5import java.util.HashMap;
6import java.util.List;
7import java.util.Map;
8import java.util.stream.Collectors;
9
10import org.eclipse.jdt.annotation.NonNull;
11
12import geniusweb.issuevalue.Bid;
13import geniusweb.issuevalue.Domain;
14import geniusweb.issuevalue.Value;
15import tudelft.utilities.immutablelist.AbstractImmutableList;
16import tudelft.utilities.immutablelist.ImmutableList;
17import tudelft.utilities.immutablelist.Outer;
18
19/**
20 * A list containing all complete bids in the space. This is an
21 * {@link ImmutableList} so it can contain all bids without pre-computing them.
22 *
23 */
24public class AllBidsList extends AbstractImmutableList<@NonNull Bid> {
25
26 private final @NonNull List<@NonNull String> issues = new ArrayList<>();
27 private final @NonNull Outer<@NonNull ? extends Value> allValuePermutations;
28
29 /**
30 * This object contains s list containing all bids in the space. This is an
31 * ImmutableList so it can contain all bids without pre-computing them.
32 *
33 * @param domain the {@link Domain}
34 *
35 */
36 public AllBidsList(@NonNull Domain domain) {
37 if (domain == null)
38 throw new IllegalArgumentException("domain=null");
39 issues.addAll(domain.getIssuesValues().keySet());
40
41 //#PY values = [domain.getValues(issue) for issue in issues]
42 final @NonNull List<@NonNull ImmutableList<@NonNull Value>> values = issues
43 .stream().map(issue -> domain.getValues(issue))
44 .collect(Collectors.toList());
45
46 allValuePermutations = new Outer<@NonNull Value>(values);
47 }
48
49 @Override
50 public @NonNull Bid get(@NonNull BigInteger index) {
51 final @NonNull ImmutableList<@NonNull ? extends Value> nextValues = allValuePermutations
52 .get(index);
53
54 final @NonNull Map<@NonNull String, @NonNull Value> issueValues = new HashMap<>();
55 for (int n = 0; n < issues.size(); n = n + 1) {
56 issueValues.put(issues.get(n),
57 nextValues.get(BigInteger.valueOf(n)));
58 }
59 return new Bid(issueValues);
60 }
61
62 @Override
63 public @NonNull BigInteger size() {
64 return allValuePermutations.size();
65 }
66
67}
Note: See TracBrowser for help on using the repository browser.