Example #1
0
 @SuppressWarnings({
   "rawtypes",
   "unchecked"
 }) // I can't parameterize this either; it scares the compiler
 private static <T extends VariantData<U, T, ?>, U extends CatalogType> T getItemData(
     ItemStack item, Class<T> type, BiMap<U, Integer> map) {
   int damage = item.getDurability();
   if (!map.containsValue(damage)) {
     throw new UnsupportedOperationException();
   }
   // no idea why a typecast is necessary here but excluding it makes javac angry
   @SuppressWarnings("RedundantCast")
   T data =
       (T)
           Pore.getGame()
               .getRegistry()
               .createItemBuilder()
               .itemType(MaterialConverter.asItem(item.getType()))
               .quantity(1)
               .build()
               .getOrCreate(type)
               .get();
   data.type().set(map.inverse().get(damage));
   return data;
 }
 @Override
 public boolean add(TravelingItem item) {
   if (delegate.containsValue(item)) return false;
   item.setContainer(container);
   delegate.put(item.id, item);
   return true;
 }
  public String unmap(String typeName) {
    if (classNameBiMap == null || classNameBiMap.isEmpty()) {
      return typeName;
    }

    if (classNameBiMap.containsValue(typeName)) {
      return classNameBiMap.inverse().get(typeName);
    }
    int dollarIdx = typeName.indexOf('$');
    String realType = dollarIdx > -1 ? typeName.substring(0, dollarIdx) : typeName;
    String subType = dollarIdx > -1 ? typeName.substring(dollarIdx + 1) : "";

    String result =
        classNameBiMap.containsValue(realType)
            ? classNameBiMap.inverse().get(realType)
            : mcpNameBiMap.containsValue(realType)
                ? mcpNameBiMap.inverse().get(realType)
                : realType;
    result = dollarIdx > -1 ? result + "$" + subType : result;
    return result;
  }
  /**
   * Generates random squares for the pieces of the provided tablebase.
   *
   * @param tablebase computerized database containing all possible legal chess positions and their
   *     evaluations, given the set of specific chess pieces
   * @return the bidirectional map from the pieces present in this chess position, to the squares
   *     they occupy
   */
  static BiMap<Piece, Square> generateRandomSquaresForPieces(Tablebase tablebase) {
    BiMap<Piece, Square> piecesWithSquares = EnumBiMap.create(Piece.class, Square.class);
    List<Piece> pieces = tablebase.getAllPieces();

    MersenneTwisterFast numberGenerator = new MersenneTwisterFast();

    Square randSquare = null;
    for (Piece piece : pieces) {
      do {
        if (piece.getPieceType() == PieceType.PAWN) {
          int pRand = numberGenerator.nextInt(Squares.PAWN_SQUARES.numberOfSquares());
          randSquare = Squares.PAWN_SQUARES.getSquaresAsList().get(pRand);
        } else {
          int allRand = numberGenerator.nextInt(Squares.ALL_SQUARES.numberOfSquares());
          randSquare = Squares.ALL_SQUARES.getSquaresAsList().get(allRand);
        }
      } while (piecesWithSquares.containsValue(randSquare));

      piecesWithSquares.put(piece, randSquare);
    }
    return piecesWithSquares;
  }
  private void dumpRegion(Region r, Appendable out) throws IOException {
    if (regionMap.containsValue(r)) {
      out.append(regionMap.inverse().get(r));

    } else if (r.isFalse()) {
      out.append("FALSE");

    } else if (r.isTrue()) {
      out.append("TRUE");

    } else {
      Triple<Region, Region, Region> triple = delegate.getIfThenElse(r);
      String predName = regionMap.inverse().get(triple.getFirst());

      Region trueBranch = triple.getSecond();
      Region falseBranch = triple.getThird();

      if (trueBranch.isFalse()) {
        assert !falseBranch.isFalse();
        // only falseBranch is present
        out.append("!").append(predName).append(" & ");
        dumpRegion(falseBranch, out);

      } else if (falseBranch.isFalse()) {
        // only trueBranch is present
        out.append(predName).append(" & ");
        dumpRegion(trueBranch, out);

      } else {
        // both branches present
        out.append("((").append(predName).append(" & ");
        dumpRegion(trueBranch, out);
        out.append(") | (").append("!").append(predName).append(" & ");
        dumpRegion(falseBranch, out);
        out.append("))");
      }
    }
  }
Example #6
0
 public boolean containsOid(long oid) {
   return objectsToCommitFirst.containsValue(oid) || objectsToCommitSecond.containsValue(oid);
 }
Example #7
0
 public Integer convertNewCfId(UUID newCfId) {
   return oldCfIdMap.containsValue(newCfId) ? oldCfIdMap.inverse().get(newCfId) : null;
 }
 public boolean uuidExists(final UUID uuid) {
   return uuidMap.containsValue(uuid);
 }
Example #9
0
  public static BiMap<Integer, Integer> getAsciTuneMap() {
    int[][] keyboardArrangement = {
      // bottommest row
      {
        KeyEvent.VK_Z,
        KeyEvent.VK_X,
        KeyEvent.VK_C,
        KeyEvent.VK_V,
        KeyEvent.VK_B,
        KeyEvent.VK_N,
        KeyEvent.VK_M,
        KeyEvent.VK_COMMA,
        KeyEvent.VK_PERIOD,
        KeyEvent.VK_SLASH,
        KeyEvent.VK_BACK_SLASH,
        KeyEvent.VK_BACK_SPACE,
      },
      // middle row
      {
        KeyEvent.VK_A,
        KeyEvent.VK_S,
        KeyEvent.VK_D,
        KeyEvent.VK_F,
        KeyEvent.VK_G,
        KeyEvent.VK_H,
        KeyEvent.VK_J,
        KeyEvent.VK_K,
        KeyEvent.VK_L,
        KeyEvent.VK_SEMICOLON,
        KeyEvent.VK_QUOTEDBL,
        KeyEvent.VK_EQUALS,
      },
      // top row
      {
        KeyEvent.VK_Q,
        KeyEvent.VK_W,
        KeyEvent.VK_E,
        KeyEvent.VK_R,
        KeyEvent.VK_T,
        KeyEvent.VK_Y,
        KeyEvent.VK_U,
        KeyEvent.VK_I,
        KeyEvent.VK_O,
        KeyEvent.VK_P,
        KeyEvent.VK_OPEN_BRACKET,
        KeyEvent.VK_CLOSE_BRACKET,
      },
      // number row
      {
        KeyEvent.VK_BACK_QUOTE,
        KeyEvent.VK_1,
        KeyEvent.VK_2,
        KeyEvent.VK_3,
        KeyEvent.VK_4,
        KeyEvent.VK_5,
        KeyEvent.VK_6,
        KeyEvent.VK_7,
        KeyEvent.VK_8,
        KeyEvent.VK_9,
        KeyEvent.VK_0,
        KeyEvent.VK_MINUS,
      },
    };
    BiMap<Integer, Integer> map = HashBiMap.create();
    int doOfSmallOctava = 48; // -до- малой октавы
    for (int i = 0; i < keyboardArrangement.length; ++i) {
      for (int j = 0; j < 12; ++j) {
        map.put(keyboardArrangement[i][j], doOfSmallOctava + 12 * i + j);
      }
    }
    for (Integer i = PianoLayoutPanel.FIRST_TUNE; i < 128; ++i) {
      if (!map.containsValue(i)) {
        map.put(256 + i, i); // setting not existing (on generic keyboard) key
        // TODO: not parsed back correctly
      }
    }

    map.put(KeyEvent.VK_PAUSE, 0);

    return map;
  }