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:gda.device.detector.countertimer.TfgScalerWithDarkCurrent.java

private DarkCurrentResults collectDarkCurrent(final DarkCurrentBean bean) throws Exception {

    final Scannable shutter = (Scannable) Finder.getInstance().find(bean.getShutterName());
    String originalShutterPosition = shutter.getPosition().toString();

    if (!originalShutterPosition.equalsIgnoreCase("Close")) {
        shutter.moveTo("Close");
    }//from ww  w. j  av a2  s. com

    setCollectionTime(bean.getDarkCollectionTime());
    // do not change the collection time - simply re-use the current time which the
    collectData();

    Thread.sleep(Math.round(bean.getDarkCollectionTime()) * 1000); // Throws interrupted exception if the thread
    // executing this method.
    while (isBusy()) {
        // TODO timeout of 2*bean.getDarkCollectionTime()
        Thread.sleep(100);
    }

    double[] countsDbl = super.readout();
    if (timeChannelRequired) {
        countsDbl = ArrayUtils.subarray(countsDbl, 1, countsDbl.length);
    }
    Double[] counts = ArrayUtils.toObject(countsDbl);

    if (useReset) {
        shutter.moveTo("Reset");
    }
    shutter.moveTo("Open");

    setCollectionTime(bean.getOriginalCollectionTime());

    return new DarkCurrentResults(bean.getDarkCollectionTime(), counts);
}

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

public float getMin(int iCol) {
    List<Float> b = Arrays.asList(ArrayUtils.toObject(signals.get(iCol)));
    float min = Collections.min(b);
    b = null;//from   w ww . java 2 s  .co  m
    return min;
}

From source file:com.flexive.ejb.beans.workflow.RouteEngineBean.java

/** {@inheritDoc} */
@Override/*ww  w .  ja va2s  .  c om*/
public List<Step> getTargets(long fromStep) throws FxApplicationException {
    Connection con = null;
    String sql = null;
    Statement stmt = null;

    // Check fromStep
    Step step = CacheAdmin.getEnvironment().getStep(fromStep);

    try {
        final UserTicket ticket = FxContext.getUserTicket();
        con = Database.getDbConnection();
        stmt = con.createStatement();
        if (ticket.isMandatorSupervisor() || ticket.isGlobalSupervisor()) {
            sql = "SELECT ID FROM " + TBL_WORKFLOW_STEP + "  WHERE WORKFLOW=" + step.getWorkflowId()
                    + " AND ID!=" + fromStep;
        } else {
            sql = "SELECT DISTINCT TO_STEP FROM " + TBL_WORKFLOW_ROUTES + " WHERE FROM_STEP=" + fromStep
                    + " AND USERGROUP IN (" + StringUtils.join(ArrayUtils.toObject(ticket.getGroups()), ',')
                    + ")";
        }
        ResultSet rs = stmt.executeQuery(sql);
        ArrayList<Step> targets = new ArrayList<Step>(20);
        int stepId = -1;
        while (rs != null && rs.next()) {
            try {
                stepId = rs.getInt(1);
                targets.add(CacheAdmin.getEnvironment().getStep(stepId));
            } catch (Exception exc) {
                LOG.error("Failed to load step " + stepId + " (skipping it), err=" + exc.getMessage(), exc);
            }
        }
        return targets;
    } catch (SQLException exc) {
        throw new FxLoadException(LOG, "ex.step.load.target", exc, fromStep, exc.getMessage());
    } finally {
        Database.closeObjects(RouteEngineBean.class, con, stmt);
    }
}

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

public float[] getMinMax(int iCol) {
    List<Float> b = Arrays.asList(ArrayUtils.toObject(signals.get(iCol)));
    float[] minmax = new float[2];
    minmax[0] = Collections.min(b);
    minmax[1] = Collections.max(b);
    b = null;/* w  ww .  j av  a2  s.  c o m*/
    return minmax;
}

From source file:com.opengamma.analytics.financial.curve.building.CurveBuildingFunction.java

/**
 * Build a unit of curves./*  www .  j a  v a  2 s.  c  o m*/
 * @param instruments The instruments used for the unit calibration.
 * @param initGuess The initial parameters guess.
 * @param curveGenerators The map of curve names to curve generators used to build the unit.
 * @param knownData The known data (fx rates, other curves, model parameters, ...)
 * @param calculator The calculator of the value on which the calibration is done (usually ParSpreadMarketQuoteCalculator (recommended) or converted present value).
 * @param sensitivityCalculator The parameter sensitivity calculator.
 * @return The new curves and the calibrated parameters.
 */
