Example usage for java.util Arrays copyOfRange

List of usage examples for java.util Arrays copyOfRange

Introduction

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

Prototype

public static boolean[] copyOfRange(boolean[] original, int from, int to) 

Source Link

Document

Copies the specified range of the specified array into a new array.

Usage

From source file:in.dream_lab.bm.stream_iot.storm.bolts.IoTStatsBolt.ParseProjectTAXIBolt.java

@Override
public void execute(Tuple input) {
    String rowString = input.getStringByField("RowString");
    String msgId = input.getStringByField("MSGID");

    {/*  ww w  .  j  a  va2  s.  com*/

        String[] rowStringArray = rowString.split(",");

        taxiDetails = StringUtils.join(Arrays.copyOfRange(rowStringArray, 0, 4), ","); //TODO: up to 3 rd
        taxiID = rowStringArray[0];

        observedValArrtemp = new String[] { rowStringArray[4], rowStringArray[5] };
        observedValArr = (String[]) ArrayUtils.addAll(observedValArrtemp,
                Arrays.copyOfRange(rowStringArray, 11, 17));

        if (l.isInfoEnabled())
            l.info("taxiDetails : " + taxiDetails + "observedValArr TAXI -" + Arrays.toString(observedValArr));

        for (int obsIndex = 0; obsIndex < observedValArr.length; obsIndex++) {
            //                    System.out.println("Emitting form parse bolt " +taxiDetails + " "+taxiID + " "+obsType[obsIndex] + " "+observedValArr[obsIndex] + " "+msgId);
            collector.emit(new Values(taxiDetails, taxiID, obsType[obsIndex], observedValArr[obsIndex], msgId));
        }

    }
}

From source file:com.itemanalysis.psychometrics.analysis.AbstractMultivariateFunction.java

/**
 * Numerically compute gradientAt by the central difference method. Override this method
 * when the analytic gradientAt is available.
 *
 *
 * @param x/*from  ww  w.j ava 2  s.c  o  m*/
 * @return
 */
public double[] gradientAt(double[] x) {
    int n = x.length;
    double[] grd = new double[n];
    double[] u1 = new double[n];
    double[] u2 = new double[n];
    double f1 = 0.0;
    double f2 = 0.0;
    double stepSize = 0.0001;

    for (int i = 0; i < n; i++) {
        u1 = Arrays.copyOfRange(x, 0, x.length);
        u2 = Arrays.copyOfRange(x, 0, x.length);

        //            stepSize = Math.sqrt(EPSILON)*(Math.abs(x[i])+1.0);//from SAS manual on nlp procedure
        u1[i] = (x[i] + stepSize);
        u2[i] = (x[i] - stepSize);

        f1 = value(u1);
        f2 = value(u2);
        grd[i] = (f1 - f2) / (2.0 * stepSize);
    }
    return grd;
}

From source file:com.elasticbox.jenkins.k8s.repositories.api.charts.github.GitHubUrl.java

public String[] pathAsArray() {
    final String[] split = parsedUrl.getPath().split("/");
    return Arrays.copyOfRange(split, 1, split.length - 1);
}

From source file:com.joyent.manta.client.crypto.EncryptingEntityTest.java

@Test(expectedExceptions = MantaClientEncryptionException.class)
public void throwsWithTooLargeContentLength() {
    SupportedCipherDetails cipherDetails = AesGcmCipherDetails.INSTANCE_128_BIT;
    byte[] keyBytes = SecretKeyUtils.generate(cipherDetails).getEncoded();

    SecretKey key = SecretKeyUtils.loadKey(Arrays.copyOfRange(keyBytes, 2, 10), cipherDetails);

    ExposedStringEntity stringEntity = new ExposedStringEntity("boo", StandardCharsets.US_ASCII);

    EncryptingEntity entity = new EncryptingEntity(key, cipherDetails, stringEntity);
}

From source file:gov.nist.healthcare.ttt.webapp.api.GetCCDAFolderTest.java

public static HashMap<String, Object> buildJson(HashMap<String, Object> parent, String[] path) {
    if (path.length == 1) {
        if (Pattern.matches(extensionRegex, path[0])) {
            return createFile(path[0]);
        } else {//from  ww w.  j av a 2  s  .  co  m
            return createDir(path[0]);
        }
    } else {
        HashMap<String, Object> nextParent = createDir(path[0]);
        parent.putAll(buildJson(nextParent, Arrays.copyOfRange(path, 1, path.length)));
        return parent;
    }
}

From source file:org.mitre.secretsharing.server.FormJoinServlet.java

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    Writer w = new HtmlXSSWriter(resp.getWriter());

    try {//from   www . j a v a 2  s  .  com
        String parts = req.getParameter("parts");
        if (parts == null)
            throw new RuntimeException("No secret parts provided");

        boolean base64 = false;
        if (req.getParameter("base64") != null)
            base64 = Boolean.parseBoolean(req.getParameter("base64"));

        List<Part> partsBytes = new ArrayList<Part>();
        for (String s : parts.split("\n")) {
            s = s.trim();
            if (s.isEmpty())
                continue;
            try {
                partsBytes.add(PartFormats.parse(s));
            } catch (Exception e) {
                throw new RuntimeException("Corrupt key part \"" + s + "\""
                        + (e.getMessage() == null ? ": Improper encoding of secret parts"
                                : ": " + e.getMessage()),
                        e);
            }
        }

        Part[] p = partsBytes.toArray(new Part[0]);

        byte[] secret = p[0].join(Arrays.copyOfRange(p, 1, p.length));

        if (base64)
            w.write(Base64Variants.MIME.encode(secret));
        else
            w.write(new String(secret, "UTF-8"));
    } catch (Throwable t) {
        if (t.getMessage() != null)
            w.write("error: " + t.getMessage());
        else
            w.write("error");
    }
}

