Example usage for org.apache.commons.lang3 ArrayUtils toPrimitive

List of usage examples for org.apache.commons.lang3 ArrayUtils toPrimitive

Introduction

In this page you can find the example usage for org.apache.commons.lang3 ArrayUtils toPrimitive.

Prototype

public static boolean[] toPrimitive(final Boolean[] array) 

Source Link

Document

Converts an array of object Booleans to primitives.

This method returns null for a null input array.

Usage

From source file:es.bsc.power_button_presser.powerbuttonstrategies.PatternRecognitionStrategy.java

@Override
public List<Host> getPowerButtonsToPress(ClusterState clusterState) {
    saveCurrentCpuDemand(clusterState);//from w w  w .  j ava 2 s . com
    int[] cpuDemandHistory = ArrayUtils.toPrimitive(historicalCpuDemand.getCpuDemandValues()
            .toArray(new Integer[historicalCpuDemand.getCpuDemandValues().size()]));
    if (cpuDemandHistory.length >= MINIMUM_HISTORICAL_CPU_DEMAND_POINTS) {
        return hostToBeTurnedOnOrOffAccordingToForecast(clusterState, getHoltWintersForecast(cpuDemandHistory));
    }
    return new ArrayList<>();
}

From source file:kieker.tools.opad.timeseries.forecast.mean.MeanForecasterJava.java

/**
 * @param numForecastSteps/*from   w  w  w  . j  av  a  2s  .com*/
 *            number of values the forecaster is going to forecast
 *
 * @return Forecast Result
 */
@Override
public IForecastResult forecast(final int numForecastSteps) {
    final ITimeSeries<Double> history = this.getTsOriginal();
    final ITimeSeries<Double> tsFC = this.prepareForecastTS();

    final List<Double> allHistory = new ArrayList<Double>(history.getValues());
    final Double[] histValuesNotNull = MeanForecasterJava.removeNullValues(allHistory);
    final double mean = StatUtils.mean(ArrayUtils.toPrimitive(histValuesNotNull));
    final Double[] forecastValues = new Double[numForecastSteps];
    Arrays.fill(forecastValues, mean);

    tsFC.appendAll(forecastValues);
    return new ForecastResult(tsFC, this.getTsOriginal(), ForecastMethod.MEAN);
}

From source file:com.strider.datadefender.requirement.Parameter.java

private Object getArrayForValues(final List<Object> list, final String type) throws ClassNotFoundException {
    String dataType = type;//from  w ww .  j  a v a 2  s  .c o  m

    if ("String".equals(dataType)) {
        dataType = "java.lang.String";
    }

    final Class<?> c = ClassUtils.getClass(dataType);

    if (c.isPrimitive()) {
        final Class<?> w = ClassUtils.primitiveToWrapper(c);
        Object array = Array.newInstance(w, list.size());

        array = list.toArray((Object[]) array);

        if (c == boolean.class) {
            return ArrayUtils.toPrimitive((Boolean[]) array);
        } else if (c == byte.class) {
            return ArrayUtils.toPrimitive((Byte[]) array);
        } else if (c == short.class) {
            return ArrayUtils.toPrimitive((Short[]) array);
        } else if (c == char.class) {
            return ArrayUtils.toPrimitive((Character[]) array);
        } else if (c == int.class) {
            return ArrayUtils.toPrimitive((Integer[]) array);
        } else if (c == long.class) {
            return ArrayUtils.toPrimitive((Long[]) array);
        } else if (c == float.class) {
            return ArrayUtils.toPrimitive((Float[]) array);
        } else if (c == double.class) {
            return ArrayUtils.toPrimitive((Double[]) array);
        }

        throw new IllegalArgumentException("Unhandled primitive type: " + c.getName());
    }

    final Object array = Array.newInstance(c, list.size());

    return list.toArray((Object[]) array);
}

From source file:de.thomasvolk.genexample.algorithmus.KonventionellAlgorithmus.java

