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.palantir.atlasdb.keyvalue.rocksdb.impl.RocksDbKeyValueServices.java

static Pair<Cell, Long> parseCellAndTs(byte[] key) {
    byte[] rowSizeBytes = new byte[2];
    rowSizeBytes[0] = key[key.length - 1];
    rowSizeBytes[1] = key[key.length - 2];

    int rowSize = (int) EncodingUtils.decodeVarLong(rowSizeBytes);
    int colEnd = key.length - 8 - EncodingUtils.sizeOfVarLong(rowSize);

    byte[] rowName = Arrays.copyOf(key, rowSize);
    byte[] colName = Arrays.copyOfRange(key, rowSize, colEnd);
    long ts = Longs.fromBytes(key[colEnd + 0], key[colEnd + 1], key[colEnd + 2], key[colEnd + 3],
            key[colEnd + 4], key[colEnd + 5], key[colEnd + 6], key[colEnd + 7]);

    return Pair.create(Cell.create(rowName, colName), ts);
}

From source file:no.difi.sdp.client.internal.DigipostMessageSenderFacade.java

public DigipostMessageSenderFacade(final TekniskAvsender avsender, final KlientKonfigurasjon konfigurasjon) {
    KeyStoreInfo keyStoreInfo = avsender.noekkelpar.getKeyStoreInfo();
    WsSecurityInterceptor wsSecurityInterceptor = new WsSecurityInterceptor(keyStoreInfo,
            new UserFriendlyWsSecurityExceptionMapper());
    wsSecurityInterceptor.afterPropertiesSet();

    MessageSender.Builder messageSenderBuilder = MessageSender
            .create(konfigurasjon.getMeldingsformidlerRoot().toString(), keyStoreInfo, wsSecurityInterceptor,
                    EbmsAktoer.avsender(avsender.organisasjonsnummer),
                    EbmsAktoer.meldingsformidler(konfigurasjon.getMeldingsformidlerOrganisasjon()))
            .withConnectTimeout((int) konfigurasjon.getConnectTimeoutInMillis())
            .withSocketTimeout((int) konfigurasjon.getSocketTimeoutInMillis())
            .withConnectionRequestTimeout((int) konfigurasjon.getConnectionRequestTimeoutInMillis())
            .withDefaultMaxPerRoute(konfigurasjon.getMaxConnectionPoolSize()) // Vi vil i praksis bare kjre n route med denne klienten.
            .withMaxTotal(konfigurasjon.getMaxConnectionPoolSize());

    if (konfigurasjon.useProxy()) {
        messageSenderBuilder.withHttpProxy(konfigurasjon.getProxyHost(), konfigurasjon.getProxyPort(),
                konfigurasjon.getProxyScheme());
    }/*from w  ww .  ja  va2 s.  co m*/

    // Legg til http request interceptors fra konfigurasjon pluss vr egen.
    HttpRequestInterceptor[] httpRequestInterceptors = Arrays.copyOf(konfigurasjon.getHttpRequestInterceptors(),
            konfigurasjon.getHttpRequestInterceptors().length + 1);
    httpRequestInterceptors[httpRequestInterceptors.length - 1] = new AddClientVersionInterceptor();
    messageSenderBuilder.withHttpRequestInterceptors(httpRequestInterceptors);

    messageSenderBuilder.withHttpResponseInterceptors(konfigurasjon.getHttpResponseInterceptors());

    messageSenderBuilder.withMeldingInterceptorBefore(TransactionLogClientInterceptor.class,
            payloadValidatingInterceptor());

    for (ClientInterceptor clientInterceptor : konfigurasjon.getSoapInterceptors()) {
        // TransactionLogClientInterceptoren br alltid ligge ytterst for  sikre riktig transaksjonslogging (i tilfelle en custom interceptor modifiserer requestet)
        messageSenderBuilder.withMeldingInterceptorBefore(TransactionLogClientInterceptor.class,
                clientInterceptor);
    }

    messageSender = messageSenderBuilder.build();
}

From source file:com.opengamma.financial.analytics.LabelledMatrix3D.java

/**
 * Creates a new 3D labeled matrix.//ww w  .  j  a  v a  2 s.  c o m
 * 
 * @param xKeys keys for the X dimension
 * @param xLabels labels for the X dimension
 * @param yKeys keys for the Y dimension
 * @param yLabels labels for the Y dimension
 * @param zKeys keys for the Z dimension
 * @param zLabels labels for the Z dimension
 * @param values values of the matrix in the shape [Z][Y][X]
 */
