source: bidspace/src/main/java/geniusweb/bidspace/AllBidsList.java@ 51

Last change on this file since 51 was 51, checked in by ruud, 22 months ago

Fixed small issues in domaineditor.

File size: 1.7 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.getIssues());
38
39 List<ImmutableList<Value>> values = issues.stream()
40 .map(issue -> domain.getValues(issue))
41 .collect(Collectors.toList());
42
43 allValuePermutations = new Outer<Value>(values);
44 }
45
46 @Override
47 public Bid get(BigInteger index) {
48 ImmutableList<? extends Value> nextValues = allValuePermutations
49 .get(index);
50
51 Map<String, Value> issueValues = new HashMap<>();
52 for (int n = 0; n < issues.size(); n++) {
53 issueValues.put(issues.get(n),
54 nextValues.get(BigInteger.valueOf(n)));
55 }
56 return new Bid(issueValues);
57 }
58
59 @Override
60 public BigInteger size() {
61 return allValuePermutations.size();
62 }
63
64}
Note: See TracBrowser for help on using the repository browser.