Example usage for org.apache.commons.lang ArrayUtils toObject

List of usage examples for org.apache.commons.lang ArrayUtils toObject

Introduction

In this page you can find the example usage for org.apache.commons.lang ArrayUtils toObject.

Prototype

public static Boolean[] toObject(boolean[] array) 

Source Link

Document

Converts an array of primitive booleans to objects.

Usage

From source file:ch.epfl.data.squall.components.theta.ThetaJoinComponent.java

@Override
public ThetaJoinComponent setOutputPartKey(int... hashIndexes) {
    return setOutputPartKey(Arrays.asList(ArrayUtils.toObject(hashIndexes)));
}

From source file:com.adobe.cq.wcm.core.components.models.impl.v1.ImageImpl.java

private void buildJson() {
    Map<String, Object> objectMap = new HashMap<>();
    objectMap.put(Image.JSON_SMART_SIZES, new JSONArray(Arrays.asList(ArrayUtils.toObject(smartSizes))));
    objectMap.put(Image.JSON_SMART_IMAGES, new JSONArray(Arrays.asList(smartImages)));
    objectMap.put(Image.JSON_LAZY_ENABLED, !disableLazyLoading);
    json = new JSONObject(objectMap).toString();
}

From source file:de.alpharogroup.file.checksum.ChecksumUtilsTest.java

/**
 * Test for {@link ChecksumUtils#getChecksum(Byte[], String)}
 * /*from  w ww. j a v a  2s.c  o  m*/
 * @throws UnsupportedEncodingException
 *             If the named charset is not supported
 * @throws NoSuchAlgorithmException
 *             Is thrown if the algorithm is not supported or does not exists.
 *             {@link java.security.MessageDigest} object.
 */
@Test
public void testGetChecksumByteObjectArrayString()
        throws UnsupportedEncodingException, NoSuchAlgorithmException {

    final String secretMessage = "secret Message";
    final byte[] sbytes = secretMessage.getBytes("UTF-8");
    final Byte[] secretMessageBytes = ArrayUtils.toObject(sbytes);
    String expected = "5cc16e663491726545c13ec2012f4601";
    String actual = ChecksumUtils.getChecksum(secretMessageBytes, Algorithm.MD2.getAlgorithm());
    Assert.assertEquals(expected, actual);

    expected = "25659bd9db98ecc3c2077d44e69607b8";
    actual = ChecksumUtils.getChecksum(secretMessageBytes, Algorithm.MD5.getAlgorithm());
    Assert.assertEquals(expected, actual);

    expected = "874026e54b67d4f9aaf87cb14a683fb51de6f9cb";
    actual = ChecksumUtils.getChecksum(secretMessageBytes, Algorithm.SHA_1.getAlgorithm());
    Assert.assertEquals(expected, actual);

    expected = "8a3b3c92a8b0eb00da917c23201a9407ef7963373464076aec4c54c066e8b7aa";
    actual = ChecksumUtils.getChecksum(secretMessageBytes, Algorithm.SHA_256.getAlgorithm());
    Assert.assertEquals(expected, actual);

    expected = "b58a362687ab42b9bf0d8af0b4860ed262d1fd128e16ab0082723e7785a862cd129b03577312452cc24aecdb36d5406d";
    actual = ChecksumUtils.getChecksum(secretMessageBytes, Algorithm.SHA_384.getAlgorithm());
    Assert.assertEquals(expected, actual);

    expected = "ab29b34a26547ca4ce517d776885a5642929d9ed571a990fc764f7d0b854d6546276ca9aa45b3d88db3dc3dbf3c2f2152017d3e3e054ed6cd7a38a1f7925a746";
    actual = ChecksumUtils.getChecksum(secretMessageBytes, Algorithm.SHA_512.getAlgorithm());
    Assert.assertEquals(expected, actual);
}

From source file:de.alpharogroup.file.checksum.ChecksumExtensionsTest.java