public LabelledMatrix3D(final KX[] xKeys, final Object[] xLabels, final KY[] yKeys, final Object[] yLabels,
        final KZ[] zKeys, final Object[] zLabels, final double[][][] values) {
    ArgumentChecker.notNull(xKeys, "xKeys");
    ArgumentChecker.notNull(xLabels, "xLabels");
    ArgumentChecker.notNull(yKeys, "yKeys");
    ArgumentChecker.notNull(yLabels, "yLabels");
    ArgumentChecker.notNull(zKeys, "zKeys");
    ArgumentChecker.notNull(zLabels, "zLabels");
    ArgumentChecker.notNull(values, "values");
    final int x = xKeys.length;
    Validate.isTrue(xLabels.length == x, "invalid xLabels length");
    final int y = yKeys.length;
    Validate.isTrue(yLabels.length == y, "invalid yLabels length");
    final int z = zKeys.length;
    Validate.isTrue(zLabels.length == z, "invalid zLabels length");
    Validate.isTrue(values.length == z, "invalid zKeys length");
    _xKeys = Arrays.copyOf(xKeys, x);
    _xLabels = Arrays.copyOf(xLabels, x);
    _yKeys = Arrays.copyOf(yKeys, y);
    _yLabels = Arrays.copyOf(yLabels, y);
    _zKeys = Arrays.copyOf(zKeys, z);
    _zLabels = Arrays.copyOf(zLabels, z);
    _values = new double[z][y][x];
    for (int iz = 0; iz < z; iz++) {
        Validate.isTrue(values[iz].length == y, "invalid yKeys length");
        for (int iy = 0; iy < y; iy++) {
            Validate.isTrue(values[iz][iy].length == x, "invalid xKeys length");
            System.arraycopy(values[iz][iy], 0, _values[iz][iy], 0, x);
        }
    }
    quickSortX();
    quickSortY();
    quickSortZ();
}

From source file:com.nokia.helium.core.EmailDataSender.java

/**
 * Add current user to recipient list./*from w  w  w. j a  va2 s . co m*/
 * 
 */
public void addCurrentUserToAddressList() throws EmailSendException {
    // Create an empty array if needed
    if (toAddressList == null) {
        toAddressList = new String[0];
    }
    try {
        String[] tmpToAddressList = Arrays.copyOf(toAddressList, toAddressList.length + 1);
        tmpToAddressList[tmpToAddressList.length - 1] = getUserEmail();
        toAddressList = tmpToAddressList;
    } catch (LDAPException ex) {
        throw new EmailSendException(ex.getMessage(), ex);
    }
}

From source file:com.github.tell.mathematics.combinatorics.Combination.java

public T[][] makeCombination() {
    if (numberOfSelection == 0) {
        //noinspection unchecked
        return (T[][]) Array.newInstance(cls, 1, 0);

    } else if (numberOfSelection == 1) {
        @SuppressWarnings("unchecked")
        final T[][] result = (T[][]) Array.newInstance(cls, elements.length, 0);
        assert result.length == elements.length : String.format("result = %s, numberOfSelection = %s",
                Arrays.deepToString(result), numberOfSelection);
        for (int i = 0; i < elements.length; i++) {
            result[i] = Arrays.copyOfRange(elements, i, i + 1);
        }//  w  ww. j  a  va 2 s.c o  m
        return result;

    } else if (numberOfSelection == elements.length) {
        @SuppressWarnings("unchecked")
        final T[][] result = (T[][]) Array.newInstance(cls, 1, 0);
        result[0] = ArrayUtils.clone(elements);
        return result;

    } else if (numberOfSelection == elements.length - 1) {
        @SuppressWarnings("unchecked")
        final T[][] result = (T[][]) Array.newInstance(cls, elements.length, 0);
        for (int i = elements.length - 1; i >= 0; i--) {
            final int j = elements.length - 1 - i;
            result[j] = Arrays.copyOf(elements, i);
            result[j] = ArrayUtils.addAll(result[j], ArrayUtils.subarray(elements, i + 1, elements.length));
            logger.trace("generated array = {}", Arrays.deepToString(result[j]));
        }
        return result;

    } else {
        final T[] partialElements = Arrays.copyOf(elements, elements.length - 1);

        logger.trace("partialElements = {}, numberOfSelection = {}", Arrays.deepToString(partialElements),
                numberOfSelection);

        final Combination<T> leftHandSideGenerator = new Combination<T>(partialElements, numberOfSelection);
        final T[][] leftCombination = leftHandSideGenerator.makeCombination();

        final Combination<T> rightHandSideGenerator = new Combination<T>(partialElements,
                numberOfSelection - 1);
        final T[][] rightCombination = rightHandSideGenerator.makeCombination();
        for (int i = 0; i < rightCombination.length; i++) {
            rightCombination[i] = ArrayUtils.add(rightCombination[i], elements[elements.length - 1]);
        }

        //noinspection unchecked
        return ArrayUtils.addAll(leftCombination, rightCombination);
    }
}

