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.linkedin.restli.datagenerator.csharp.CSharpUtil.java

/**
 * Invokes the Rythm template with the given name and pass the arguments. This can be used in place of template
 * invocation in Rythm template to workaround Rythm limitation in argument passing.
 *//*from  ww w.  j av  a2 s .co  m*/
public static String invokeRythmTemplate(String template, RythmEngine engine, Object... args) {
    Object[] argsWithEngine = Arrays.copyOf(args, args.length + 1);
    argsWithEngine[args.length] = engine;
    String rendered = engine.renderIfTemplateExists(
            CSharpRythmGenerator.TEMPLATE_PATH_ROOT + '/' + template + ".rythm", argsWithEngine);
    if (rendered.isEmpty()) {
        throw new RuntimeException("Rythm template '" + template + "' does not exist.");
    }
    return rendered;
}

From source file:de.fu_berlin.inf.dpp.intellij.project.fs.PathImp.java

@Override
public IPath removeLastSegments(int count) {
    String[] result = Arrays.copyOf(segments, segments.length - count);
    return new PathImp(join(result));
}

From source file:com.heliosdecompiler.helios.controller.files.OpenedFile.java

public byte[] getContent(String path) {
    return Arrays.copyOf(this.fileContents.get(path), this.fileContents.get(path).length);
}

From source file:net.sf.dsp4j.octave.packages.signal_1_0_11.Freqz.java

public Freqz(double[] b, double[] a, int n) {
    FastFourierTransformer fft = new FastFourierTransformer(DftNormalization.STANDARD);

    Complex[] hb = fft.transform(Arrays.copyOf(b, 2 * n), TransformType.FORWARD);
    Complex[] ha = fft.transform(Arrays.copyOf(a, 2 * n), TransformType.FORWARD);

    H = new Complex[n];
    w = new double[n];

    for (int i = 0; i < H.length; i++) {
        H[i] = hb[i].divide(ha[i]);//from  w w  w . j  a v  a2 s .c om
        w[i] = Math.PI / n * i;
    }

}

From source file:org.apache.taverna.activities.wsdl.xmlsplitter.XMLSplitterConfigurationBeanBuilder.java

public static JsonNode buildBeanForInput(Element element) throws JDOMException, IOException {
    ObjectNode bean = JSON_NODE_FACTORY.objectNode();
    ArrayNode inputDefinitions = bean.arrayNode();
    bean.put("inputPorts", inputDefinitions);
    ArrayNode outputDefinitions = bean.arrayNode();
    bean.put("outputPorts", outputDefinitions);

    TypeDescriptor descriptor = XMLSplitterSerialisationHelper.extensionXMLToTypeDescriptor(element);
    ObjectNode outBean = outputDefinitions.addObject();
    outBean.put("name", "output");
    outBean.put("mimeType", "'text/xml'");
    outBean.put("depth", 0);
    outBean.put("granularDepth", 0);

    if (descriptor instanceof ComplexTypeDescriptor) {
        List<TypeDescriptor> elements = ((ComplexTypeDescriptor) descriptor).getElements();
        String[] names = new String[elements.size()];
        Class<?>[] types = new Class<?>[elements.size()];
        TypeDescriptor.retrieveSignature(elements, names, types);
        for (int i = 0; i < names.length; i++) {
            ObjectNode portBean = inputDefinitions.addObject();
            portBean.put("name", names[i]);
            portBean.put("mimeType", TypeDescriptor.translateJavaType(types[i]));
            portBean.put("depth", depthForDescriptor(elements.get(i)));
        }//w  w w . ja  va  2 s .com

        List<TypeDescriptor> attributes = ((ComplexTypeDescriptor) descriptor).getAttributes();
        String[] elementNames = Arrays.copyOf(names, names.length);
        Arrays.sort(elementNames);
        String[] attributeNames = new String[attributes.size()];
        Class<?>[] attributeTypes = new Class<?>[attributes.size()];
        TypeDescriptor.retrieveSignature(attributes, attributeNames, attributeTypes);
        for (int i = 0; i < attributeNames.length; i++) {
            ObjectNode portBean = inputDefinitions.addObject();
            if (Arrays.binarySearch(elementNames, attributeNames[i]) < 0) {
                portBean.put("name", attributeNames[i]);
            } else {
                portBean.put("name", "1" + attributeNames[i]);
            }
            portBean.put("mimeType", TypeDescriptor.translateJavaType(attributeTypes[i]));
            portBean.put("depth", depthForDescriptor(attributes.get(i)));
        }
    } else if (descriptor instanceof ArrayTypeDescriptor) {
        ObjectNode portBean = inputDefinitions.addObject();
        portBean.put("name", descriptor.getName());

        if (((ArrayTypeDescriptor) descriptor).getElementType() instanceof BaseTypeDescriptor) {
            portBean.put("mimeType", "l('text/plain')");
        } else {
            portBean.put("mimeType", "l('text/xml')");
        }
        portBean.put("depth", 1);
    }

    String wrappedType = new XMLOutputter().outputString(element);
    bean.put("wrappedType", wrappedType);

    return bean;
}