/**
 * Test for {@link ChecksumExtensions#getChecksum(Byte[], String)}
 * /* w w  w .j  av a2 s.  c  o m*/
 * @throws UnsupportedEncodingException
 *             If the named charset is not supported
 * @throws NoSuchAlgorithmException
 *             Is thrown if the algorithm is not supported or does not exists.
 *             {@link java.security.MessageDigest} object.
 */
@Test
public void testGetChecksumByteObjectArrayString()
        throws UnsupportedEncodingException, NoSuchAlgorithmException {

    final String secretMessage = "secret Message";
    final byte[] sbytes = secretMessage.getBytes("UTF-8");
    final Byte[] secretMessageBytes = ArrayUtils.toObject(sbytes);
    String expected = "5cc16e663491726545c13ec2012f4601";
    String actual = ChecksumExtensions.getChecksum(secretMessageBytes, Algorithm.MD2.getAlgorithm());
    Assert.assertEquals(expected, actual);

    expected = "25659bd9db98ecc3c2077d44e69607b8";
    actual = ChecksumExtensions.getChecksum(secretMessageBytes, Algorithm.MD5.getAlgorithm());
    Assert.assertEquals(expected, actual);

    expected = "874026e54b67d4f9aaf87cb14a683fb51de6f9cb";
    actual = ChecksumExtensions.getChecksum(secretMessageBytes, Algorithm.SHA_1.getAlgorithm());
    Assert.assertEquals(expected, actual);

    expected = "8a3b3c92a8b0eb00da917c23201a9407ef7963373464076aec4c54c066e8b7aa";
    actual = ChecksumExtensions.getChecksum(secretMessageBytes, Algorithm.SHA_256.getAlgorithm());
    Assert.assertEquals(expected, actual);

    expected = "b58a362687ab42b9bf0d8af0b4860ed262d1fd128e16ab0082723e7785a862cd129b03577312452cc24aecdb36d5406d";
    actual = ChecksumExtensions.getChecksum(secretMessageBytes, Algorithm.SHA_384.getAlgorithm());
    Assert.assertEquals(expected, actual);

    expected = "ab29b34a26547ca4ce517d776885a5642929d9ed571a990fc764f7d0b854d6546276ca9aa45b3d88db3dc3dbf3c2f2152017d3e3e054ed6cd7a38a1f7925a746";
    actual = ChecksumExtensions.getChecksum(secretMessageBytes, Algorithm.SHA_512.getAlgorithm());
    Assert.assertEquals(expected, actual);
}

From source file:gov.redhawk.model.sca.impl.ScaSimpleSequencePropertyImpl.java

@Override
protected void internalFromAny(Any newAny) {
    try {/*from   w  w w . j  a  v a2s.  co m*/
        if (newAny != null) {
            final Object value = AnyUtils.convertAny(newAny);
            if (value != null && value.getClass().isArray()) {
                Object[] array = null;
                if (value instanceof boolean[]) {
                    array = ArrayUtils.toObject((boolean[]) value);
                } else if (value instanceof byte[]) {
                    array = ArrayUtils.toObject((byte[]) value);
                } else if (value instanceof char[]) {
                    array = ArrayUtils.toObject((char[]) value);
                } else if (value instanceof double[]) {
                    array = ArrayUtils.toObject((double[]) value);
                } else if (value instanceof float[]) {
                    array = ArrayUtils.toObject((float[]) value);
                } else if (value instanceof int[]) {
                    array = ArrayUtils.toObject((int[]) value);
                } else if (value instanceof long[]) {
                    array = ArrayUtils.toObject((long[]) value);
                } else if (value instanceof short[]) {
                    array = ArrayUtils.toObject((short[]) value);
                } else if (value instanceof Object[]) {
                    array = (Object[]) value;
                }
                setValue(array);
            }
        } else {
            getValues().restoreDefaultValue();
        }
        setStatus(ScaPackage.Literals.SCA_SIMPLE_SEQUENCE_PROPERTY__VALUES, Status.OK_STATUS);
    } catch (Exception e) {
        setStatus(ScaPackage.Literals.SCA_SIMPLE_SEQUENCE_PROPERTY__VALUES, new Status(Status.ERROR,
                ScaModelPlugin.ID, "Failed to read property value of:" + getName(), e));
    }
}

