Example usage for java.util Arrays copyOf

List of usage examples for java.util Arrays copyOf

Introduction

In this page you can find the example usage for java.util Arrays copyOf.

Prototype

public static boolean[] copyOf(boolean[] original, int newLength) 

Source Link

Document

Copies the specified array, truncating or padding with false (if necessary) so the copy has the specified length.

Usage

From source file:com.almende.dht.Bucket.java

/**
 * Gets the closest nodes.// w  w  w.j  av a 2 s. c o  m
 *
 * @param near
 *            the near
 * @param limit
 *            the limit
 * @param filter
 *            the filter
 * @return the closest nodes
 */
public List<Node> getClosestNodes(final Key near, final int limit, final Collection<Key> filter) {
    synchronized (nodes) {
        final TreeMap<Key, Node> distMap = new TreeMap<Key, Node>();
        final Iterator<Entry<Key, Node>> iter = nodes.entrySet().iterator();
        while (iter.hasNext()) {
            Entry<Key, Node> entry = iter.next();
            if (filter != null && filter.contains(entry.getKey())) {
                continue;
            }
            distMap.put(near.dist(entry.getKey()), entry.getValue());
        }
        final Node[] values = distMap.values().toArray(new Node[0]);
        return Arrays.asList(Arrays.copyOf(values, Math.min(limit, distMap.size())));
    }
}

From source file:com.arpnetworking.tsdcore.sinks.KairosDbSink.java

/**
 * {@inheritDoc}//from   w w w .j a  v a 2s.  com
 */
@Override
protected Collection<byte[]> serialize(final PeriodicData periodicData) {
    // Initialize serialization structures
    final List<byte[]> completeChunks = Lists.newArrayList();
    final ByteBuffer currentChunk = ByteBuffer.allocate(_maxRequestSize);
    final ByteArrayOutputStream chunkStream = new ByteArrayOutputStream();

    // Extract and transform shared data
    final long timestamp = periodicData.getStart().plus(periodicData.getPeriod()).getMillis();
    final String serializedPeriod = periodicData.getPeriod().toString(ISOPeriodFormat.standard());
    final ImmutableMap<String, String> dimensions = periodicData.getDimensions();
    final Serializer serializer = new Serializer(timestamp, serializedPeriod, dimensions);

    // Initialize the chunk buffer
    currentChunk.put(HEADER);

    // Add aggregated data
    for (final AggregatedData datum : periodicData.getData()) {
        if (!datum.isSpecified()) {
            LOGGER.trace().setMessage("Skipping unspecified datum").addData("datum", datum).log();
            continue;
        }

        serializer.serializeDatum(completeChunks, currentChunk, chunkStream, datum);
    }

    // Add conditions
    for (final Condition condition : periodicData.getConditions()) {
        serializer.serializeCondition(completeChunks, currentChunk, chunkStream, condition);
    }

    // Add the current chunk (if any) to the completed chunks
    if (currentChunk.position() > HEADER_BYTE_LENGTH) {
        currentChunk.put(currentChunk.position() - 1, FOOTER);
        completeChunks.add(Arrays.copyOf(currentChunk.array(), currentChunk.position()));
    }

    return completeChunks;
}

From source file:com.opengamma.maths.highlevelapi.datatypes.primitive.OGIndexType.java

/**
 * Gets the data/*from  w  ww . j a  va 2  s  .  c  o  m*/
 * @return _data the OGIndex data in it's native storage format
 */
public int[] getData() {
    return Arrays.copyOf(_data, _data.length);
}

From source file:com.haulmont.chile.core.model.MetaPropertyPath.java

/**
 * Tests if this path is a nested property of the given path.
 *///from ww w.j av a 2  s. c  o  m
public boolean startsWith(MetaPropertyPath other) {
    if (other.getPath().length > path.length)
        return false;
    MetaProperty[] subarray = Arrays.copyOf(this.metaProperties, other.getMetaProperties().length);
    return Arrays.equals(subarray, other.metaProperties);
}

From source file:com.aliyun.odps.mapred.bridge.streaming.StreamJob.java

public int run(String[] args) throws Exception {
    for (String aa : args) {
        LOG.debug("arg: '" + aa + "'");
    }//from   w  w  w  . jav  a 2s .  c  o  m
    try {
        this.argv_ = Arrays.copyOf(args, args.length);
        init();

        preProcessArgs();
        parseArgv();
        if (printUsage) {
            printUsage(detailedUsage_);
            return 0;
        }
        postProcessArgs();

        setJobConf();
    } catch (IllegalArgumentException ex) {
        //ignore, since log will already be printed
        // print the log in debug mode.
        LOG.debug("Error in streaming job", ex);
        ex.printStackTrace();
        return 1;
    }
    return submitAndMonitorJob();
}

