Changeset 4 for issuevalue/src/main


Ignore:
Timestamp:
09/18/19 10:00:22 (5 years ago)
Author:
bart
Message:

Faster example parties

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issuevalue/src/main/java/geniusweb/issuevalue/Bid.java

    r1 r4  
    33import java.util.Collections;
    44import java.util.HashMap;
     5import java.util.HashSet;
    56import java.util.Map;
    67import java.util.Set;
     
    4041
    4142        /**
     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        /**
    4258         * @param issue
    4359         * @return the value for the given issue, or null if there is no value for
     
    5975        public Set<String> getIssues() {
    6076                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
    6198        }
    6299
Note: See TracChangeset for help on using the changeset viewer.