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:dfs.OLSTrendLine.java

@Override
public void setValues(double[] y, double[] x) {
    if (x.length != y.length) {
        throw new IllegalArgumentException(
                String.format("The numbers of y and x values must be equal (%d != %d)", y.length, x.length));
    }//from ww  w. j ava2s .c  o m
    double[][] xData = new double[x.length][];
    for (int i = 0; i < x.length; i++) {
        // the implementation determines how to produce a vector of predictors from a single x
        xData[i] = xVector(x[i]);
    }
    if (logY()) { // in some models we are predicting ln y, so we replace each y with ln y
        y = Arrays.copyOf(y, y.length); // user might not be finished with the array we were given
        for (int i = 0; i < x.length; i++) {
            y[i] = Math.log(y[i]);
        }
    }
    OLSMultipleLinearRegression ols = new OLSMultipleLinearRegression();
    ols.setNoIntercept(true); // let the implementation include a constant in xVector if desired
    ols.newSampleData(y, xData); // provide the data to the model
    coef = MatrixUtils.createColumnRealMatrix(ols.estimateRegressionParameters()); // get our coefs
}

From source file:lovinghusbandpuzzle.LoHusbState.java

/**
 * The state needs 3 parameters - arrays for people on the north and south,
 * and the location of the raft .//  ww  w.j  a  v  a 2s.c o m
 *
 * @param couplesN people on the north side
 * @param couplesS people on the south side
 * @param raftLocation
 */
public LoHusbState(char[] couplesN, char[] couplesS, RiverBank raftLocation) {
    this.couplesN = Arrays.copyOf(couplesN, couplesN.length);
    this.couplesS = Arrays.copyOf(couplesS, couplesS.length);
    this.raftLocation = raftLocation;
}

From source file:ezbake.data.elastic.test.models.PlaceOfInterest.java

public void setTags(String[] tags) {
    this.tags = Arrays.copyOf(tags, tags.length);
}

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

/**
 * Sorts values statelessly in ascending order
 * @param v1 the values to sort (a native backed array)
 * @return tmp the sorted values//from ww  w.  j a  v  a 2s.co m
 */
public static double[] stateless(double[] v1) {
    Validate.notNull(v1);
    double[] tmp = Arrays.copyOf(v1, v1.length);
    Arrays.sort(tmp);
    return tmp;
}

From source file:com.formatAdmin.utils.UtilsSecurity.java

public static String decifrarMD5(String textoEncriptado) throws Exception {
    String base64EncryptedString = "";

    try {// w  w  w .java  2 s  .  c om
        byte[] message = Base64.decodeBase64(textoEncriptado.getBytes("utf-8"));
        MessageDigest md = MessageDigest.getInstance("MD5");
        byte[] digestOfPassword = md.digest(SECRET_MD5_KEY.getBytes("utf-8"));
        byte[] keyBytes = Arrays.copyOf(digestOfPassword, 24);
        SecretKey key = new SecretKeySpec(keyBytes, ENCRYPT_ALGORITHM);

        Cipher decipher = Cipher.getInstance(ENCRYPT_ALGORITHM);
        decipher.init(Cipher.DECRYPT_MODE, key);

        byte[] plainText = decipher.doFinal(message);

        base64EncryptedString = new String(plainText, "UTF-8");

    } catch (UnsupportedEncodingException | InvalidKeyException | NoSuchAlgorithmException | BadPaddingException
            | IllegalBlockSizeException | NoSuchPaddingException ex) {
        throw ex;
    }
    return base64EncryptedString;
}

From source file:me.bramhaag.discordselfbot.commands.util.CommandJavadoc.java

