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:gaffer.function.ConsumerProducerFunction.java

/**
 * @return Output record structure accepted by this <code>ConsumerProducerFunction</code>.
 *//*from  w ww . j  av a2  s . c o m*/
@JsonIgnore
public Class<?>[] getOutputClasses() {
    if (null == outputs) {
        processOutputAnnotation();
    }

    return Arrays.copyOf(outputs, outputs.length);
}

From source file:com.threewks.thundr.util.Encoder.java

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

From source file:com.google.nigori.server.JUser.java

@Override
public byte[] getPublicHash() {
    return Arrays.copyOf(publicHash, publicHash.length);
}

From source file:io.warp10.continuum.gts.GTSOutliersHelper.java

protected static double median(GeoTimeSerie gts) {
    // FIXME(JCV): if size of gts too big, we should better work inplace by making a quickSortByValue and sort by ticks after
    double[] copy = Arrays.copyOf(gts.doubleValues, gts.values);
    Arrays.sort(copy);//  w  ww . j a  va2s  .com

    return gts.values % 2 == 0 ? (copy[gts.values / 2] + copy[gts.values / 2 - 1]) / 2 : copy[gts.values / 2];
}

From source file:testFileHandler.java

public void encrypt(String message, String secretKey, javax.swing.JTextArea ciphertextField) throws Exception {

    MessageDigest md = MessageDigest.getInstance("SHA-1");
    byte[] digestOfPassword = md.digest(secretKey.getBytes("utf-8"));
    byte[] keyBytes = Arrays.copyOf(digestOfPassword, 24);

    SecretKey key = new SecretKeySpec(keyBytes, "DESede");
    Cipher cipher = Cipher.getInstance("DESede");
    cipher.init(Cipher.ENCRYPT_MODE, key);
    // Encode the string into bytes using utf-8
    byte[] plainTextBytes = message.getBytes("utf-8");
    // Encrypt// w  w  w  .  j av  a  2s .co  m
    byte[] buf = cipher.doFinal(plainTextBytes);
    // Encode bytes to base64 to get a string
    byte[] base64Bytes = Base64.encodeBase64(buf);
    String base64EncryptedString = new String(base64Bytes);

    ciphertextField.setText(base64EncryptedString);
}

From source file:Main.java

/**
 * Draws data and returns items in array list.
 * // w w w.  j a va2 s  .c  o m
 * @param list
 *            Draws data from premade list.
 * @param filter
 *            Filters data to lower case.
 * @return Returns items in the form of an array list.
 */
public static String[] filter(String[] list, String filter) {
    String[] items = new String[0];
    for (String item : list) {
        if (item.toLowerCase().contains(filter.toLowerCase())) {
            items = Arrays.copyOf(items, items.length + 1);
            items[items.length - 1] = item;
        }
    }
    return items;
}

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

protected Atom(Predicate p, Term[] args) {
    predicate = p;//from   w ww.j a va  2  s.co  m
    arguments = Arrays.copyOf(args, args.length);
    hashcode = new HashCodeBuilder().append(predicate).append(arguments).toHashCode();
    checkSchema();
}

From source file:com.opengamma.strata.math.impl.statistics.descriptive.PercentileCalculatorTest.java

@Test
public void testExtremes() {
    final double[] y = Arrays.copyOf(X, X.length);
    Arrays.sort(y);/*from   w w  w .  j a v a 2  s  .  co  m*/
    CALCULATOR.setPercentile(1e-15);
    assertEquals(CALCULATOR.apply(X), y[0], 0);
    CALCULATOR.setPercentile(1 - 1e-15);
    assertEquals(CALCULATOR.apply(X), y[N - 1], 0);
}

From source file:net.nicholaswilliams.java.licensing.licensor.interfaces.cli.TestPeriods.java

@Test
public void testRun01() throws InterruptedException {
    new Thread(this.periods).start();

    Thread.sleep(100);/*from w  ww  . j  av a  2 s .  c om*/

    this.periods.stop();

    byte[] bytes = this.outputStream.toByteArray();
    assertTrue("The length is not correct.", bytes.length >= 3);
    assertArrayEquals("The arrays are not correct.", Arrays.copyOf(bytes, 3), new byte[] { '.', '.', '.' });
}

From source file:com.offbynull.voip.kademlia.externalmessages.FindResponse.java

/**
 * Get closest nodes to the ID that was searched for.
 * @return closest nodes
 */
public Node[] getNodes() {
    return Arrays.copyOf(nodes, nodes.length);
}