Java Arrays.copyOf Examples

Java Arrays.copyOf - 30 examples found. These are the top rated real world Java examples of java.util.Arrays.copyOf extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
  @Override
  public List<String[]> getColumnVector() {
    List<String[]> columnList = new ArrayList<String[]>();
    String[] columnVec =
        new String[] {
          Configuration.IDX_FIELD_API_NAME,
          Configuration.IDX_FIELD_CLASS_BASE_NAME,
          Configuration.IDX_FIELD_METHOD_NAME,
          Configuration.IDX_FIELD_DESCRIPTION
        };
    String[] columnVec1 =
        new String[] {
          Configuration.IDX_FIELD_API_NAME,
          Configuration.IDX_FIELD_CLASS_NAME_PKG_SPLIT,
          Configuration.IDX_FIELD_METHOD_NAME,
          Configuration.IDX_FIELD_DESCRIPTION
        };

    columnList.add(columnVec);
    columnList.add(Arrays.copyOf(columnVec, 4));
    columnList.add(Arrays.copyOf(columnVec, 4));
    columnList.add(Arrays.copyOf(columnVec, 4));
    columnList.add(columnVec1);
    return columnList;
  }
Example #2
0
  public void purge() {
    _lock.lock();
    try {
      int newIndex = 0;
      for (int oldIndex = 0; oldIndex < _elements.length; oldIndex++) {
        final Object obj = _elements[oldIndex];
        final long time = _access[oldIndex];

        _elements[oldIndex] = null;
        _access[oldIndex] = 0;

        if (obj == null || time + getMaxLifeTime() < System.currentTimeMillis()) continue;

        _elements[newIndex] = obj;
        _access[newIndex] = time;

        newIndex++;
      }

      _elements = Arrays.copyOf(_elements, newIndex);
      _access = Arrays.copyOf(_access, newIndex);
      _size = newIndex;
    } finally {
      _lock.unlock();
    }
  }
  /**
   * Returns the generated OLS based on Polynomial Finite Field.
   *
   * @param pm the order of the OLS and it should be a prime power
   * @param n the number of OLS and it should be at most {@code pm-1}
   * @return the generated OLS based on Polynomial Finite Field
   */
  private List<int[][]> generatePoly_OLS(int pm, int n) {

    ArrayList<int[][]> OLS_list = new ArrayList<int[][]>(n);

    if (n == 0) {
      return OLS_list;
    }

    // p & m
    int[] parts = MathUtil.partOfPrimePower(pm);
    int[][] firstPoly_LS = generatePoly_LS(parts[0], parts[1]);
    OLS_list.add(firstPoly_LS);

    int[][] nextPoly_LS = Arrays.copyOf(firstPoly_LS, firstPoly_LS.length);
    for (int i = 1; i < n; i++) {

      int[] secondRow = nextPoly_LS[1];

      // 3->2, 4->3, 5->4 ...
      for (int row = 1; row < nextPoly_LS.length - 1; row++) {
        nextPoly_LS[row] = nextPoly_LS[row + 1];
      }
      // second row -> last row
      nextPoly_LS[nextPoly_LS.length - 1] = secondRow;

      // add and copy a new LS with raw data to process
      OLS_list.add(nextPoly_LS);
      nextPoly_LS = Arrays.copyOf(nextPoly_LS, nextPoly_LS.length);
    }

    return OLS_list;
  }
  @Override
  public List<FSM> apply(List<FSM> parents) {
    int numberOfStates = parents.get(0).getNumberOfStates();
    int numberOfEvents = parents.get(0).getNumberOfEvents();
    List<String> events = parents.get(0).getEvents();

    int point = ThreadLocalRandom.current().nextInt(parents.get(0).getNumberOfStates());
    FSM.Transition[][] tr0 = new FSM.Transition[numberOfStates][numberOfEvents];
    FSM.Transition[][] tr1 = new FSM.Transition[numberOfStates][numberOfEvents];

    for (int state = 0; state < numberOfStates; state++) {
      if (state < point) {
        tr0[state] =
            Arrays.copyOf(
                parents.get(0).transitions[state], parents.get(0).transitions[state].length);
        tr1[state] =
            Arrays.copyOf(
                parents.get(1).transitions[state], parents.get(1).transitions[state].length);
      } else {
        tr0[state] =
            Arrays.copyOf(
                parents.get(1).transitions[state], parents.get(1).transitions[state].length);
        tr1[state] =
            Arrays.copyOf(
                parents.get(0).transitions[state], parents.get(0).transitions[state].length);
      }
    }

    List<FSM> offspring = new ArrayList<FSM>();
    offspring.add(new FSM(numberOfStates, tr0));
    offspring.add(new FSM(numberOfStates, tr1));
    return offspring;
  }
  // This is where you load the data that you saved in writeToNBT
  @Override
  public void readFromNBT(NBTTagCompound nbtTagCompound) {
    super.readFromNBT(
        nbtTagCompound); // The super call is required to save and load the tiles location
    final byte NBT_TYPE_COMPOUND = 10; // See NBTBase.createNewByType() for a listing
    NBTTagList dataForAllSlots = nbtTagCompound.getTagList("Items", NBT_TYPE_COMPOUND);

    Arrays.fill(itemStacks, null); // set all slots to empty
    for (int i = 0; i < dataForAllSlots.tagCount(); ++i) {
      NBTTagCompound dataForOneSlot = dataForAllSlots.getCompoundTagAt(i);
      byte slotNumber = dataForOneSlot.getByte("Slot");
      if (slotNumber >= 0 && slotNumber < this.itemStacks.length) {
        this.itemStacks[slotNumber] = ItemStack.loadItemStackFromNBT(dataForOneSlot);
      }
    }

    // Load everything else.  Trim the arrays (or pad with 0) to make sure they have the correct
    // number of elements
    cookTime = nbtTagCompound.getShort("CookTime");
    burnTimeRemaining =
        Arrays.copyOf(nbtTagCompound.getIntArray("burnTimeRemaining"), FUEL_SLOTS_COUNT);
    burnTimeInitialValue =
        Arrays.copyOf(nbtTagCompound.getIntArray("burnTimeInitial"), FUEL_SLOTS_COUNT);
    cachedNumberOfBurningSlots = -1;
  }
Example #6
0
  public static ClusterData makeCd(
      final int lane,
      final int tile,
      final int xCoord,
      final int yCoord,
      final boolean pf,
      final byte[] bases,
      final byte[] qualities,
      final String matchedBarcode) {
    final ReadData rd = new ReadData();
    rd.setBases(Arrays.copyOf(bases, bases.length));
    rd.setQualities(Arrays.copyOf(qualities, bases.length));
    rd.setReadType(
        ReadType.T); // This will be ignored, as the cluster will be chopped up by ReadStructure

    final ClusterData cd = new ClusterData(rd);
    cd.setLane(lane);
    cd.setTile(tile);
    cd.setX(xCoord);
    cd.setY(yCoord);
    cd.setPf(pf);
    cd.setMatchedBarcode(matchedBarcode);

    return cd;
  }