@Override
public WagonBelegung berechneWagon(AlgorithmusBericht algorithmusBericht) {
    algorithmusBericht.start(getWagonBelegung());
    List<Integer> passagierReihenfolge = new ArrayList<>();
    Set<SitzplatzVergabe> vergebenePlaetze = new HashSet<>();
    for (Passagier p : getPassagierListe()) {
        SitzplatzVergabe besterPlatz = null;
        int index = 0;
        int ausgewaehlterPassagierIndex = 0;
        for (Sitzplatz sp : getSitzplatzListe()) {
            SitzplatzVergabe sitzplatzVergabe = new SitzplatzVergabe(sp, p);
            if (!vergebenePlaetze.contains(sitzplatzVergabe) && !passagierReihenfolge.contains(index)) {
                if (besterPlatz == null
                        || sitzplatzVergabe.getZufriedenheit() > besterPlatz.getZufriedenheit()) {
                    besterPlatz = sitzplatzVergabe;
                    ausgewaehlterPassagierIndex = index;
                }/*from  w  w w . j ava2 s.co m*/
            }
            index++;
        }
        vergebenePlaetze.add(besterPlatz);
        passagierReihenfolge.add(ausgewaehlterPassagierIndex);
    }
    WagonBelegung wagonBelegung = new WagonBelegung(getWagonBelegung().getWagon(), getPassagierListe(),
            ArrayUtils.toPrimitive(passagierReihenfolge.toArray(new Integer[getPassagierListe().length])));
    algorithmusBericht.ende(new Generation(0, Collections.singleton(wagonBelegung),
            wagonBelegung.getZufriedenheit(), wagonBelegung));
    return wagonBelegung;
}

From source file:com.medlog.webservice.vo.pairs.DiaryMoodToneXYPair.java

/**
 * Process data to points//from w  w w  . j  av  a 2 s .  c  om
 * @return 
 */
public boolean process() {
    try {
        Double[] xp = new Double[1];
        Double[] yp = new Double[1];
        getXl().toArray(xp);
        getYl().toArray(yp);
        setX(ArrayUtils.toPrimitive(xp));
        setY(ArrayUtils.toPrimitive(yp));
    } catch (Exception e) {
        return false;
    }
    return true;
}

From source file:de.hsheilbronn.mi.domain.NativeSvmModelWrapper.java

public NativeSvmModelWrapper(SvmConfigurationBuilder svmConfigurationBuilder, int probabilityEstimates,
        List<Double> rhoConstants, List<Integer> labelForEachClass, List<Double> probabilityA,
        List<Double> probabilityB, List<Integer> numberOfSVforEachClass, int numberOfClasses,
        int amountOfSupportVectors, Map<Integer, List<Double>> svCoefficients,
        Map<Integer, List<SvmFeature>> supportVectors) {

    svm_model nativeSvmModel = new svm_model();

    nativeSvmModel.l = (amountOfSupportVectors);
    nativeSvmModel.nr_class = (numberOfClasses);

    nativeSvmModel.rho = (ArrayUtils.toPrimitive(rhoConstants.toArray(new Double[rhoConstants.size()])));
    nativeSvmModel.probA = (ArrayUtils.toPrimitive(probabilityA.toArray(new Double[probabilityA.size()])));
    nativeSvmModel.probB = (ArrayUtils.toPrimitive(probabilityB.toArray(new Double[probabilityB.size()])));
    nativeSvmModel.label = ((ArrayUtils/*from  ww w .ja  v  a  2 s .co m*/
            .toPrimitive(labelForEachClass.toArray(new Integer[labelForEachClass.size()]))));
    nativeSvmModel.nSV = (ArrayUtils
            .toPrimitive(numberOfSVforEachClass.toArray(new Integer[numberOfSVforEachClass.size()])));

    if (svCoefficients != null) {
        nativeSvmModel.sv_coef = (PrimitiveHelper.doubleMapTo2dArray(svCoefficients));
    }

    if (supportVectors != null) {
        nativeSvmModel.SV = (PrimitiveHelper.svmFeatureMapTo2dArray(supportVectors));
    }

    nativeSvmModel.param = AbstractSvmTool
            .unwrap((svmConfigurationBuilder.setProbability(probabilityEstimates == 1 ? true : false).build()));

    this.svmModel = nativeSvmModel;
}

From source file:jat.examples.CRTBP.CRTBPPlot.java