@Command(name = "javadoc", aliases = { "doc", "jd" }, minArgs = 1)
public void execute(@NonNull Message message, @NonNull TextChannel channel, @NonNull String[] args) {
    String[] parts = args[0].split("\\.");

    String pack = parts.length >= 3 ? StringUtils.join(Arrays.copyOf(parts, parts.length - 2), "/") + "/"
            : null;/*  w  w w .  ja  v a2  s.  c  o  m*/
    String clazz = parts[parts.length - 2];
    String method = args[0].contains(".") ? args[0].substring(args[0].lastIndexOf(".") + 1, args[0].length())
            : args[0];

    JavadocParser.JavadocResult result = null;

    try {
        if (pack == null) {
            result = JavadocParser.getJavadoc(clazz + "/" + method);
        } else {
            result = args.length > 1 ? JavadocParser.getJavadoc(args[1], pack + clazz, method)
                    : JavadocParser.getJavadoc(pack + clazz, method);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    if (result == null) {
        Util.sendError(message, "Result is null!");
    }

    EmbedBuilder builder = new EmbedBuilder().setTitle("Javadoc", null)
            .addField("Name", code(result.getName()), false).addField("Format", code(result.getFormat()), false)
            .addField("Description", code(result.getDescription()), false);

    result.getFields()
            .forEach((key, value) -> builder.addField(key, code(StringUtils.join(value, "\n")), false));
    channel.sendMessage(builder.build()).queue();
}

From source file:com.juicioenlinea.application.secutiry.Security.java

public static String desencriptar(String textoEncriptado) {

    final String secretKey = "hunter"; //llave para encriptar datos
    String encryptedString = null;

    try {/*ww  w  . j av a 2  s .  c  o  m*/
        byte[] message = Base64.decodeBase64(textoEncriptado.getBytes("UTF-8"));
        MessageDigest md = MessageDigest.getInstance("SHA");
        byte[] digestOfPassword = md.digest(secretKey.getBytes("UTF-8"));
        byte[] keyBytes = Arrays.copyOf(digestOfPassword, 24);
        SecretKey key = new SecretKeySpec(keyBytes, "DESede");

        Cipher decipher = Cipher.getInstance("DESede");
        decipher.init(Cipher.DECRYPT_MODE, key);

        byte[] plainText = decipher.doFinal(message);

        encryptedString = new String(plainText, "UTF-8");

    } catch (UnsupportedEncodingException | InvalidKeyException | NoSuchAlgorithmException
            | NoSuchPaddingException | IllegalBlockSizeException | BadPaddingException ex) {
        Logger.getLogger(Security.class.getName()).log(Level.SEVERE, null, ex);
    }

    return encryptedString;
}

From source file:com.opengamma.analytics.math.statistics.descriptive.PercentileCalculator.java

/**
 * @param x The data, not null or empty//from   w  ww .j a  v a2s.  c  o  m
 * @return The percentile
 */
@Override
public Double evaluate(final double[] x) {
    Validate.notNull(x, "x");
    Validate.isTrue(x.length > 0, "x cannot be empty");
    final int length = x.length;
    final double[] copy = Arrays.copyOf(x, length);
    Arrays.sort(copy);
    final double n = _percentile * (length - 1) + 1;
    if (Math.round(n) == 1) {
        return copy[0];
    }
    if (Math.round(n) == length) {
        return copy[length - 1];
    }
    final double d = n % 1;
    final int k = (int) Math.round(n - d);
    return copy[k - 1] + d * (copy[k] - copy[k - 1]);
}

From source file:com.opengamma.analytics.math.surface.ObjectsSurface.java

/**
 * @param xData An array of <i>x</i> data, not null, no null elements.
 * @param yData An array of <i>y</i> data, not null, no null elements. Must be the same length as the <i>x</i> data.
 * @param zData An array of <i>z</i> data, not null, no null elements. Must be the same length as the <i>x</i> data.
 *///  ww w  .  j a va  2  s  .c  om
public ObjectsSurface(final T[] xData, final U[] yData, final V[] zData) {
    super();
    Validate.notNull(xData, "x data");
    Validate.notNull(yData, "y data");
    Validate.notNull(zData, "z data");
    Validate.isTrue(xData.length == yData.length);
    Validate.isTrue(xData.length == zData.length);
    _n = xData.length;
    _xData = Arrays.copyOf(xData, _n);
    _yData = Arrays.copyOf(yData, _n);
    _zData = Arrays.copyOf(zData, _n);
}

From source file:org.leandreck.endpoints.processor.model.RequestMapping.java

public String[] value() {
    return Arrays.copyOf(value, value.length);
}