From source file:com.github.horrorho.inflatabledonkey.data.der.PublicKeyInfo.java

public byte[] key() {
    return Arrays.copyOf(key, key.length);
}

From source file:ffx.potential.parameters.OutOfPlaneBendType.java

/**
 * Remap new atom classes to known internal ones.
 *
 * @param typeMap a lookup between new atom types and known atom types.
 * @return//from  w ww .ja v a2  s  .c om
 */
public OutOfPlaneBendType patchClasses(HashMap<AtomType, AtomType> typeMap) {
    int count = 0;
    int len = atomClasses.length;
    /**
     * Look for new OutOfPlaneBends that contain 1 mapped atom classes.
     */
    for (AtomType newType : typeMap.keySet()) {
        for (int i = 0; i < len; i++) {
            if (atomClasses[i] == newType.atomClass) {
                count++;
            }
        }
    }
    /**
     * If found, create a new OutOfPlaneBend that bridges to known classes.
     */
    if (count == 1) {
        int newClasses[] = Arrays.copyOf(atomClasses, len);
        for (AtomType newType : typeMap.keySet()) {
            for (int i = 0; i < len; i++) {
                if (atomClasses[i] == newType.atomClass) {
                    AtomType knownType = typeMap.get(newType);
                    newClasses[i] = knownType.atomClass;
                }
            }
        }
        return new OutOfPlaneBendType(newClasses, forceConstant);
    }
    return null;
}

From source file:com.cloudera.sqoop.testutil.BaseSqoopTestCase.java

protected void setColNames(String[] cols) {
    if (null == cols) {
        this.colNames = null;
    } else {//from  w  w  w . jav  a  2  s .c  o  m
        this.colNames = Arrays.copyOf(cols, cols.length);
    }
}

From source file:es.udc.gii.common.eaf.algorithm.operator.reproduction.mutation.de.mutationStrategy.RandomDEMutationStrategy.java

@Override
public Individual getMutatedIndividual(EvolutionaryAlgorithm algorithm, Individual target) {

    int basePos;//w  w  w . ja  v  a2  s  .c o  m
    double[] base;
    List<Individual> individuals;
    List<Individual> listInd;
    List<Integer> index_list;
    int randomPos;
    double auxGeneValue, x1, x2;
    double F;

    F = this.getFPlugin().get(algorithm);
    individuals = algorithm.getPopulation().getIndividuals();

    basePos = (int) EAFRandom.nextInt(individuals.size());
    base = ((Individual) individuals.get(basePos)).getChromosomeAt(0);
    index_list = new ArrayList<>();
    index_list.add(basePos);

    //se eligen los vectores diferenciales:
    listInd = new ArrayList<>();

    for (int i = 0; i < this.getDiffVector() * 2; i++) {

        do {

            randomPos = (int) EAFRandom.nextInt(individuals.size());

        } while (index_list.contains(randomPos));

        index_list.add(randomPos);
        listInd.add(individuals.get(randomPos));

    }

    double[][] diffVectorMatrix = new double[this.getDiffVector() * 2][base.length];

    for (int j = 0; j < diffVectorMatrix.length; j++) {
        diffVectorMatrix[j] = Arrays.copyOf(listInd.get(j).getChromosomeAt(0), base.length);
    }

    if (base != null) {
        //Recorremos el numero de genes:
        for (int i = 0; i < base.length; i++) {

            auxGeneValue = base[i];

            for (int j = 0; j < this.getDiffVector(); j += 2) {

                x1 = diffVectorMatrix[j][i];
                x2 = diffVectorMatrix[j + 1][i];

                auxGeneValue += F * (x1 - x2);

            }

            base[i] = auxGeneValue;

        }

    }

    Individual mutatedIndividual;
    if (target instanceof JADEIndividual) {
        mutatedIndividual = new JADEIndividual();
        ((JADEIndividual) mutatedIndividual).setF(F);
    } else {
        mutatedIndividual = new Individual();
    }
    mutatedIndividual.setChromosomeAt(0, base);
    return mutatedIndividual;

}

From source file:org.bigtester.ate.model.casestep.RepeatDataRefreshEvent.java

/**
 * @return the repeatStepInvokePathNodes
 *///from   w w w . ja  v a  2  s .c o m
public TreeNode[] getRepeatStepInvokePathNodes() {
    TreeNode[] temp = Arrays.copyOf(repeatStepInvokePathNodes, repeatStepInvokePathNodes.length);
    if (null == temp)
        throw GlobalUtils.createInternalError("error in copying array, repeatStepInvokePathNodes");
    else
        return temp;
}