void doExample() {
    double mu = 0.15;
    double[] y0 = { .11, 0, 0, 1.35, 1.33, 0 }; // initial state

    // double mu = 0.1;
    // double mu = 3.035909999e-6;

    // double mu = 0.012277471;
    // double[] y0 = { .1, 0, 0, 2.69, 2.69, 0 }; // initial state

    // double mu = 0.2;

    CRTBP myCRTBP = new CRTBP(mu);
    FirstOrderIntegrator dp853 = new DormandPrince853Integrator(1.0e-8, 100.0, 1.0e-10, 1.0e-10);
    dp853.addStepHandler(myCRTBP.stepHandler);

    FirstOrderDifferentialEquations ode = myCRTBP;

    double tf;//from  w  w w  .  j av a 2 s.  c  o m
    double[] y = new double[6]; // initial state

    // for (int i = 1; i < 2; i++) {
    // tf = i * 20.;
    tf = 40.;
    System.arraycopy(y0, 0, y, 0, 6);

    dp853.integrate(ode, 0.0, y, tf, y); // now y contains final state
    // at
    // time tf
    if (print) {
        System.out.printf("%9.6f %9.6f %9.6f %9.6f %9.6f", tf, y[0], y[1], y[2], myCRTBP.JacobiIntegral(y));
        System.out.println();
    }

    int arraySize = myCRTBP.time.size();
    double[] timeArray = ArrayUtils.toPrimitive(myCRTBP.time.toArray(new Double[arraySize]));
    double[] xsolArray = ArrayUtils.toPrimitive(myCRTBP.xsol.toArray(new Double[arraySize]));
    double[] ysolArray = ArrayUtils.toPrimitive(myCRTBP.ysol.toArray(new Double[arraySize]));
    double[][] XY = new double[timeArray.length][2];
    for (int i = 0; i < timeArray.length; i++) {
        XY[i][0] = xsolArray[i];
        XY[i][1] = ysolArray[i];
    }

    Plot2DPanel p = new Plot2DPanel();
    LinePlot l = new LinePlot("spacecraft", Color.RED, XY);
    l.closed_curve = false;
    l.draw_dot = true;
    p.addPlot(l);
    double plotSize = 1.2;
    myCRTBP.findLibrationPoints();
    Color darkGreen = new java.awt.Color(0, 190, 0);

    addPoint(p, "Earth", java.awt.Color.BLUE, -mu, 0);
    addPoint(p, "Moon", java.awt.Color.gray, 1 - mu, 0);
    addPoint(p, "L1", darkGreen, myCRTBP.LibPoints[0].getX(), 0);
    addPoint(p, "L2", darkGreen, myCRTBP.LibPoints[1].getX(), 0);
    addPoint(p, "L3", darkGreen, myCRTBP.LibPoints[2].getX(), 0);

    String Labelmu = "mu = " + myCRTBP.mu;
    p.addLabel(Labelmu, java.awt.Color.black, 1, .9 * plotSize);
    String initial = "initial x,v = (" + y0[0] + "," + y0[1] + "),(" + y0[3] + "," + y0[4] + ")";
    p.addLabel(initial, java.awt.Color.black, 1, .8 * plotSize);
    String Jacobi = "spacecraft C = " + myCRTBP.C;
    p.addLabel(Jacobi, java.awt.Color.black, 1, .7 * plotSize);
    String L1C = "L1 C = " + myCRTBP.C1;
    p.addLabel(L1C, java.awt.Color.black, 1, .6 * plotSize);

    myCRTBP.findZeroVelocity();
    int size = myCRTBP.xzv.size();
    double[] xzvArray = ArrayUtils.toPrimitive(myCRTBP.xzv.toArray(new Double[size]));
    double[] yzvArray = ArrayUtils.toPrimitive(myCRTBP.yzv.toArray(new Double[size]));
    double[][] XYzv = new double[size][2];
    for (int i = 0; i < size; i++) {
        XYzv[i][0] = xzvArray[i];
        XYzv[i][1] = yzvArray[i];
    }
    LinePlot lzv = new LinePlot("zero vel", Color.blue, XYzv);
    lzv.closed_curve = false;
    lzv.draw_dot = true;
    p.addPlot(lzv);

    p.setLegendOrientation(PlotPanel.SOUTH);
    p.setFixedBounds(0, -plotSize, plotSize);
    p.setFixedBounds(1, -plotSize, plotSize);
    new FrameView(p).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

From source file:jcalccalculator.TaskClient.java

public boolean cmdOperation(Request rq) throws ComputeEngineException {
    Response rs = new Response();

    Operation op = (Operation) rq.getData().get(0);
    if (op.getType().compareTo("x+y") == 0) {
        Float[] numeros = new Float[op.getInputData().size()];
        for (int i = 0; i < numeros.length; i++) {
            numeros[i] = (Float) op.getInputData().get(i).value;
        }//from w  ww .  j av a2s. c  o m
        float[] datos = ArrayUtils.toPrimitive(numeros);
        Double res = new Double(fengine.sumar(datos));
        op.setResult(res);

        rs.setSubtype("_JCALC_OPERATION_OK_");
        rs.addData(op);
        return ccp.sendResponse(rs);
    } else if (op.getType().compareTo("x-y") == 0) {

        Float[] numeros = new Float[op.getInputData().size()];
        for (int i = 0; i < numeros.length; i++) {
            numeros[i] = (Float) op.getInputData().get(i).value;
        }
        float[] datos = ArrayUtils.toPrimitive(numeros);
        Double res = new Double(fengine.restar(datos));
        op.setResult(res);

        rs.setSubtype("_JCALC_OPERATION_OK_");
        rs.addData(op);
        return ccp.sendResponse(rs);
    }

    else if (op.getType().compareTo("media") == 0) {
        Float[] numeros = (Float[]) op.getInputData().get(0).value;

        float[] datos = ArrayUtils.toPrimitive(numeros);
        Double res = new Double(fengine.media(datos));
        op.setResult(res);

        rs.setSubtype("_JCALC_OPERATION_OK_");
        rs.addData(op);
        return ccp.sendResponse(rs);
    } else if (op.getType().compareTo("varianza") == 0) {
        Float[] numeros = (Float[]) op.getInputData().get(0).value;

        float[] datos = ArrayUtils.toPrimitive(numeros);
        Double res = new Double(fengine.varianza(datos));
        op.setResult(res);

        rs.setSubtype("_JCALC_OPERATION_OK_");
        rs.addData(op);
        return ccp.sendResponse(rs);
    } else if (op.getType().compareTo("desviacion") == 0) {
        Float[] numeros = (Float[]) op.getInputData().get(0).value;

        float[] datos = ArrayUtils.toPrimitive(numeros);
        Double res = null;
        try {
            res = new Double(fengine.desviacion(datos));
        } catch (ComputeEngineException ex) {
            Logger.getLogger(TaskClient.class.getName()).log(Level.SEVERE, null, ex);
        }
        op.setResult(res);

        rs.setSubtype("_JCALC_OPERATION_OK_");
        rs.addData(op);
        return ccp.sendResponse(rs);
    } else if (op.getType().compareTo("moda") == 0) {
        Float[] numeros = (Float[]) op.getInputData().get(0).value;

        float[] datos = ArrayUtils.toPrimitive(numeros);
        Double res = null;
        res = new Double(fengine.moda(datos));
        op.setResult(res);

        rs.setSubtype("_JCALC_OPERATION_OK_");
        rs.addData(op);
        return ccp.sendResponse(rs);
    } else if (op.getType().compareTo("mediana") == 0) {
        Float[] numeros = (Float[]) op.getInputData().get(0).value;

        float[] datos = ArrayUtils.toPrimitive(numeros);
        Double res = null;
        res = new Double(fengine.mediana(datos));
        op.setResult(res);

        rs.setSubtype("_JCALC_OPERATION_OK_");
        rs.addData(op);
        return ccp.sendResponse(rs);
    } else if (op.getType().compareTo("mediaGeometrica") == 0) {
        Float[] numeros = (Float[]) op.getInputData().get(0).value;

        float[] datos = ArrayUtils.toPrimitive(numeros);
        try {
            Double res = fengine.mediaGeometrica(datos);
            op.setResult(res);
            rs.setSubtype("_JCALC_OPERATION_OK_");
        } catch (ComputeEngineException ex) {
            protocol.common.Error err = new protocol.common.Error();
            err.type = ex.getMessage();
            err.msg = "Raz cuadrada negativa";
            op.setResult(err);
            rs.setSubtype("_JCALC_OPERATION_ERROR_");
        }

        rs.addData(op);
        return ccp.sendResponse(rs);
    } else if (op.getType().compareTo("aproximacionE") == 0) {
        Float n = (Float) op.getInputData().get(0).value;
        double rss = fengine.aproximacionE(n.floatValue());
        Double res = new Double(rss);
        // Double res = new Double(fengine.x2(n.floatValue()));
        op.setResult(res);
        rs.setSubtype("_JCALC_OPERATION_OK_");
        rs.addData(op);
        return ccp.sendResponse(rs);
    }

    else if (op.getType().compareTo("x*y") == 0) {

        Float[] numeros = new Float[op.getInputData().size()];
        for (int i = 0; i < numeros.length; i++) {
            numeros[i] = (Float) op.getInputData().get(i).value;
        }
        float[] datos = ArrayUtils.toPrimitive(numeros);
        Double res = new Double(fengine.multiplicar(datos));
        op.setResult(res);

        rs.setSubtype("_JCALC_OPERATION_OK_");
        rs.addData(op);
        return ccp.sendResponse(rs);
    }

    else if (op.getType().compareTo("x/y") == 0) {
        Float[] numeros = new Float[op.getInputData().size()];
        for (int i = 0; i < numeros.length; i++) {
            numeros[i] = (Float) op.getInputData().get(i).value;
        }
        float[] datos = ArrayUtils.toPrimitive(numeros);
        try {
            Double res = new Double(fengine.dividir(datos));
            op.setResult(res);

            rs.setSubtype("_JCALC_OPERATION_OK_");
            rs.addData(op);
        } catch (ComputeEngineException ex) {
            protocol.common.Error err = new protocol.common.Error();
            err.type = ex.getMessage();
            err.msg = "Divisor 0";
            op.setResult(err);
            rs.setSubtype("_JCALC_OPERATION_ERROR_");
        }
        rs.addData(op);
        return ccp.sendResponse(rs);
    } else if (op.getType().compareTo("x2") == 0) {

        Float n = (Float) op.getInputData().get(0).value;
        double rss = fengine.x2(n.floatValue());
        Double res = new Double(rss);
        // Double res = new Double(fengine.x2(n.floatValue()));
        op.setResult(res);
        rs.setSubtype("_JCALC_OPERATION_OK_");
        rs.addData(op);
        return ccp.sendResponse(rs);
    } else if (op.getType().compareTo("cambioSigno") == 0) {

        Float n = (Float) op.getInputData().get(0).value;
        double rss = fengine.cambioSigno(n.floatValue());
        Double res = new Double(rss);
        // Double res = new Double(fengine.x2(n.floatValue()));
        op.setResult(res);
        rs.setSubtype("_JCALC_OPERATION_OK_");
        rs.addData(op);
        return ccp.sendResponse(rs);
    }

    else if (op.getType().compareTo("raiz2") == 0) {

        Float n = (Float) op.getInputData().get(0).value;
        double rss = 0;
        try {
            rss = fengine.raiz2(n.floatValue());
            Double res = new Double(rss);
            op.setResult(res);
            rs.setSubtype("_JCALC_OPERATION_OK_");
        } catch (ComputeEngineException ex) {
            protocol.common.Error err = new protocol.common.Error();
            err.type = ex.getMessage();
            err.msg = "Raz cuadrada negativa";
            op.setResult(err);
            rs.setSubtype("_JCALC_OPERATION_ERROR_");
        }

        rs.addData(op);
        return ccp.sendResponse(rs);
    } else if (op.getType().compareTo("segundoGrado") == 0) {
        Float[] numeros = new Float[op.getInputData().size()];
        for (int i = 0; i < numeros.length; i++) {
            numeros[i] = (Float) op.getInputData().get(i).value;
        }
        float[] datos = ArrayUtils.toPrimitive(numeros);
        float[] resta = new float[2];
        float[] suma = new float[2];
        resta[0] = datos[0];
        resta[1] = datos[2];
        suma[0] = datos[1];
        suma[1] = datos[2];
        try {
            Double[] res = new Double[2];
            res[0] = new Double(fengine.dividir(suma));
            res[1] = new Double(fengine.dividir(resta));
            op.setResult(res);

            rs.setSubtype("_JCALC_OPERATION_OK_");
            rs.addData(op);
        } catch (ComputeEngineException ex) {
            if (ex.getMessage() == "DIVIDE_BY_ZERO") {
                protocol.common.Error err = new protocol.common.Error();
                err.type = ex.getMessage();
                err.msg = "Divisor 0";
                op.setResult(err);
                rs.setSubtype("_JCALC_OPERATION_ERROR_");
            }
            if (ex.getMessage() == "SQUAREROOT_NEGATIVE") {
                protocol.common.Error err = new protocol.common.Error();
                err.type = ex.getMessage();
                err.msg = "Raz cuadrada negativa";
                op.setResult(err);
                rs.setSubtype("_JCALC_OPERATION_ERROR_");
            }
            rs.addData(op);
            return ccp.sendResponse(rs);
        }
        return ccp.sendResponse(rs);
    }

    return true;
}

From source file:ijfx.ui.utils.ChartUpdater.java

public void updateChart() {

    final double min; // minimum value
    final double max; // maximum value
    double range; // max - min
    final double binSize;
    // int maximumBinNumber = 30;
    int finalBinNumber;

    int differentValuesCount = possibleValues.stream().filter(n -> Double.isFinite(n.doubleValue()))
            .collect(Collectors.toSet()).size();
    if (differentValuesCount < maximumBinNumber) {
        finalBinNumber = differentValuesCount;
    } else {//ww w . ja  v  a 2 s.c o m
        finalBinNumber = maximumBinNumber;
    }

    EmpiricalDistribution distribution = new EmpiricalDistribution(finalBinNumber);

    Double[] values = possibleValues.parallelStream().filter(n -> Double.isFinite(n.doubleValue()))
            .map(v -> v.doubleValue()).sorted()
            //.toArray();
            .toArray(size -> new Double[size]);
    distribution.load(ArrayUtils.toPrimitive(values));

    min = values[0];
    max = values[values.length - 1];
    range = max - min;
    binSize = range / (finalBinNumber - 1);

    //System.out.println(String.format("min = %.0f, max = %.0f, range = %.0f, bin size = %.0f, bin number = %d", min, max, range, binSize, finalBinNumber));

    XYChart.Series<Double, Double> serie = new XYChart.Series<>();
    ArrayList<XYChart.Data<Double, Double>> data = new ArrayList<>();
    double k = min;
    for (SummaryStatistics st : distribution.getBinStats()) {
        data.add(new XYChart.Data<>(k, new Double(st.getN())));
        k += binSize;
    }

    Platform.runLater(() -> {
        serie.getData().addAll(data);
        areaChart.getData().clear();
        areaChart.getData().add(serie);
    });

}

From source file:ml.dmlc.xgboost4j.java.example.util.DataLoader.java

public static CSRSparseData loadSVMFile(String filePath) throws IOException {
    CSRSparseData spData = new CSRSparseData();

    List<Float> tlabels = new ArrayList<>();
    List<Float> tdata = new ArrayList<>();
    List<Long> theaders = new ArrayList<>();
    List<Integer> tindex = new ArrayList<>();

    File f = new File(filePath);
    FileInputStream in = new FileInputStream(f);
    BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));

    String line;/*ww w. j  a v a 2s.c  o  m*/
    long rowheader = 0;
    theaders.add(rowheader);
    while ((line = reader.readLine()) != null) {
        String[] items = line.trim().split(" ");
        if (items.length == 0) {
            continue;
        }

        rowheader += items.length - 1;
        theaders.add(rowheader);
        tlabels.add(Float.valueOf(items[0]));

        for (int i = 1; i < items.length; i++) {
            String[] tup = items[i].split(":");
            assert tup.length == 2;

            tdata.add(Float.valueOf(tup[1]));
            tindex.add(Integer.valueOf(tup[0]));
        }
    }

    spData.labels = ArrayUtils.toPrimitive(tlabels.toArray(new Float[tlabels.size()]));
    spData.data = ArrayUtils.toPrimitive(tdata.toArray(new Float[tdata.size()]));
    spData.colIndex = ArrayUtils.toPrimitive(tindex.toArray(new Integer[tindex.size()]));
    spData.rowHeaders = ArrayUtils.toPrimitive(theaders.toArray(new Long[theaders.size()]));

    return spData;
}