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:com.netflix.dyno.contrib.consul.ConsulHelper.java

public static Map<String, String> getMetadata(List<String> tags) {
    LinkedHashMap<String, String> metadata = new LinkedHashMap<>();
    if (tags != null) {
        for (String tag : tags) {
            String[] parts = StringUtils.split(tag, "=");
            switch (parts.length) {
            case 0:
                break;
            case 1:
                metadata.put(parts[0], parts[0]);
                break;
            case 2:
                metadata.put(parts[0], parts[1]);
                break;
            default:
                String[] end = Arrays.copyOfRange(parts, 1, parts.length);
                metadata.put(parts[0], StringUtils.join(end, "="));
                break;
            }//  ww  w.ja v  a  2 s . c o m

        }
    }

    return metadata;
}

From source file:de.tudarmstadt.ukp.dkpro.tc.core.feature.InstanceIdFeature.java

public static Feature retrieve(JCas jcas, TextClassificationUnit unit, Integer sequenceId) {
    String fullId = DocumentMetaData.get(jcas).getDocumentId();
    String[] parts = fullId.split("_");
    fullId = StringUtils.join(Arrays.copyOfRange(parts, 0, parts.length - 1), "_");

    fullId = fullId + "_" + sequenceId;
    fullId = fullId + "_" + unit.getId();

    String suffix = unit.getSuffix();
    if (suffix != null && suffix.length() > 0) {
        fullId = fullId + "_" + suffix;
    }/* w w w. ja v  a 2s.  c om*/

    return new Feature(ID_FEATURE_NAME, fullId);
}

From source file:com.opengamma.analytics.financial.timeseries.analysis.AutocovarianceFunctionCalculator.java

@Override
public double[] evaluate(final DoubleTimeSeries<?> x) {
    Validate.notNull(x, "x");
    if (x.isEmpty()) {
        throw new IllegalArgumentException("Time series was empty");
    }/*from  ww w .  j  a  v  a2  s . c om*/
    final int h = x.size() - 1;
    final double[] result = new double[h];
    final double mean = _meanCalculator.evaluate(x);
    double[] x1, x2;
    final int n = x.size();
    double sum;
    final double[] x0 = x.valuesArrayFast();
    for (int i = 0; i < h; i++) {
        x1 = Arrays.copyOfRange(x0, 0, n - i);
        x2 = Arrays.copyOfRange(x0, i, n);
        if (x1.length != x2.length) {
            throw new IllegalArgumentException("Series were not the same length; this should not happen");
        }
        sum = 0;
        for (int j = 0; j < x1.length; j++) {
            sum += (x1[j] - mean) * (x2[j] - mean);
        }
        result[i] = sum / n;
    }
    return result;
}

From source file:com.inmobi.messaging.util.AuditUtil.java

public static ByteBuffer removeHeader(byte[] data) {
    if (isValidHeaders(data)) {
        return ByteBuffer.wrap(Arrays.copyOfRange(data, HEADER_LENGTH, data.length));
    } else {/*  w  w w.  j  a v a 2s. co  m*/
        return ByteBuffer.wrap(data);
    }
}

From source file:edu.oregonstate.eecs.mcplan.domains.voyager.Main.java

private static PolicyFactory<VoyagerState, VoyagerEvent, VoyagerParameters, VoyagerInstance> createPolicy(
        final String[] args) {
    final String policy_name = args[0];
    final String[] policy_args = Arrays.copyOfRange(args, 1, args.length);
    if ("FastExpandPolicy".equals(policy_name)) {
        // TODO:/*from  ww w.  j  a  v  a 2 s  . co m*/
        return null;
    } else {
        throw new IllegalArgumentException();
    }
}

From source file:com.codebutler.farebot.transit.myway.MyWayTagRecord.java

public MyWayTagRecord(byte[] record) {
    byte[] ts = Utils.reverseBuffer(record, 3, 4);
    mTimestamp = Utils.byteArrayToInt(ts);

    mTagOn = record[7] == 0x10;//w w  w .  j a  v a 2s.co m

    byte[] route = Arrays.copyOfRange(record, 8, 4 + 8);
    route = ArrayUtils.removeAllOccurences(route, (byte) 0x00);
    mRoute = new String(route);

    byte[] cost = Utils.reverseBuffer(record, 13, 2);
    mCost = Utils.byteArrayToInt(cost);

}

