コード例 #1
0
  public ShipStrategyType getOutputShipStrategy(int outputNum) {
    // check how many outputs are encoded in the config
    final int outputCnt = this.config.getInteger(OUTPUTS_NUM, -1);
    if (outputCnt < 1) {
      throw new CorruptConfigurationException(
          "No output ship strategies are specified in the configuration.");
    }

    // sanity range checks
    if (outputNum < 0 || outputNum >= outputCnt) {
      throw new IllegalArgumentException("Invalid index for output shipping strategy.");
    }

    final int strategy = this.config.getInteger(OUTPUT_SHIP_STRATEGY_PREFIX + outputNum, -1);
    if (strategy == -1) {
      throw new CorruptConfigurationException(
          "No output shipping strategy in configuration for output " + outputNum);
    } else if (strategy < 0 || strategy >= ShipStrategyType.values().length) {
      throw new CorruptConfigurationException(
          "Illegal output shipping strategy in configuration for output "
              + outputNum
              + ": "
              + strategy);
    } else {
      return ShipStrategyType.values()[strategy];
    }
  }
コード例 #2
0
 public void addOutputShipStrategy(ShipStrategyType strategy) {
   final int outputCnt = this.config.getInteger(OUTPUTS_NUM, 0);
   this.config.setInteger(OUTPUT_SHIP_STRATEGY_PREFIX + outputCnt, strategy.ordinal());
   this.config.setInteger(OUTPUTS_NUM, outputCnt + 1);
 }