From source file:gobblin.util.reflection.GobblinConstructorUtils.java

/**
 * Returns a new instance of the <code>cls</code> based on a set of arguments. The method will search for a
 * constructor accepting the first k arguments in <code>args</code> for every k from args.length to 0, and will
 * invoke the first constructor found./*from  w  w w. j av  a2 s .c  om*/
 *
 * For example, {@link #invokeLongestConstructor}(cls, myString, myInt) will first attempt to create an object with
 * of class <code>cls</code> with constructor <init>(String, int), if it fails it will attempt <init>(String), and
 * finally <init>().
 *
 * @param cls the class to instantiate.
 * @param args the arguments to use for instantiation.
 * @throws ReflectiveOperationException
 */
public static <T> T invokeLongestConstructor(Class<T> cls, Object... args) throws ReflectiveOperationException {

    Class<?>[] parameterTypes = new Class[args.length];
    for (int i = 0; i < args.length; i++) {
        parameterTypes[i] = args[i].getClass();
    }

    for (int i = args.length; i >= 0; i--) {
        if (ConstructorUtils.getMatchingAccessibleConstructor(cls,
                Arrays.copyOfRange(parameterTypes, 0, i)) != null) {
            log.info(String.format("Found accessible constructor for class %s with parameter types %s.", cls,
                    Arrays.toString(Arrays.copyOfRange(parameterTypes, 0, i))));
            return ConstructorUtils.invokeConstructor(cls, Arrays.copyOfRange(args, 0, i));
        }
    }
    throw new NoSuchMethodException(
            String.format("No accessible constructor for class %s with parameters a subset of %s.", cls,
                    Arrays.toString(parameterTypes)));
}

From source file:com.opengsn.controller.client.ControllerClient.java

/**
 * Use the commandline args to invoke the proper service client and
 * operation using Reflection//w ww.ja v a  2 s  .com
 * 
 * @param args
 */
private void process(String[] args) {

    Class<?> c = this.getClass();
    try {
        // Class<?> c =
        // Class.forName("com.greenstarnetwork.controller.client.ControllerWrapper");

        // Use reflection to call the service and operation that was given
        // from the command line
        Object obj = c.newInstance();
        @SuppressWarnings("rawtypes")
        Class[] argTypes = new Class[] { String[].class };
        Method m = c.getDeclaredMethod(args[0], argTypes);

        String[] methodArgs = Arrays.copyOfRange(args, 1, args.length);
        System.out.println("invoking Operation: " + c.getName() + "." + m.getName());
        m.invoke(obj, (Object) methodArgs);

    } catch (NoSuchMethodException e) {
        System.out.println("Invalid Operation: " + args[1]);
        System.out.println("Operations for the " + c.getName() + ": ");
        Method[] allMethods = c.getDeclaredMethods();
        for (Method m : allMethods) {
            System.out.println("  " + m.getName());
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:bachelorthesis.captchabuilder.builder.CaptchaBuildSequenceParser.java

/**
 * Modifies the CaptchaBuilder to store a list of ElementCreatorBuilders the
 * parsers made//www.  j a v a  2 s .c  o m
 * from the buildstring.
 *
 * @param builder the CaptchBuilder object to be modified
 * <p/>
 * @throws ParseException
 * @see CaptchaBuilder
 */
public static void longParse(CaptchaBuilder builder) throws ParseException {

    for (String lvl1Arg : builder.getBuildSequence().split(CaptchaConstants.buildSequencelvl1Delim)) {
        if (!lvl1Arg.isEmpty()) {
            try {
                String[] optionArgs = lvl1Arg.split(CaptchaConstants.buildSequencelvl2Delim);
                BuildSequenceOptions buildSequenceOptionType = BuildSequenceOptions.valueOf(optionArgs[0]);
                String[] buildSequenceOptions = Arrays.copyOfRange(optionArgs, 1, optionArgs.length);

                builder = parseBuildSequenceOption(buildSequenceOptionType, buildSequenceOptions, builder);

            } catch (IllegalArgumentException e) {
                throw new ParseException(e.getMessage());
            }
        }
    }
}

From source file:com.netflix.imfutility.ttmltostl.stl.StlTtiTest.java

@Test
public void testSubtitleZero() throws Exception {
    TimedTextObject tto = StlTestUtil.buildTto("10:00:00:00", "10:00:05:00", "text1", "10:00:05:00",
            "10:00:10:12", "text2", "10:04:59:00", "23:59:59:24", "text3");
    byte[][] stl = StlTestUtil.build(tto, StlTestUtil.getMetadataXml());
    byte[] tti = stl[1];

    // subtitle zero
    assertArrayEquals(new byte[] { 0x00, // group number - 0
            0x00, 0x00, // subtitle number - 0
            (byte) 0xff, // extension block - default
            0x00, // cumulative status - 00 (no cumulative)
            0x00, 0x00, 0x00, 0x00, // code in: 00:00:00:00
            0x00, 0x00, 0x01, 0x00, // code out: 00:00:01:00 // default for zero subtitle
            0x16, // vertical position
            0x02, // centered by default
            0x00, // comment - 00 (contains subtitle)
    }, Arrays.copyOfRange(tti, 0, 16));

    // 1st block: text
    assertArrayEquals(fillExpectedText(new byte[] { 0x50, 0x72, 0x6f, 0x67, 0x72, 0x61, 0x6d, 0x6d, 0x65 // 'Programme' as in metadata.xml
    }), Arrays.copyOfRange(tti, 16, 128));
}