From source file:de.codecentric.boot.admin.notify.MailNotifier.java

public void setCc(String[] cc) {
    this.cc = Arrays.copyOf(cc, cc.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//from  w  w w  .j a v  a  2  s  .com
 */
public static float[] stateless(float[] v1, direction d) {
    Validate.notNull(v1);
    float[] tmp = Arrays.copyOf(v1, v1.length);
    Arrays.sort(tmp);
    switch (d) {
    case ascend:
        break;
    case descend:
        Reverse.inPlace(tmp);
    }
    return tmp;
}

From source file:gdsc.smlm.utils.Convolution.java

/**
 * Calculates the <a href="http://en.wikipedia.org/wiki/Convolution">
 * convolution</a> between two sequences.
 * <p>// ww  w.j ava  2s.c om
 * The solution is obtained via multiplication in the frequency domain.
 *
 * @param x
 *            First sequence.
 *            Typically, this sequence will represent an input signal to a system.
 * @param h
 *            Second sequence.
 *            Typically, this sequence will represent the impulse response of the system.
 * @return the convolution of {@code x} and {@code h}.
 *         This array's length will be {@code x.length + h.length - 1}.
 * @throws IllegalArgumentException
 *             if either {@code x} or {@code h} is {@code null} or either {@code x} or {@code h} is empty.
 */
public static double[] convolveFFT(double[] x, double[] h) throws IllegalArgumentException {
    checkInput(x, h);

    if (x.length < h.length) {
        // Swap so that the longest array is the signal
        final double[] tmp = x;
        x = h;
        h = tmp;
    }

    final int xLen = x.length;
    final int hLen = h.length;
    final int totalLength = xLen + hLen - 1;

    // Get length to a power of 2
    int newL = 2;
    while (newL < totalLength) //xLen)
        newL *= 2;

    // Double the new length for complex values in DoubleFFT_1D
    x = Arrays.copyOf(x, 2 * newL);
    h = Arrays.copyOf(h, x.length);
    double[] tmp = new double[x.length];

    DoubleFFT_1D fft = new DoubleFFT_1D(newL);

    // FFT
    fft.realForwardFull(x);
    fft.realForwardFull(h);

    // Complex multiply
    for (int i = 0; i < newL; i++) {
        final int ii = 2 * i;
        tmp[ii] = x[ii] * h[ii] - x[ii + 1] * h[ii + 1];
        tmp[ii + 1] = x[ii] * h[ii + 1] + x[ii + 1] * h[ii];
    }

    // Inverse FFT
    fft.complexInverse(tmp, true);

    // Fill result with real part
    final double[] y = new double[totalLength];
    for (int i = 0; i < totalLength; i++) {
        y[i] = tmp[2 * i];
    }
    return y;
}

From source file:com.cloudera.sqoop.mapreduce.db.DBRecordReader.java

/**
 * @param split The InputSplit to read data for
 * @throws SQLException//from  w  w w.ja v a  2s.  co  m
 */
// CHECKSTYLE:OFF
// TODO (aaron): Refactor constructor to take fewer arguments
public DBRecordReader(DBInputFormat.DBInputSplit split, Class<T> inputClass, Configuration conf,
        Connection conn, DBConfiguration dbConfig, String cond, String[] fields, String table)
        throws SQLException {
    this.inputClass = inputClass;
    this.split = split;
    this.conf = conf;
    this.connection = conn;
    this.dbConf = dbConfig;
    this.conditions = cond;
    if (fields != null) {
        this.fieldNames = Arrays.copyOf(fields, fields.length);
    }
    this.tableName = table;
}

From source file:com.opengamma.analytics.math.linearalgebra.TridiagonalMatrix.java

/**
 * @return An array of the values of the lower sub-diagonal
 */
public double[] getLowerSubDiagonal() {
    return Arrays.copyOf(_c, _c.length);
}