From source file:ch.epfl.data.squall.operators.HeavyHittersOperator.java

@Override
public HeavyHittersOperator setGroupByColumns(int... hashIndexes) {
    return setGroupByColumns(Arrays.asList(ArrayUtils.toObject(hashIndexes)));
}

From source file:ch.epfl.data.squall.operators.ApproximateCountSketchOperator2.java

@Override
public ApproximateCountSketchOperator2 setGroupByColumns(int... hashIndexes) {
    return setGroupByColumns(Arrays.asList(ArrayUtils.toObject(hashIndexes)));
}

From source file:com.opengamma.financial.analytics.model.equity.option.EquityVanillaBarrierOptionVegaMatrixFunction.java

@Override
protected Set<ComputedValue> computeValues(final Set<EquityIndexOption> vanillaOptions,
        final StaticReplicationDataBundle market, final FunctionInputs inputs,
        final Set<ValueRequirement> desiredValues, final ComputationTargetSpecification targetSpec,
        final ValueProperties resultProperties) {
    final ValueSpecification resultSpec = new ValueSpecification(getValueRequirementNames()[0], targetSpec,
            resultProperties);//from  w  ww.j a v a 2 s.com
    final NodalDoublesSurface vegaSurface;
    if (market.getVolatilitySurface() instanceof BlackVolatilitySurfaceMoneynessFcnBackedByGrid) {
        // unpack the market data, including the interpolators
        final BlackVolatilitySurfaceMoneynessFcnBackedByGrid surfaceBundle = (BlackVolatilitySurfaceMoneynessFcnBackedByGrid) market
                .getVolatilitySurface();
        final VolatilitySurfaceInterpolator surfaceInterpolator = surfaceBundle.getInterpolator();
        final GeneralSmileInterpolator strikeInterpolator = surfaceInterpolator.getSmileInterpolator();
        final SmileSurfaceDataBundle volGrid = surfaceBundle.getGridData();
        final double[] forwards = volGrid.getForwards();
        final double[] expiries = volGrid.getExpiries();
        final int nExpiries = volGrid.getNumExpiries();
        final double optionExpiry = vanillaOptions.iterator().next().getTimeToExpiry();
        final double[][] strikes = volGrid.getStrikes();
        final double[][] vols = volGrid.getVolatilities();

        // Prices of vanillas in base scenario
        final int nVanillas = vanillaOptions.size();
        final EquityIndexOption[] vanillas = vanillaOptions.toArray(new EquityIndexOption[nVanillas]);
        final Double[] basePrices = new Double[nVanillas];
        for (int v = 0; v < nVanillas; v++) {
            basePrices[v] = PVC.visitEquityIndexOption(vanillas[v], market);
        }

        // Smile fits across strikes in base scenario, one per expiry
        final Function1D<Double, Double>[] smileFitsBase = surfaceInterpolator.getIndependentSmileFits(volGrid);

        // Bump market at each expiry and strike scenario
        // In each scenario, reprice each of the underlying vanillaOptions
        // NOTE: Only computing down-shift as this appears to produce more stable risk, and is faster
        final List<Triple<Double, Double, Double>> triplesExpiryStrikeVega = new ArrayList<>();
        final int expiryIndex = SurfaceArrayUtils.getLowerBoundIndex(expiries, optionExpiry);
        for (int t = Math.max(0, expiryIndex - 3); t < Math.min(nExpiries, expiryIndex + 4); t++) {
            final int nStrikes = strikes[t].length;
            int idxLow = SurfaceArrayUtils.getLowerBoundIndex(strikes[t], vanillas[0].getStrike());
            int idxHigh = idxLow;
            for (int v = 1; v < nVanillas; v++) {
                final int idxV = SurfaceArrayUtils.getLowerBoundIndex(strikes[t], vanillas[v].getStrike());
                idxLow = Math.min(idxLow, idxV);
                idxHigh = Math.max(idxHigh, idxV);
            }

            for (int k = Math.max(0, idxLow - 6); k < Math.min(nStrikes, idxHigh + 16); k++) {
                // Scenario (t,k)
                // TODO: REVIEW Each scenario only requires a single new smile fit in k. We only recompute the smile function for the expiry we are bumping..
                final double[] bumpedVols = Arrays.copyOf(vols[t], nStrikes);
                bumpedVols[k] = vols[t][k] - SHIFT;
                final Function1D<Double, Double> thisExpirysSmile = strikeInterpolator
                        .getVolatilityFunction(forwards[t], strikes[t], expiries[t], bumpedVols);
                final Function1D<Double, Double>[] scenarioSmileFits = Arrays.copyOf(smileFitsBase,
                        smileFitsBase.length);
                scenarioSmileFits[t] = thisExpirysSmile;
                final BlackVolatilitySurfaceMoneynessFcnBackedByGrid shiftedSurface = surfaceInterpolator
                        .combineIndependentSmileFits(scenarioSmileFits, volGrid);
                final StaticReplicationDataBundle shiftedMarket = market.withShiftedSurface(shiftedSurface);
                // Sensitivities
                for (int v = 0; v < nVanillas; v++) {
                    final Double shiftedPV = vanillas[v].accept(PVC, shiftedMarket);
                    Validate.notNull(shiftedPV,
                            "Null PV in shifted scenario, T = " + expiries[t] + ", k = " + strikes[t][k]);
                    final Double vega = (shiftedPV - basePrices[v]) / -SHIFT;
                    final Triple<Double, Double, Double> xyz = new Triple<>(expiries[t], strikes[t][k], vega);
                    triplesExpiryStrikeVega.add(xyz);
                }
            }
        }
        vegaSurface = NodalDoublesSurface.from(triplesExpiryStrikeVega);

        // Repackage into DoubleLabelledMatrix2D
        // Find unique set of expiries,
        final Double[] uniqueX = ArrayUtils.toObject(expiries);
        // and strikes
        final Set<Double> strikeSet = new HashSet<>();
        for (final double[] strike : strikes) {
            strikeSet.addAll(Arrays.asList(ArrayUtils.toObject(strike)));
        }
        final Double[] uniqueY = strikeSet.toArray(new Double[0]);
        // Fill matrix with values, zero where no vega is available
        final double[][] values = new double[uniqueY.length][uniqueX.length];
        int i = 0;
        for (final Double x : uniqueX) {
            int j = 0;
            for (final Double y : uniqueY) {
                double vega;
                try {
                    vega = vegaSurface.getZValue(x, y);
                } catch (final IllegalArgumentException e) {
                    vega = 0;
                }
                values[j++][i] = vega;
            }
            i++;
        }
        final DoubleLabelledMatrix2D vegaMatrix = new DoubleLabelledMatrix2D(uniqueX, uniqueY, values);
        return Collections.singleton(new ComputedValue(resultSpec, vegaMatrix));
    }
    throw new OpenGammaRuntimeException(
            "Currently will only accept a VolatilitySurface of type: BlackVolatilitySurfaceMoneynessFcnBackedByGrid");
}

From source file:com.flexive.shared.tree.FxTreeNode.java

/**
 * Return the ACL id(s) of the referenced content.
 *
 * @return the ACL id(s) of the referenced content.
 *//*www. j  a  v a2 s  .  c o m*/
public List<Long> getACLIds() {
    return Arrays.asList(ArrayUtils.toObject(acls));
}

From source file:ch.epfl.data.squall.operators.ApproximateCountSamplingOperator.java

@Override
public ApproximateCountSamplingOperator setGroupByColumns(int... hashIndexes) {
    return setGroupByColumns(Arrays.asList(ArrayUtils.toObject(hashIndexes)));
}