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.opengamma.analytics.math.interpolation.PiecewiseCubicHermiteSplineInterpolatorWithSensitivity.java

@Override
public PiecewisePolynomialResultsWithSensitivity interpolateWithSensitivity(final double[] xValues,
        final double[] yValues) {

    ArgumentChecker.notNull(xValues, "xValues");
    ArgumentChecker.notNull(yValues, "yValues");

    ArgumentChecker.isTrue(xValues.length == yValues.length, "xValues length = yValues length");
    ArgumentChecker.isTrue(xValues.length > 1, "Data points should be more than 1");

    final int nDataPts = xValues.length;

    for (int i = 0; i < nDataPts; ++i) {
        ArgumentChecker.isFalse(Double.isNaN(xValues[i]), "xData containing NaN");
        ArgumentChecker.isFalse(Double.isInfinite(xValues[i]), "xData containing Infinity");
        ArgumentChecker.isFalse(Double.isNaN(yValues[i]), "yData containing NaN");
        ArgumentChecker.isFalse(Double.isInfinite(yValues[i]), "yData containing Infinity");
    }/*from  w w  w  . ja v  a 2 s.  c  o m*/

    double[] xValuesSrt = Arrays.copyOf(xValues, nDataPts);
    double[] yValuesSrt = Arrays.copyOf(yValues, nDataPts);
    ParallelArrayBinarySort.parallelBinarySort(xValuesSrt, yValuesSrt);

    for (int i = 1; i < nDataPts; ++i) {
        ArgumentChecker.isFalse(xValuesSrt[i - 1] == xValuesSrt[i], "xValues should be distinct");
    }

    final DoubleMatrix2D[] temp = solve(xValuesSrt, yValuesSrt);

    // check the matrices
    // TODO remove some of these tests
    ArgumentChecker.noNulls(temp, "error in solve - some matrices are null");
    int n = temp.length;
    ArgumentChecker.isTrue(n == nDataPts, "wrong number of matricies");
    for (int k = 0; k < n; k++) {
        DoubleMatrix2D m = temp[k];
        final int rows = m.getNumberOfRows();
        final int cols = m.getNumberOfColumns();
        for (int i = 0; i < rows; ++i) {
            for (int j = 0; j < cols; ++j) {
                ArgumentChecker.isTrue(Doubles.isFinite(m.getEntry(i, j)), "Matrix contains a NaN or infinite");
            }
        }
    }

    DoubleMatrix2D coefMatrix = temp[0];
    DoubleMatrix2D[] coefMatrixSense = new DoubleMatrix2D[n - 1];
    System.arraycopy(temp, 1, coefMatrixSense, 0, n - 1);

    return new PiecewisePolynomialResultsWithSensitivity(new DoubleMatrix1D(xValuesSrt), coefMatrix, 4, 1,
            coefMatrixSense);
}

From source file:jenkins.plugins.publish_over.helper.RandomFile.java

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

From source file:edu.umd.cs.psl.model.atom.Atom.java

/**
 * Returns the arguments associated with this atom.
 * /*from  ww w  .  j a  va  2s.c  om*/
 * @return The arguments associated with this atom
 */
public Term[] getArguments() {
    return Arrays.copyOf(arguments, arguments.length);
}

From source file:tachyon.client.keyvalue.hadoop.KeyValueRecordWriter.java

@Override
public synchronized void write(BytesWritable key, BytesWritable value) throws IOException {
    try {/* w  ww. j  ava 2 s.com*/
        // NOTE: BytesWritable.getBytes() returns the internal byte array, whose length might not be
        // the same as BytesWritable.getLength().
        mWriter.put(Arrays.copyOf(key.getBytes(), key.getLength()),
                Arrays.copyOf(value.getBytes(), value.getLength()));
        // Sends a progress to the job manager to inform it that the task is still running.
        mProgress.progress();
    } catch (TachyonException e) {
        throw new IOException(e);
    }
}

From source file:com.netflix.hollow.jsonadapter.HollowJsonAdapterPrimaryKeyFinder.java

