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

Last change on this file since 744 was 744, checked in by wouter, 11 months ago

#254 PyProgram now throws TranslationException. Ignore broken test in tudunit-t

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