public Pair<YieldCurveBundle, Double[]> makeUnit(InstrumentDerivative[] instruments, double[] initGuess,
        LinkedHashMap<String, GeneratorYDCurve> curveGenerators, YieldCurveBundle knownData,
        final AbstractInstrumentDerivativeVisitor<YieldCurveBundle, Double> calculator,
        final AbstractInstrumentDerivativeVisitor<YieldCurveBundle, InterestRateCurveSensitivity> sensitivityCalculator) {
    final MultipleYieldCurveFinderGeneratorDataBundle data = new MultipleYieldCurveFinderGeneratorDataBundle(
            instruments, knownData, curveGenerators);
    final Function1D<DoubleMatrix1D, DoubleMatrix1D> curveCalculator = new MultipleYieldCurveFinderGeneratorFunction(
            calculator, data);
    final Function1D<DoubleMatrix1D, DoubleMatrix2D> jacobianCalculator = new MultipleYieldCurveFinderGeneratorJacobian(
            new ParameterUnderlyingSensitivityCalculator(sensitivityCalculator), data);
    final double[] parameters = _rootFinder
            .getRoot(curveCalculator, jacobianCalculator, new DoubleMatrix1D(initGuess)).getData();
    final YieldCurveBundle newCurves = data.getBuildingFunction().evaluate(new DoubleMatrix1D(parameters));
    return new ObjectsPair<YieldCurveBundle, Double[]>(newCurves, ArrayUtils.toObject(parameters));
}

From source file:com.haulmont.cuba.web.app.ui.statistics.ThreadsDatasource.java

@Override
protected void loadData(Map<String, Object> params) {
    JmxInstance node = (JmxInstance) params.get("node");
    ManagedBeanInfo threadingBean = jmxControlAPI.getManagedBean(node, "java.lang:type=Threading");
    int nCPUs = (int) getAttributeValue(node, "java.lang:type=OperatingSystem", "AvailableProcessors");

    final long[] allThreadsIds = (long[]) getAttributeValue(node, "java.lang:type=Threading", "AllThreadIds");
    ManagedBeanOperation getThreadInfo = jmxControlAPI.getOperation(threadingBean, "getThreadInfo",
            new String[] { "[J" });
    CompositeData[] threadsInfo = (CompositeData[]) jmxControlAPI.invokeOperation(getThreadInfo,
            new Object[] { allThreadsIds });

    final long currentUptime = (long) getAttributeValue(node, "java.lang:type=Runtime", "Uptime");
    ManagedBeanOperation getThreadCpuTime = jmxControlAPI.getOperation(threadingBean, "getThreadCpuTime",
            new String[] { "[J" });
    long[] threadCpuTime = (long[]) jmxControlAPI.invokeOperation(getThreadCpuTime,
            new Object[] { allThreadsIds });
    if (prevUptime > 0L && currentUptime > prevUptime) {
        // elapsedTime is in ms
        long elapsedTime = currentUptime - prevUptime;
        for (int i = 0; i < allThreadsIds.length; i++) {
            // elapsedCpu is in ns
            Long threadId = allThreadsIds[i];
            Long prevCpuTimeLong = prevThread2CpuTime.get(threadId); //for new threads returns null.
            long prevCpuTime = prevCpuTimeLong != null ? prevCpuTimeLong : 0L;
            long elapsedCpu = threadCpuTime[i] - prevCpuTime;
            // cpuUsage could go higher than 100% because elapsedTime
            // and elapsedCpu are not fetched simultaneously. Limit to 99%.
            double cpuUsage = Math.min(99d, elapsedCpu / (elapsedTime * 1000000d /*convert to ns*/
                    / 100 /*percents*/ * nCPUs));
            getThreadSnapshot(threadId).setCpu(cpuUsage);
        }/*from  w  w w  .  j  ava  2  s. co  m*/
    }
    prevUptime = currentUptime;
    for (int i = 0; i < allThreadsIds.length; i++) {
        long time = threadCpuTime[i] != -1L ? threadCpuTime[i] : 0L;
        prevThread2CpuTime.put(allThreadsIds[i], time);
    }

    ManagedBeanOperation findDeadlockedThreads = jmxControlAPI.getOperation(threadingBean,
            "findDeadlockedThreads", null);
    Long[] deadlockedThreads = (Long[]) jmxControlAPI.invokeOperation(findDeadlockedThreads, null);
    Set<Long> deadLockedThreadsSet = new HashSet<>();
    if (deadlockedThreads != null) {
        CollectionUtils.addAll(deadLockedThreadsSet, deadlockedThreads);
    }
    Set<Long> allThreadsSet = new HashSet<>();
    CollectionUtils.addAll(allThreadsSet, ArrayUtils.toObject(allThreadsIds));

    //remove all terminated threads.
    Collection<ThreadSnapshot> toRemove = new LinkedList<>();
    for (ThreadSnapshot snapshot : getItems()) {
        if (!allThreadsSet.contains(snapshot.getThreadId())) {
            toRemove.add(snapshot);
        }
    }
    for (ThreadSnapshot snapshot : toRemove) {
        removeItem(snapshot);
    }

    //update visual data.
    for (int i = 0; i < threadsInfo.length; i++) {
        CompositeData info = threadsInfo[i];
        if (info != null) {
            Long threadId = (Long) info.get("threadId");
            ThreadSnapshot item = getThreadSnapshot(threadId);
            item.setName((String) info.get("threadName"));
            item.setStatus(info.get("threadState").toString());
            item.setDeadLocked(deadLockedThreadsSet.contains(threadId));
        } else {
            removeItem(getThreadSnapshot(allThreadsIds[i])); //no thread info available.
        }
    }

}

