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:msi.gama.util.GamaListFactory.java

public static IList<Double> createWithoutCasting(final IType contentType, final double[] objects) {
    final IList<Double> list = create(contentType, objects.length);
    list.addAll(Arrays.asList(ArrayUtils.toObject(objects)));
    return list;/*ww w.  j  av  a2  s  . c  o m*/
}

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

@Override
protected Set<ComputedValue> computeValues(final InstrumentDerivative derivative,
        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);/* ww w.j  a va2 s. co m*/
    final NodalDoublesSurface vegaSurface = CALCULATOR.calcBlackVegaForEntireSurface(derivative, market, SHIFT);
    final Double[] xValues;
    final Double[] yValues;
    if (market.getVolatilitySurface() instanceof BlackVolatilitySurfaceMoneynessFcnBackedByGrid) {
        final BlackVolatilitySurfaceMoneynessFcnBackedByGrid volDataBundle = (BlackVolatilitySurfaceMoneynessFcnBackedByGrid) market
                .getVolatilitySurface();
        xValues = ArrayUtils.toObject(volDataBundle.getGridData().getExpiries());
        final double[][] strikes2d = volDataBundle.getGridData().getStrikes();
        final Set<Double> strikeSet = new HashSet<>();
        for (final double[] element : strikes2d) {
            strikeSet.addAll(Arrays.asList(ArrayUtils.toObject(element)));
        }
        yValues = strikeSet.toArray(new Double[] {});
    } else {
        xValues = vegaSurface.getXData();
        yValues = vegaSurface.getYData();
    }

    final Set<Double> xSet = new HashSet<>(Arrays.asList(xValues));
    final Set<Double> ySet = new HashSet<>(Arrays.asList(yValues));
    final Double[] uniqueX = xSet.toArray(new Double[0]);
    final String[] expLabels = new String[uniqueX.length];
    // Format the expiries for display
    for (int i = 0; i < uniqueX.length; i++) {
        uniqueX[i] = roundTwoDecimals(uniqueX[i]);
        expLabels[i] = VegaMatrixUtils.getFXVolatilityFormattedExpiry(uniqueX[i]);
    }
    final Double[] uniqueY = ySet.toArray(new Double[0]);
    final double[][] values = new double[ySet.size()][xSet.size()];
    int i = 0;
    for (final Double x : xSet) {
        int j = 0;
        for (final Double y : ySet) {
            double vega;
            try {
                vega = vegaSurface.getZValue(x, y);
            } catch (final IllegalArgumentException e) {
                vega = 0;
            }
            values[j++][i] = vega;
        }
        i++;
    }
    final DoubleLabelledMatrix2D matrix = new DoubleLabelledMatrix2D(uniqueX, expLabels, uniqueY, uniqueY,
            values);
    return Collections.singleton(new ComputedValue(resultSpec, matrix));
}

From source file:examples.utils.CifarReader.java

