/**
   * Sets the count for a particular value in the specified {@code Categorical} distribution.
   *
   * @param key the key of the {@code Categorical} being modified
   * @param value the value whose count is being set
   * @param count the new count of the value
   */
  public void setCount(K key, V value, int count) {
    Guard.argumentsAreNotNull(key, value);
    Guard.argumentIsNonNegative(count);

    int change = count - getCountGiven(key, value);
    totals.setCount(value, totals.getCount(value) + change);
    getCategorical(key).setCount(value, count);
  }
Beispiel #2
0
  /**
   * Gets a randomly chosen open tile on the {@code World} within the given bounds. If after 100
   * randomly selected tiles are closed, then each tile will be checked and the first open tile
   * found is returned. If the entire {@code World} is closed, null is returned.
   *
   * @param dice the random number generator used to randomly select tiles
   * @param topLeft the bounds upper-left most value
   * @param bottomRight the bounds bottom-right most value
   * @return a randomly chosen open tile
   */
  public final Coordinate getOpenTile(Dice dice, Coordinate topLeft, Coordinate bottomRight) {
    Guard.argumentsAreNotNull(topLeft, bottomRight);

    return getOpenTile(dice, topLeft.x(), topLeft.y(), bottomRight.x(), bottomRight.y());
  }
  /**
   * Increments the count of a value given a key.
   *
   * @param key the key of the {@code Categorical} being modified
   * @param value the value to increment
   */
  public void incrementCount(K key, V value) {
    Guard.argumentsAreNotNull(key, value);

    totals.incrementCount(value);
    getCategorical(key).incrementCount(value);
  }
  /**
   * Returns the count of a value given a particular {@code Categorical}.
   *
   * @param key the key to the {@code Categorical} distribution being queried
   * @param value the value whose count is being queried
   * @return the count of value given the key
   */
  public int getCountGiven(K key, V value) {
    Guard.argumentsAreNotNull(key, value);

    return frequencies.containsKey(key) ? frequencies.get(key).getCount(value) : 0;
  }