From source file:hudson.logging.LogRecorder.java

@Restricted(NoExternalUse.class)
@VisibleForTesting/*from   ww w.j av  a  2s  . c  o  m*/
public static Set<String> getAutoCompletionCandidates(List<String> loggerNamesList) {
    Set<String> loggerNames = new HashSet<>(loggerNamesList);

    // now look for package prefixes that make sense to offer for autocompletion:
    // Only prefixes that match multiple loggers will be shown.
    // Example: 'org' will show 'org', because there's org.apache, org.jenkinsci, etc.
    // 'io' might only show 'io.jenkins.plugins' rather than 'io' if all loggers starting with 'io' start with 'io.jenkins.plugins'.
    HashMap<String, Integer> seenPrefixes = new HashMap<>();
    SortedSet<String> relevantPrefixes = new TreeSet<>();
    for (String loggerName : loggerNames) {
        String[] loggerNameParts = loggerName.split("[.]");

        String longerPrefix = null;
        for (int i = loggerNameParts.length; i > 0; i--) {
            String loggerNamePrefix = StringUtils.join(Arrays.copyOf(loggerNameParts, i), ".");
            seenPrefixes.put(loggerNamePrefix, seenPrefixes.getOrDefault(loggerNamePrefix, 0) + 1);
            if (longerPrefix == null) {
                relevantPrefixes.add(loggerNamePrefix); // actual logger name
                longerPrefix = loggerNamePrefix;
                continue;
            }

            if (seenPrefixes.get(loggerNamePrefix) > seenPrefixes.get(longerPrefix)) {
                relevantPrefixes.add(loggerNamePrefix);
            }
            longerPrefix = loggerNamePrefix;
        }
    }
    return relevantPrefixes;
}

From source file:gobblin.compaction.mapreduce.avro.AvroKeyRecursiveCombineFileInputFormat.java

/**
 * Set the number of locations in the split to SPLIT_MAX_NUM_LOCATIONS if it is larger than
 * SPLIT_MAX_NUM_LOCATIONS (MAPREDUCE-5186).
 *//*from w  w w. j a  va  2s.com*/
private static List<InputSplit> cleanSplits(List<InputSplit> splits) throws IOException {
    if (VersionInfo.getVersion().compareTo("2.3.0") >= 0) {
        // This issue was fixed in 2.3.0, if newer version, no need to clean up splits
        return splits;
    }

    List<InputSplit> cleanedSplits = Lists.newArrayList();

    for (int i = 0; i < splits.size(); i++) {
        CombineFileSplit oldSplit = (CombineFileSplit) splits.get(i);
        String[] locations = oldSplit.getLocations();

        Preconditions.checkNotNull(locations, "CombineFileSplit.getLocations() returned null");

        if (locations.length > SPLIT_MAX_NUM_LOCATIONS) {
            locations = Arrays.copyOf(locations, SPLIT_MAX_NUM_LOCATIONS);
        }

        cleanedSplits.add(new CombineFileSplit(oldSplit.getPaths(), oldSplit.getStartOffsets(),
                oldSplit.getLengths(), locations));
    }
    return cleanedSplits;
}

From source file:com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck.java

/**
 * @return file extensions that identify the files that pass the
 *     filter of this FileSetCheck.//  ww  w  .j a v  a  2 s .com
 */
public String[] getFileExtensions() {
    return Arrays.copyOf(fileExtensions, fileExtensions.length);
}

From source file:de.kopis.glacier.parsers.GlacierUploaderOptionParserTest.java

@Test
public void hasActionOptionUpload() {
    final String[] newArgs = Arrays.copyOf(args, args.length + 2);
    newArgs[newArgs.length - 2] = "--upload";
    newArgs[newArgs.length - 1] = "/path/to/file";

    final OptionSet optionSet = optionsParser.parse(newArgs);
    assertTrue("Option 'upload' not found in " + Arrays.deepToString(optionSet.specs().toArray()),
            optionSet.has("upload"));
    assertEquals("Value of option 'upload' not found in " + Arrays.deepToString(optionSet.specs().toArray()),
            new File("/path/to/file"), optionSet.valueOf("upload"));
}

From source file:aldenjava.opticalmapping.data.data.DataNode.java

/**
 * Constructs a new <code>DataNode</code>, initialized to match the values of the specified <code>DataNode</code>.
 * /*from w  ww . j a  v a2  s .co  m*/
 * @param data
 *            the <code>DataNode</code> from which to copy initial values to a newly constructed <code>DataNode</code>
 */
public DataNode(DataNode data) {
    this.name = data.name;
    this.size = data.size;
    this.refp = Arrays.copyOf(data.refp, data.refp.length);
    ;
    this.importSimulationInfo(data.simuInfo);
}