public static List<double[]> rawDouble(InputStream is) {
    List<double[]> result = new ArrayList<>();
    int row = 1 + (IMAGE_WIDTH * IMAGE_HIGHT * IMAGE_DEPTH);
    try {/*from   w ww . j ava  2 s  .  c om*/
        while (is.available() > 0) {
            byte[] arr = new byte[row];
            is.read(arr);
            result.add(
                    Arrays.stream(ArrayUtils.toObject(arr)).mapToDouble(b -> Byte.toUnsignedInt(b)).toArray());
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        IOUtils.closeQuietly(is);
    }
    return result;
}

From source file:com.opengamma.analytics.math.statistics.leastsquare.GeneralizedLeastSquare.java

/**
 * Generalised least square with penalty on (higher-order) finite differences of weights
 * @param <T> The type of the independent variables (e.g. Double, double[], DoubleMatrix1D etc)
 * @param x independent variables/*from  w  w  w  .j a va  2 s  .  co  m*/
 * @param y dependent (scalar) variables
 * @param sigma (Gaussian) measurement error on dependent variables
 * @param basisFunctions set of basis functions - the fitting function is formed by these basis functions times a set of weights
 * @param lambda strength of penalty function
 * @param differenceOrder difference order between weights used in penalty function
 * @return the results of the least square
 */
public <T> GeneralizedLeastSquareResults<T> solve(final T[] x, final double[] y, final double[] sigma,
        final List<Function1D<T, Double>> basisFunctions, final double lambda, final int differenceOrder) {
    ArgumentChecker.notNull(x, "x null");
    ArgumentChecker.notNull(y, "y null");
    ArgumentChecker.notNull(sigma, "sigma null");
    ArgumentChecker.notEmpty(basisFunctions, "empty basisFunctions");
    final int n = x.length;
    ArgumentChecker.isTrue(n > 0, "no data");
    ArgumentChecker.isTrue(y.length == n, "y wrong length");
    ArgumentChecker.isTrue(sigma.length == n, "sigma wrong length");

    ArgumentChecker.isTrue(lambda >= 0.0, "negative lambda");
    ArgumentChecker.isTrue(differenceOrder >= 0, "difference order");

    final List<T> lx = Lists.newArrayList(x);
    final List<Double> ly = Lists.newArrayList(ArrayUtils.toObject(y));
    final List<Double> lsigma = Lists.newArrayList(ArrayUtils.toObject(sigma));

    return solveImp(lx, ly, lsigma, basisFunctions, lambda, differenceOrder);
}

From source file:com.adaptris.core.services.jdbc.JdbcBatchingDataCaptureService.java

protected static long rowsUpdated(int[] rc) throws SQLException {
    List<Integer> result = Arrays.asList(ArrayUtils.toObject(rc));
    if (result.contains(Statement.EXECUTE_FAILED)) {
        throw new SQLException("Batch Execution Failed.");
    }//from  ww w .ja  va  2s  . co  m
    return result.stream().filter(e -> !(e == Statement.SUCCESS_NO_INFO)).mapToLong(i -> i).sum();
}

From source file:com.mg.framework.service.ApplicationDictionaryImpl.java

private com.mg.framework.api.ui.Form loadForm(int classId, String formName,
        RuntimeMacrosLoader runtimeMacrosLoader) throws ApplicationException {
    if (log.isDebugEnabled())
        log.debug("load UI form: " + formName);

    DetachedCriteria dc = DetachedCriteria.forEntityName("com.mg.merp.core.model.Form", "fLayer")
            .setProjection(Projections.max("fLayer.ApplicationLayer"))
            .add(Restrictions.eqProperty("fLayer.Name", "f.Name"))
            .add(Restrictions.eqProperty("fLayer.SysClass", "f.SysClass"));
    List<String> formControllerImplNames = OrmTemplate.getInstance()
            .findByCriteria(OrmTemplate.createCriteria("com.mg.merp.core.model.Form", "f")
                    .setProjection(Projections.property("f.Implementation"))
                    .add(Restrictions.eq("f.Name", formName)).add(Restrictions.eq("f.SysClass.Id", classId))
                    .add(Restrictions.or(Restrictions.isNull("f.Role"),
                            Restrictions.in("f.Role.Id",
                                    (Object[]) ArrayUtils.toObject(ServerUtils.getUserProfile().getGroups()))))
                    .add(Restrictions.or(Restrictions.isNull("f.User"),
                            Restrictions.eq("f.User.Id", ServerUtils.getUserProfile().getIdentificator())))
                    .add(Subqueries.propertyEq("f.ApplicationLayer", dc)).setCacheable(true)
                    .setCacheRegion("com/mg/jet/ui/forms/").setFlushMode(FlushMode.MANUAL));
    if (formControllerImplNames.size() == 0) {
        log.warn("Form is not found: ".concat(formName));
        throw new ApplicationException(
                Messages.getInstance().getMessage(Messages.FORM_NOT_FOUND, new Object[] { formName }));
    }/*from  w  w  w .  j a v  a 2 s . c  o m*/
    String formControllerImplName = formControllerImplNames.get(0);
    if (formControllerImplName == null)
        throw new IllegalStateException("Name of form controller is null. Form " + formName);
    return UIProducer.produceForm(formControllerImplName, runtimeMacrosLoader);
}

From source file:fr.moribus.imageonmap.gui.MapDetailGui.java

@Override
protected void onUpdate() {
    /// Title of the map details GUI
    setTitle(I.t(getPlayerLocale(), "Your maps  {black}{0}", map.getName()));
    setKeepHorizontalScrollingSpace(true);

    if (map instanceof PosterMap) {
        PosterMap poster = (PosterMap) map;
        if (poster.hasColumnData()) {
            setDataShape(poster.getColumnCount(), poster.getRowCount());
        } else {//from  ww w  .  ja  v a2  s .com
            setData(ArrayUtils.toObject(poster.getMapsIDs()));
        }
    } else {
        setDataShape(1, 1);
    }

    action("rename", getSize() - 7,
            new ItemStackBuilder(Material.BOOK_AND_QUILL)
                    .title(I.t(getPlayerLocale(), "{blue}Rename this image")).longLore(I.t(getPlayerLocale(),
                            "{gray}Click here to rename this image; this is used for your own organization.")));

    action("delete", getSize() - 6,
            new ItemStackBuilder(Material.BARRIER).title(I.t(getPlayerLocale(), "{red}Delete this image"))
                    .longLore(I.t(getPlayerLocale(),
                            "{gray}Deletes this map {white}forever{gray}. This action cannot be undone!"))
                    .loreLine().longLore(I.t(getPlayerLocale(),
                            "{gray}You will be asked to confirm your choice if you click here.")));

    // To keep the controls centered, the back button is shifted to the right when the
    // arrow isn't displayed, so when the map fit on the grid without sliders.
    int backSlot = getSize() - 4;

    if (map instanceof PosterMap && ((PosterMap) map).getColumnCount() <= INVENTORY_ROW_SIZE)
        backSlot++;

    action("back", backSlot,
            new ItemStackBuilder(Material.EMERALD).title(I.t(getPlayerLocale(), "{green} Back"))
                    .lore(I.t(getPlayerLocale(), "{gray}Go back to the list.")));
}

From source file:com.linkedin.pinot.tools.scan.query.Projection.java

public ResultTable run() {
    ResultTable resultTable = new ResultTable(_columnList, _filteredDocIds.size());
    resultTable.setResultType(ResultTable.ResultType.Selection);

    for (Pair pair : _columnList) {
        String column = (String) pair.getFirst();
        if (!_mvColumns.contains(column)) {
            BlockSingleValIterator bvIter = (BlockSingleValIterator) _indexSegment.getDataSource(column)
                    .getNextBlock().getBlockValueSet().iterator();

            int rowId = 0;
            for (Integer docId : _filteredDocIds) {
                bvIter.skipTo(docId);/*  w w w.  j  a  va  2s. c o  m*/
                resultTable.add(rowId++, bvIter.nextIntVal());
            }
        } else {
            BlockMultiValIterator bvIter = (BlockMultiValIterator) _indexSegment.getDataSource(column)
                    .getNextBlock().getBlockValueSet().iterator();

            int rowId = 0;
            for (Integer docId : _filteredDocIds) {
                bvIter.skipTo(docId);
                int[] dictIds = _mvColumnArrayMap.get(column);
                int numMVValues = bvIter.nextIntVal(dictIds);

                dictIds = Arrays.copyOf(dictIds, numMVValues);
                resultTable.add(rowId++, ArrayUtils.toObject(dictIds));
            }
        }
    }

    return transformFromIdToValues(resultTable, _dictionaryMap, _addCountStar);
}

From source file:com.noterik.bart.fs.fscommand.dynamic.playlist.util.SBFile.java

public float getMax(int iCol) {
    List<Float> b = Arrays.asList(ArrayUtils.toObject(signals.get(iCol)));
    float max = Collections.max(b);
    b = null;/*from w  w  w.  j a  v  a 2 s. c o  m*/
    return max;
}

From source file:com.opengamma.analytics.math.statistics.leastsquare.GeneralizedLeastSquare.java

GeneralizedLeastSquareResults<Double> solve(final double[] x, final double[] y, final double[] sigma,
        final List<Function1D<Double, Double>> basisFunctions, final double lambda, final int differenceOrder) {
    return solve(ArrayUtils.toObject(x), y, sigma, basisFunctions, lambda, differenceOrder);
}