From source file:ch.epfl.data.squall.components.AbstractComponent.java

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

From source file:com.opengamma.analytics.financial.curve.interestrate.building.CurveBuildingFunction.java

/**
 * Build a unit of curves./*from   w ww. j  a v a2  s  . c  o m*/
 * @param instruments The instruments used for the unit calibration.
 * @param initGuess The initial parameters guess.
 * @param curveGenerators The map of curve names to curve generators used to build the unit.
 * @param knownData The known data (fx rates, other curves, model parameters, ...)
 * @param calculator The calculator of the value on which the calibration is done (usually ParSpreadMarketQuoteCalculator (recommended) or converted present value).
 * @param sensitivityCalculator The parameter sensitivity calculator.
 * @return The new curves and the calibrated parameters.
 */
public Pair<YieldCurveBundle, Double[]> makeUnit(final InstrumentDerivative[] instruments,
        final double[] initGuess, final LinkedHashMap<String, GeneratorYDCurve> curveGenerators,
        final YieldCurveBundle knownData,
        final InstrumentDerivativeVisitor<YieldCurveBundle, Double> calculator,
        final InstrumentDerivativeVisitor<YieldCurveBundle, InterestRateCurveSensitivity> sensitivityCalculator) {
    final MultipleYieldCurveFinderGeneratorDataBundle data = new MultipleYieldCurveFinderGeneratorDataBundle(
            instruments, knownData, curveGenerators);
    final Function1D<DoubleMatrix1D, DoubleMatrix1D> curveCalculator = new MultipleYieldCurveFinderGeneratorFunction(
            calculator, data);
    final Function1D<DoubleMatrix1D, DoubleMatrix2D> jacobianCalculator = new MultipleYieldCurveFinderGeneratorJacobian(
            new ParameterUnderlyingSensitivityCalculator(sensitivityCalculator), data);
    final double[] parameters = _rootFinder
            .getRoot(curveCalculator, jacobianCalculator, new DoubleMatrix1D(initGuess)).getData();
    final YieldCurveBundle newCurves = data.getBuildingFunction().evaluate(new DoubleMatrix1D(parameters));
    return new ObjectsPair<>(newCurves, ArrayUtils.toObject(parameters));
}

From source file:ch.epfl.data.squall.storm_components.InterchangingComponent.java

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

From source file:ch.epfl.data.squall.ewh.components.DummyComponent.java

@Override
public DummyComponent setOutputPartKey(int... hashIndexes) {
    _hashIndexes = Arrays.asList(ArrayUtils.toObject(hashIndexes));
    return this;
}