From source file:com.ning.arecibo.util.timeline.times.TimesAndSamplesCoder.java

public static TimeBytesAndSampleBytes getTimesBytesAndSampleBytes(final byte[] timesAndSamples) {
    final int timeByteCount = getSizeOfTimeBytes(timesAndSamples);
    final byte[] timeBytes = Arrays.copyOfRange(timesAndSamples, 4, 4 + timeByteCount);
    final byte[] sampleBytes = Arrays.copyOfRange(timesAndSamples, 4 + timeByteCount, timesAndSamples.length);
    return new TimeBytesAndSampleBytes(timeBytes, sampleBytes);
}

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

/**
 * @param x The array of data, not null. Must contain at least three points.
 * @return The quartile skewness.//from  w  w w.ja v a 2  s.c om
 */
@Override
public Double evaluate(final double[] x) {
    Validate.notNull(x, "x");
    final int n = x.length;
    Validate.isTrue(n >= 3, "Need at least three points to calculate interquartile range");
    if (n == 3) {
        return (x[2] - 2 * x[1] + x[0]) / 2.;
    }
    final double[] copy = Arrays.copyOf(x, n);
    Arrays.sort(copy);
    double[] lower, upper;
    if (n % 2 == 0) {
        lower = Arrays.copyOfRange(copy, 0, n / 2);
        upper = Arrays.copyOfRange(copy, n / 2, n);
    } else {
        lower = Arrays.copyOfRange(copy, 0, n / 2 + 1);
        upper = Arrays.copyOfRange(copy, n / 2, n);
    }
    final double q1 = MEDIAN.evaluate(lower);
    final double q2 = MEDIAN.evaluate(x);
    final double q3 = MEDIAN.evaluate(upper);
    return (q1 - 2 * q2 + q3) / (q3 - q1);
}

From source file:io.dyn.core.handler.Handlers.java

@SuppressWarnings({ "unchecked" })
public static void invoke(final Object handler, final Object... args) {
    if (handler instanceof io.dyn.core.handler.Handler) {
        int argc = args.length;
        Object argument = (argc > 0 ? args[0] : null);
        Object[] otherArgs = (argc > 1 ? Arrays.copyOfRange(args, 1, args.length - 1) : new Object[0]);
        ((io.dyn.core.handler.Handler) handler).handle(argument, otherArgs);
        return;//w  w  w .ja  va  2  s .  c om
    }
    if (Sys.isGroovyPresent()) {
        if (handler instanceof groovy.lang.Closure) {
            groovy.lang.Closure cl = ((groovy.lang.Closure) handler);
            Class[] paramTypes = cl.getParameterTypes();

            if (paramTypes.length == 0) {
                cl.call();
            } else {
                Object[] params = new Object[paramTypes.length];
                if (null != args && args.length > 0) {
                    for (int i = 0; i < params.length; i++) {
                        if (null != args[i] && !ClassUtils.isAssignable(args[i].getClass(), paramTypes[i])) {
                            params[i] = Sys.DEFAULT_CONVERSION_SERVICE.convert(args[i], paramTypes[i]);
                        } else {
                            params[i] = args[i];
                        }
                    }
                    cl.call(params);
                } else {
                    cl.call(args);
                }
            }
            return;
        }
    }
    /*
    if (Sys.isScalaPresent()) {
      if (handler instanceof scala.Function1) {
        ((scala.Function1) handler).apply(argument);
        return;
      }
    }
    */
    /*
    if (Sys.isClojurePresent()) {
      if (handler instanceof clojure.lang.IFn) {
        ((clojure.lang.IFn) handler).invoke(argument);
        return;
      }
    }
    */
    if (handler instanceof Runnable) {
        ((Runnable) handler).run();
    }
}

From source file:Main.java

/**
 * Returns all threads that have a name matching the specified pattern name.
 * // ww  w. j a  v  a  2 s  . c  o  m
 * @param threadNamePattern
 *            regex to match.
 * 
 * @return all threads that have a name matching the specified pattern name.
 */
public static Thread[] getAllThreads(String threadNamePattern) {
    Thread[] threads = getAllThreads();

    Thread[] filteredThreads = new Thread[threads.length];

    int i = 0;
    for (Thread t : threads) {
        if (t.getName().matches(threadNamePattern)) {
            filteredThreads[i] = t;
            i++;
        }
    }

    return Arrays.copyOfRange(filteredThreads, 0, i);
}