Skip to content

Changing the content of a given bid

Taha Doğan Güneş edited this page Oct 24, 2017 · 1 revision

To change the content of a bid, use putValue method:

     /**
     * Make a new Bid as the current bid but with the value of the issue with
     * the given issueID to the given value.
     *
     * @param issueId
     *            unique ID of an issue.
     * @param pValue
     *            value of the issue.
     */
    public Bid putValue(int issueId, Value pValue)

Please notice that putValue returns a new bid with the given value changed. The old bid stays unchanged.

For example, to assign the value of the first issue to a random value:

// Modifying a bid
Bid bid = offer.getBid();
Bid newBid = null;

// Getting the first issue
Issue issue = bid.getIssues().get(0);

// Getting issue number
final int issueNumber = issue.getNumber();

// Determining issue type
switch (issue.getType()) {
    case REAL:
        IssueReal issueReal = (IssueReal) issue;
        double upperRealBound = issueReal.getUpperBound();
        double lowerRealBound = issueReal.getLowerBound();

        // accessing to the old value
        // ValueReal valueReal = (ValueReal) bid.getValue(issueNumber);

        // generating a new random value
        double randomReal = ThreadLocalRandom.current().nextDouble(lowerRealBound, upperRealBound);
        ValueReal valueReal = new ValueReal(randomReal);
        newBid = bid.putValue(issue.getNumber(), valueReal);
        break;
    case INTEGER:
        IssueInteger issueInteger = (IssueInteger) issue;
        int upperIntegerBound = issueInteger.getUpperBound();
        int lowerIntegerBound = issueInteger.getLowerBound();

        // accessing to the old value
        // ValueInteger valueInteger = (ValueInteger) bid.getValue(issueNumber);

        // generating a new random value
        int randomInteger = ThreadLocalRandom.current().nextInt(lowerIntegerBound, upperIntegerBound);
        ValueInteger valueInteger = new ValueInteger(randomInteger);
        newBid = bid.putValue(issueNumber, valueInteger);

        break;

    case DISCRETE:
        IssueDiscrete issueDiscrete = (IssueDiscrete) issue;
        List<ValueDiscrete> allValues = issueDiscrete.getValues();

        // accessing to the old value
        // ValueDiscrete valueDiscrete = (ValueDiscrete) bid.getValue(issueNumber);

        // generating a new random value
        Collections.shuffle(allValues);
        ValueDiscrete valueDiscrete = allValues.get(0);

        newBid = bid.putValue(issueNumber, valueDiscrete);
        break;
}
Clone this wiki locally