Changeset 4 for issuevalue/src/main/java
- Timestamp:
- 09/18/19 10:00:22 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issuevalue/src/main/java/geniusweb/issuevalue/Bid.java
r1 r4 3 3 import java.util.Collections; 4 4 import java.util.HashMap; 5 import java.util.HashSet; 5 6 import java.util.Map; 6 7 import java.util.Set; … … 40 41 41 42 /** 43 * Makes partial bid with just 1 issue and value. 44 * 45 * @param issue the issue name 46 * @param value the {@link Value} 47 */ 48 public Bid(String issue, Value value) { 49 if (issue == null || value == null) { 50 throw new NullPointerException("issue and value must be not =null"); 51 } 52 53 issuevalues = new HashMap<>(); 54 issuevalues.put(issue, value); 55 } 56 57 /** 42 58 * @param issue 43 59 * @return the value for the given issue, or null if there is no value for … … 59 75 public Set<String> getIssues() { 60 76 return Collections.unmodifiableSet(issuevalues.keySet()); 77 } 78 79 /** 80 * Merges this partial bid with another partial bid. 81 * 82 * @param otherbid another partial bid. 83 * @return a bid with the combined values of both partial bids. 84 * @throws IllegalArgumentException if issues overlap. 85 */ 86 public Bid merge(Bid otherbid) { 87 Set<String> ourissues = new HashSet<>(issuevalues.keySet()); 88 ourissues.retainAll(otherbid.getIssues()); 89 if (!ourissues.isEmpty()) { 90 throw new IllegalArgumentException( 91 "Otherbid contains issues that are already set:" 92 + ourissues); 93 } 94 HashMap<String, Value> newvalues = new HashMap<>(issuevalues); 95 newvalues.putAll(otherbid.issuevalues); 96 return new Bid(newvalues); 97 61 98 } 62 99
Note:
See TracChangeset
for help on using the changeset viewer.