public Object[] findKey(String json) throws IOException {
    JsonFactory factory = new JsonFactory();
    JsonParser parser = factory.createParser(new StringReader(json));
    return Arrays.copyOf(findKey(parser), keyElementArray.length);
}

From source file:com.opengamma.maths.lowlevelapi.functions.utilities.Sort.java

/**
 * Sorts values statelessly in order given by enumeration
 * @param v1 the values to sort (a native backed array)
 * @param d the direction in which the sorted array should be returned (based on {@link direction})
 * @return tmp the sorted values/* ww w. j  a v a  2s.c o  m*/
 */
public static long[] stateless(long[] v1, direction d) {
    Validate.notNull(v1);
    long[] tmp = Arrays.copyOf(v1, v1.length);
    Arrays.sort(tmp);
    switch (d) {
    case ascend:
        break;
    case descend:
        Reverse.inPlace(tmp);
    }
    return tmp;
}

From source file:graph.inference.module.GenlPredTransitiveWorker.java

@Override
public void queryInternal(QueryObject queryObj) throws IllegalArgumentException {
    // Find related edges for args
    ArrayList<Object> nonPreds = new ArrayList<>();
    Node[] nodes = queryObj.getNodes();
    for (int i = 1; i < nodes.length; i++) {
        if (!(nodes[i] instanceof VariableNode)) {
            nonPreds.add(nodes[i]);/*from w w  w.  jav a 2  s. c om*/
            nonPreds.add(i + 1);
        }
    }
    Collection<Edge> nonPredEdges = relatedModule_.execute(nonPreds.toArray(new Object[nonPreds.size()]));

    // Sub preds
    VariableNode varNode = new VariableNode("?SUB_PREDS");
    Collection<Substitution> subPreds = querier_.execute(CommonConcepts.GENLPREDS.getNode(dag_), varNode,
            queryObj.getNode(0));
    if (subPreds.isEmpty())
        subPreds.add(new Substitution(varNode, (DAGNode) queryObj.getNode(0)));
    for (Substitution sub : subPreds) {
        Node subPred = sub.getSubstitution(varNode);
        Collection<Edge> predEdges = relatedModule_.findEdgeByNodes(subPred);
        Collection<Edge> intersect = CollectionUtils.retainAll(nonPredEdges, predEdges);
        for (Edge interEdge : intersect) {
            Node[] edgeNodes = Arrays.copyOf(interEdge.getNodes(), interEdge.getNodes().length);
            if (queryObj.addResult(edgeNodes))
                return;
        }
    }
}

From source file:edu.hm.cs.fs.scriptinat0r7.model.ScriptDocument.java

/**
 * Sets the file./*from  w w  w  .  ja  v a  2s.  c  o m*/
 * @param file the file.
 */
public void setFile(final byte[] file) {
    this.file = Arrays.copyOf(file, file.length);
    fileSize = file.length;
}

From source file:edu.oregonstate.eecs.mcplan.domains.yahtzee2.KeepAllAction.java

@Override
public void doAction(final RandomGenerator rng, final YahtzeeState s) {
    assert (old_hand_ == null);
    assert (s.rerolls > 0);
    old_hand_ = s.hand();/*from   w ww  . jav a  2 s .c  o m*/

    final int n = old_hand_.dice[k - 1];
    final int[] r;
    if (n < Hand.Ndice) {
        r = s.roll(rng, Hand.Ndice - n);
        r[k - 1] += n;
    } else {
        r = Arrays.copyOf(old_hand_.dice, old_hand_.dice.length);
    }
    final Hand h = new Hand(r);
    s.setHand(h, s.rerolls - 1);
}

From source file:com.eugene.fithealthmaingit.FatSecretSearchAndGet.FatSecretGetMethod.java

private static String paramify(String[] params) {
    String[] p = Arrays.copyOf(params, params.length);
    Arrays.sort(p);//  ww  w  .ja v a 2  s  .c om
    return join(p, "&");
}