List of usage examples for org.apache.commons.lang ArrayUtils toPrimitive
public static boolean[] toPrimitive(Boolean[] array)
Converts an array of object Booleans to primitives.
From source file:com.opengamma.util.timeseries.fast.integer.object.AbstractFastIntObjectTimeSeries.java
@Override public ObjectTimeSeries<Integer, T> newInstance(final Integer[] times, final T[] values) { return newInstanceFast(ArrayUtils.toPrimitive(times), values); }
From source file:com.opengamma.analytics.financial.curve.sensitivity.ParameterUnderlyingSensitivityCalculator.java
/** * Computes the sensitivity with respect to the parameters from the point sensitivities to the continuously compounded rate. * The sensitivity computed is only to the curves not in the fixedCurves set. When a curve depend on another underlying curve and the underlying curve is a fixed curve, * its sensitivity is not reported.//ww w .j a va2s . c o m * @param sensitivity The point sensitivity. * @param fixedCurves The fixed curves names (for which the parameter sensitivity are not computed even if they are necessary for the instrument pricing). * The curve in the list may or may not be in the bundle. Not null. * @param bundle The curve bundle with all the curves with respect to which the sensitivity should be computed. Not null. * @return The sensitivity (as a DoubleMatrix1D). */ @Override public DoubleMatrix1D pointToParameterSensitivity(final InterestRateCurveSensitivity sensitivity, final Set<String> fixedCurves, final YieldCurveBundle bundle) { Set<String> curveNamesSet = bundle.getAllNames(); int nbCurve = curveNamesSet.size(); String[] curveNamesArray = new String[nbCurve]; int loopname = 0; LinkedHashMap<String, Integer> curveNum = new LinkedHashMap<String, Integer>(); for (final String name : curveNamesSet) { // loop over all curves (by name) curveNamesArray[loopname] = name; curveNum.put(name, loopname++); } int[] nbNewParameters = new int[nbCurve]; // Implementation note: nbNewParameters - number of new parameters in the curve, parameters not from an underlying curve which is another curve of the bundle. int[][] indexOther = new int[nbCurve][]; // Implementation note: indexOther - the index of the underlying curves, if any. loopname = 0; for (final String name : curveNamesSet) { // loop over all curves (by name) final YieldAndDiscountCurve curve = bundle.getCurve(name); List<String> underlyingCurveNames = curve.getUnderlyingCurvesNames(); nbNewParameters[loopname] = curve.getNumberOfParameters(); List<Integer> indexOtherList = new ArrayList<Integer>(); for (String u : underlyingCurveNames) { Integer i = curveNum.get(u); if (i != null) { indexOtherList.add(i); nbNewParameters[loopname] -= nbNewParameters[i]; } } indexOther[loopname] = ArrayUtils.toPrimitive(indexOtherList.toArray(new Integer[0])); loopname++; } int nbSensiCurve = 0; for (final String name : bundle.getAllNames()) { // loop over all curves (by name) if (!fixedCurves.contains(name)) { nbSensiCurve++; } } int[] nbNewParamSensiCurve = new int[nbSensiCurve]; // Implementation note: nbNewParamSensiCurve int[][] indexOtherSensiCurve = new int[nbSensiCurve][]; // Implementation note: indexOtherSensiCurve - int[] startCleanParameter = new int[nbSensiCurve]; // Implementation note: startCleanParameter - for each curve for which the sensitivity should be computed, the index in the total sensitivity vector at which that curve start. int[][] startDirtyParameter = new int[nbSensiCurve][]; // Implementation note: startDirtyParameter - for each curve for which the sensitivity should be computed, the indexes of the underlying curves. int nbSensitivityCurve = 0; int nbCleanParameters = 0; int currentDirtyStart = 0; for (final String name : curveNamesSet) { // loop over all curves (by name) if (!fixedCurves.contains(name)) { int num = curveNum.get(name); final YieldAndDiscountCurve curve = bundle.getCurve(name); List<Integer> startDirtyParameterList = new ArrayList<Integer>(); List<String> underlyingCurveNames = curve.getUnderlyingCurvesNames(); for (String u : underlyingCurveNames) { Integer i = curveNum.get(u); if (i != null) { startDirtyParameterList.add(currentDirtyStart); currentDirtyStart += nbNewParameters[i]; } } startDirtyParameterList.add(currentDirtyStart); currentDirtyStart += nbNewParameters[nbSensitivityCurve]; startDirtyParameter[nbSensitivityCurve] = ArrayUtils .toPrimitive(startDirtyParameterList.toArray(new Integer[0])); nbNewParamSensiCurve[nbSensitivityCurve] = nbNewParameters[num]; indexOtherSensiCurve[nbSensitivityCurve] = indexOther[num]; startCleanParameter[nbSensitivityCurve] = nbCleanParameters; nbCleanParameters += nbNewParamSensiCurve[nbSensitivityCurve]; nbSensitivityCurve++; } } final List<Double> sensiDirtyList = new ArrayList<Double>(); for (final String name : curveNamesSet) { // loop over all curves (by name) if (!fixedCurves.contains(name)) { final YieldAndDiscountCurve curve = bundle.getCurve(name); List<Double> oneCurveSensitivity = pointToParameterSensitivity( sensitivity.getSensitivities().get(name), curve); sensiDirtyList.addAll(oneCurveSensitivity); } } double[] sensiDirty = ArrayUtils.toPrimitive(sensiDirtyList.toArray(new Double[0])); double[] sensiClean = new double[nbCleanParameters]; for (int loopcurve = 0; loopcurve < nbSensiCurve; loopcurve++) { for (int loopo = 0; loopo < indexOtherSensiCurve[loopcurve].length; loopo++) { if (!fixedCurves.contains(curveNamesArray[indexOtherSensiCurve[loopcurve][loopo]])) { for (int loops = 0; loops < nbNewParamSensiCurve[indexOtherSensiCurve[loopcurve][loopo]]; loops++) { sensiClean[startCleanParameter[indexOtherSensiCurve[loopcurve][loopo]] + loops] += sensiDirty[startDirtyParameter[loopcurve][loopo] + loops]; } } } for (int loops = 0; loops < nbNewParamSensiCurve[loopcurve]; loops++) { sensiClean[startCleanParameter[loopcurve] + loops] += sensiDirty[startDirtyParameter[loopcurve][indexOtherSensiCurve[loopcurve].length] + loops]; } } return new DoubleMatrix1D(sensiClean); }
From source file:com.opengamma.util.timeseries.fast.integer.AbstractFastIntDoubleTimeSeries.java
@Override public DoubleTimeSeries<Integer> newInstance(final Integer[] times, final Double[] values) { return newInstanceFast(ArrayUtils.toPrimitive(times), ArrayUtils.toPrimitive(values)); }
From source file:com.microrisc.hdlcframing.v2.HDLC_DataTransformer.java
public static short[] getDataFromFrame(short[] uartDataFrame) throws HDLC_FormatException { checkUartDataFrame(uartDataFrame);// w ww . ja va 2 s . c o m List<Short> dataList = new LinkedList<>(); if (uartDataFrame[0] != FLAG_SEQUENCE) { throw new HDLC_FormatException("First byte must be 0x7e"); } if (uartDataFrame[uartDataFrame.length - 1] != FLAG_SEQUENCE) { throw new HDLC_FormatException("Last byte must be 0x7e"); } boolean escapedByte = false; short countedCRC = 0xFF; // getting starting position of a checksum int crcStartPos = uartDataFrame.length - 2; if (uartDataFrame[uartDataFrame.length - 3] == CONTROL_ESCAPE) { crcStartPos = uartDataFrame.length - 3; } for (int dataId = 1; dataId < crcStartPos; dataId++) { short dataItem = uartDataFrame[dataId]; if (dataItem == CONTROL_ESCAPE) { escapedByte = true; continue; } // previous byte was CONTROL ESCAPE if (escapedByte) { if ((dataItem & ESCAPE_BIT) == 0) { dataItem |= ESCAPE_BIT; } else { dataItem ^= ESCAPE_BIT; } escapedByte = false; } countedCRC = updateCRC(countedCRC, dataItem); dataList.add(dataItem); } short packetCRC = uartDataFrame[uartDataFrame.length - 2]; if (uartDataFrame[uartDataFrame.length - 3] == CONTROL_ESCAPE) { packetCRC = uartDataFrame[uartDataFrame.length - 2]; if ((packetCRC & ESCAPE_BIT) == 0) { packetCRC |= ESCAPE_BIT; } else { packetCRC ^= ESCAPE_BIT; } } if (countedCRC != packetCRC) { throw new HDLC_FormatException("CRC mismatch. " + "Counted: " + countedCRC + " Get: " + packetCRC); } Short[] data = dataList.toArray(new Short[] {}); return ArrayUtils.toPrimitive(data); }
From source file:com.opengamma.analytics.financial.curve.ParameterUnderlyingSensitivityCalculator.java
/** * Computes the sensitivity with respect to the parameters from the point sensitivities to the continuously compounded rate. * @param sensitivity The point sensitivity. * @param fixedCurves The fixed curves names (for which the parameter sensitivity are not computed even if they are necessary for the instrument pricing). * The curve in the list may or may not be in the bundle. Not null. * @param bundle The curve bundle with all the curves with respect to which the sensitivity should be computed. Not null. * @return The sensitivity (as a DoubleMatrix1D). *///www . j a v a 2s.c o m @Override public DoubleMatrix1D pointToParameterSensitivity(final InterestRateCurveSensitivity sensitivity, final Set<String> fixedCurves, final YieldCurveBundle bundle) { Integer nbCurve = 0; LinkedHashMap<String, Integer> curveNum = new LinkedHashMap<String, Integer>(); for (final String name : bundle.getAllNames()) { // loop over all curves (by name) if (!fixedCurves.contains(name)) { curveNum.put(name, nbCurve++); } } nbCurve = 0; int[] nbNewParameters = new int[curveNum.size()]; // Implementation note: int[] startCleanParameter = new int[curveNum.size()]; // Implementation note: int[][] startDirtyParameter = new int[curveNum.size()][]; int[][] indexOther = new int[curveNum.size()][]; // Implementation note: the start of the different blocs of parameters. First the other curves, then the new part. int nbCleanParameters = 0; int currentDirtyStart = 0; for (final String name : bundle.getAllNames()) { // loop over all curves (by name) if (!fixedCurves.contains(name)) { final YieldAndDiscountCurve curve = bundle.getCurve(name); List<String> underlyingCurveNames = curve.getUnderlyingCurvesNames(); startCleanParameter[nbCurve] = nbCleanParameters; nbNewParameters[nbCurve] = curve.getNumberOfParameters(); List<Integer> indexOtherList = new ArrayList<Integer>(); List<Integer> startDirtyParameterList = new ArrayList<Integer>(); for (String u : underlyingCurveNames) { Integer i = curveNum.get(u); if (i != null) { indexOtherList.add(i); nbNewParameters[nbCurve] -= nbNewParameters[i]; startDirtyParameterList.add(currentDirtyStart); currentDirtyStart += nbNewParameters[i]; } } startDirtyParameterList.add(currentDirtyStart); currentDirtyStart += nbNewParameters[nbCurve]; indexOther[nbCurve] = ArrayUtils.toPrimitive(indexOtherList.toArray(new Integer[0])); startDirtyParameter[nbCurve] = ArrayUtils .toPrimitive(startDirtyParameterList.toArray(new Integer[0])); nbCleanParameters += nbNewParameters[nbCurve]; nbCurve++; } } final List<Double> sensiDirtyList = new ArrayList<Double>(); for (final String name : bundle.getAllNames()) { // loop over all curves (by name) if (!fixedCurves.contains(name)) { final YieldAndDiscountCurve curve = bundle.getCurve(name); List<Double> oneCurveSensitivity = pointToParameterSensitivity( sensitivity.getSensitivities().get(name), curve); sensiDirtyList.addAll(oneCurveSensitivity); } } double[] sensiDirty = ArrayUtils.toPrimitive(sensiDirtyList.toArray(new Double[0])); double[] sensiClean = new double[nbCleanParameters]; for (int loopcurve = 0; loopcurve < nbCurve; loopcurve++) { for (int loopo = 0; loopo < indexOther[loopcurve].length; loopo++) { for (int loops = 0; loops < nbNewParameters[indexOther[loopcurve][loopo]]; loops++) { sensiClean[startCleanParameter[indexOther[loopcurve][loopo]] + loops] += sensiDirty[startDirtyParameter[loopcurve][loopo] + loops]; } } for (int loops = 0; loops < nbNewParameters[loopcurve]; loops++) { sensiClean[startCleanParameter[loopcurve] + loops] += sensiDirty[startDirtyParameter[loopcurve][indexOther[loopcurve].length] + loops]; } } return new DoubleMatrix1D(sensiClean); }
From source file:com.opengamma.analytics.financial.curve.sensitivity.ParameterUnderlyingSensitivityBlockCalculator.java
public ParameterSensitivity pointToParameterSensitivity(final Currency ccy, final InterestRateCurveSensitivity sensitivity, final Set<String> fixedCurves, final YieldCurveBundle bundle) { Set<String> curveNamesSet = bundle.getAllNames(); int nbCurve = curveNamesSet.size(); String[] curveNamesArray = new String[nbCurve]; int loopname = 0; LinkedHashMap<String, Integer> curveNum = new LinkedHashMap<String, Integer>(); for (final String name : curveNamesSet) { // loop over all curves (by name) curveNamesArray[loopname] = name; curveNum.put(name, loopname++);//from www . ja v a 2s . c o m } int[] nbNewParameters = new int[nbCurve]; // Implementation note: nbNewParameters - number of new parameters in the curve, parameters not from an underlying curve which is another curve of the bundle. int[][] indexOther = new int[nbCurve][]; // Implementation note: indexOther - the index of the underlying curves, if any. loopname = 0; for (final String name : curveNamesSet) { // loop over all curves (by name) final YieldAndDiscountCurve curve = bundle.getCurve(name); List<String> underlyingCurveNames = curve.getUnderlyingCurvesNames(); nbNewParameters[loopname] = curve.getNumberOfParameters(); List<Integer> indexOtherList = new ArrayList<Integer>(); for (String u : underlyingCurveNames) { Integer i = curveNum.get(u); if (i != null) { indexOtherList.add(i); nbNewParameters[loopname] -= nbNewParameters[i]; } } indexOther[loopname] = ArrayUtils.toPrimitive(indexOtherList.toArray(new Integer[0])); loopname++; } loopname = 0; for (final String name : bundle.getAllNames()) { // loop over all curves (by name) if (!fixedCurves.contains(name)) { loopname++; } } int nbSensitivityCurve = loopname; int[] nbNewParamSensiCurve = new int[nbSensitivityCurve]; // Implementation note: nbNewParamSensiCurve int[][] indexOtherSensiCurve = new int[nbSensitivityCurve][]; // Implementation note: indexOtherSensiCurve - // int[] startCleanParameter = new int[nbSensitivityCurve]; // Implementation note: startCleanParameter - for each curve for which the sensitivity should be computed, the index in the total sensitivity vector at which that curve start. int[][] startDirtyParameter = new int[nbSensitivityCurve][]; // Implementation note: startDirtyParameter - for each curve for which the sensitivity should be computed, the indexes of the underlying curves. int nbCleanParameters = 0; int currentDirtyStart = 0; loopname = 0; for (final String name : curveNamesSet) { // loop over all curves (by name) if (!fixedCurves.contains(name)) { int num = curveNum.get(name); final YieldAndDiscountCurve curve = bundle.getCurve(name); List<Integer> startDirtyParameterList = new ArrayList<Integer>(); List<String> underlyingCurveNames = curve.getUnderlyingCurvesNames(); for (String u : underlyingCurveNames) { Integer i = curveNum.get(u); if (i != null) { startDirtyParameterList.add(currentDirtyStart); currentDirtyStart += nbNewParameters[i]; } } startDirtyParameterList.add(currentDirtyStart); currentDirtyStart += nbNewParameters[loopname]; startDirtyParameter[loopname] = ArrayUtils .toPrimitive(startDirtyParameterList.toArray(new Integer[0])); nbNewParamSensiCurve[loopname] = nbNewParameters[num]; indexOtherSensiCurve[loopname] = indexOther[num]; // startCleanParameter[loopname] = nbCleanParameters; nbCleanParameters += nbNewParamSensiCurve[loopname]; loopname++; } } final List<Double> sensiDirtyList = new ArrayList<Double>(); for (final String name : curveNamesSet) { // loop over all curves (by name) if (!fixedCurves.contains(name)) { final YieldAndDiscountCurve curve = bundle.getCurve(name); Double[] oneCurveSensitivity = pointToParameterSensitivity(sensitivity.getSensitivities().get(name), curve); sensiDirtyList.addAll(Arrays.asList(oneCurveSensitivity)); } } double[] sensiDirty = ArrayUtils.toPrimitive(sensiDirtyList.toArray(new Double[0])); double[][] sensiClean = new double[nbSensitivityCurve][]; for (int loopcurve = 0; loopcurve < nbSensitivityCurve; loopcurve++) { sensiClean[loopcurve] = new double[nbNewParamSensiCurve[loopcurve]]; } for (int loopcurve = 0; loopcurve < nbSensitivityCurve; loopcurve++) { for (int loopo = 0; loopo < indexOtherSensiCurve[loopcurve].length; loopo++) { if (!fixedCurves.contains(curveNamesArray[indexOtherSensiCurve[loopcurve][loopo]])) { for (int loops = 0; loops < nbNewParamSensiCurve[indexOtherSensiCurve[loopcurve][loopo]]; loops++) { sensiClean[indexOtherSensiCurve[loopcurve][loopo]][loops] += sensiDirty[startDirtyParameter[loopcurve][loopo] + loops]; } } } for (int loops = 0; loops < nbNewParamSensiCurve[loopcurve]; loops++) { sensiClean[loopcurve][loops] += sensiDirty[startDirtyParameter[loopcurve][indexOtherSensiCurve[loopcurve].length] + loops]; } } final LinkedHashMap<Pair<String, Currency>, DoubleMatrix1D> result = new LinkedHashMap<Pair<String, Currency>, DoubleMatrix1D>(); for (int loopcurve = 0; loopcurve < nbSensitivityCurve; loopcurve++) { result.put(new ObjectsPair<String, Currency>(curveNamesArray[loopcurve], ccy), new DoubleMatrix1D(sensiClean[loopcurve])); } return new ParameterSensitivity(result); }
From source file:com.compomics.cell_coord.gui.controller.computation.ComputationDataController.java
/** * * @param track// w w w .ja v a 2s. c o m */ private void plotCoordinatesTime(Track track) { Double[][] coordinates = track.getCoordinates(); Double[][] transpose2DArray = ComputationUtils.transpose2DArray(coordinates); double[] timeIndexes = track.getTimeIndexes(); double[] xCoordinates = ArrayUtils.toPrimitive(ComputationUtils.excludeNullValues(transpose2DArray[0])); XYSeries xtSeries = JFreeChartUtils.generateXYSeries(timeIndexes, xCoordinates); XYSeriesCollection xtSeriesCollection = new XYSeriesCollection(xtSeries); XYItemRenderer renderer = new StandardXYItemRenderer(); NumberAxis xAxis = new NumberAxis("x"); XYPlot xTPlot = new XYPlot(xtSeriesCollection, null, xAxis, renderer); NumberAxis yAxis = new NumberAxis("y"); double[] yCoordinates = ArrayUtils.toPrimitive(ComputationUtils.excludeNullValues(transpose2DArray[1])); XYSeries ytSeries = JFreeChartUtils.generateXYSeries(timeIndexes, yCoordinates); XYSeriesCollection ytSeriesCollection = new XYSeriesCollection(ytSeries); XYPlot yTPlot = new XYPlot(ytSeriesCollection, null, yAxis, renderer); // domain axis NumberAxis domainAxis = new NumberAxis("time index"); CombinedDomainXYPlot combinedDomainXYPlot = new CombinedDomainXYPlot(domainAxis); combinedDomainXYPlot.setRenderer(new XYLineAndShapeRenderer()); combinedDomainXYPlot.add(xTPlot); combinedDomainXYPlot.add(yTPlot); combinedDomainXYPlot.setOrientation(PlotOrientation.VERTICAL); JFreeChart combinedChart = new JFreeChart("temp. evolution", combinedDomainXYPlot); ChartPanel chartPanel = new ChartPanel(combinedChart); computationDataPanel.getxYParentPanel().removeAll(); computationDataPanel.getxYParentPanel().add(chartPanel, gridBagConstraints); computationDataPanel.getxYParentPanel().revalidate(); computationDataPanel.getxYParentPanel().repaint(); }
From source file:com.opengamma.financial.analytics.model.volatility.surface.black.EquityBlackVolatilitySurfaceFunction.java
@Override /**/* w ww . j a va2 s. c om*/ * Builds a StandardSmileSurfaceDataBundle * <p> * Note that the Volatility requirement is of type STANDARD_VOLATILITY_SURFACE_DATA. This means that it is tiled, and must be brought down to its unique expiry/strike values * This is done because the existing of existing Function chain. * RawEquityOptionVolatilitySurfaceFunction produces a VOLATILITY_SURFACE_DATA, but the expiries are simply ordinals to n'th expiry, not times, and there are empty columns.. * The next function in the chain, EquityFutureOptionVolatilitySurfaceDataFunction, sorts this out, but produces the tiled STANDARD type, hence we use that. Easy to refactor if desired. */ protected SmileSurfaceDataBundle getData(final FunctionInputs inputs, final ValueRequirement volatilityDataRequirement, final ValueRequirement forwardCurveRequirement) { final Object volatilitySurfaceObject = inputs.getValue(volatilityDataRequirement); if (volatilitySurfaceObject == null) { throw new OpenGammaRuntimeException("Could not get " + volatilityDataRequirement); } final Object forwardCurveObject = inputs.getValue(forwardCurveRequirement); if (forwardCurveObject == null) { throw new OpenGammaRuntimeException("Could not get " + forwardCurveRequirement); } final ForwardCurve forwardCurve = (ForwardCurve) forwardCurveObject; @SuppressWarnings("unchecked") final VolatilitySurfaceData<Double, Double> rawVolatilitySurface = (VolatilitySurfaceData<Double, Double>) volatilitySurfaceObject; // Get Unique Expiries final double[] expiries = ArrayUtils.toPrimitive(rawVolatilitySurface.getXs()); final DoubleLinkedOpenHashSet expirySet = new DoubleLinkedOpenHashSet(expiries); final double[] uniqueExpiries = expirySet.toDoubleArray(); Arrays.sort(uniqueExpiries); final int nExpiries = uniqueExpiries.length; // Get Unique Strikes final double[] strikes = ArrayUtils.toPrimitive(rawVolatilitySurface.getYs()); final DoubleLinkedOpenHashSet strikeSet = new DoubleLinkedOpenHashSet(strikes); final double[] uniqueStrikes = strikeSet.toDoubleArray(); Arrays.sort(uniqueStrikes); final int nStrikes = uniqueStrikes.length; // Convert vols and strikes to double[][], // noting that different expiries may have different populated strikes final double[][] fullStrikes = new double[nExpiries][]; final double[][] fullVols = new double[nExpiries][]; for (int i = 0; i < nExpiries; i++) { final DoubleList availableStrikes = new DoubleArrayList(); final DoubleList availableVols = new DoubleArrayList(); for (int j = 0; j < nStrikes; j++) { final Double vol = rawVolatilitySurface.getVolatility(uniqueExpiries[i], uniqueStrikes[j]); if (vol != null) { availableStrikes.add(uniqueStrikes[j]); availableVols.add(vol); } } if (availableVols.size() == 0) { throw new OpenGammaRuntimeException("Unexpected error. No Vols found for an expiry."); // Use ArrayLists for fullStrikes (and Vols). But first, check input surface data } fullStrikes[i] = availableStrikes.toDoubleArray(); fullVols[i] = availableVols.toDoubleArray(); } // TODO Where does it matter whether calls are used? No prices are given, just vols.. return new StandardSmileSurfaceDataBundle(forwardCurve, uniqueExpiries, fullStrikes, fullVols); }
From source file:com.rapidminer.operator.learner.tree.SelectionCreator.java
/** * Creates in parallel an example index start selection for each numerical attribute, or if * there is none, only one./* w w w . j a v a 2s . c o m*/ * * @param operator * the operator for which the calculation is done * @return a map containing for each numerical attribute an example index array such that the * associated attribute values are in ascending order. * @throws OperatorException */ public Map<Integer, int[]> getStartSelectionParallel(Operator operator) throws OperatorException { Map<Integer, int[]> selection = new HashMap<>(); if (columnTable.getNumberOfRegularNumericalAttributes() == 0) { selection.put(0, createFullArray(columnTable.getNumberOfExamples())); } else { List<Callable<int[]>> tasks = new ArrayList<Callable<int[]>>(); final Integer[] bigSelectionArray = createFullBigArray(columnTable.getNumberOfExamples()); for (int j = columnTable.getNumberOfRegularNominalAttributes(); j < columnTable .getTotalNumberOfRegularAttributes(); j++) { final double[] attributeColumn = columnTable.getNumericalAttributeColumn(j); tasks.add(new Callable<int[]>() { @Override public int[] call() { Integer[] startSelection = Arrays.copyOf(bigSelectionArray, bigSelectionArray.length); Arrays.sort(startSelection, new Comparator<Integer>() { @Override public int compare(Integer a, Integer b) { return Double.compare(attributeColumn[a], attributeColumn[b]); } }); return ArrayUtils.toPrimitive(startSelection); } }); } List<int[]> results = null; try { results = Resources.getConcurrencyContext(operator).call(tasks); } catch (ExecutionException e) { Throwable cause = e.getCause(); if (cause instanceof RuntimeException) { throw (RuntimeException) cause; } else if (cause instanceof Error) { throw (Error) cause; } else { throw new OperatorException(cause.getMessage(), cause); } } for (int j = columnTable.getNumberOfRegularNominalAttributes(); j < columnTable .getTotalNumberOfRegularAttributes(); j++) { selection.put(j, results.get(j - columnTable.getNumberOfRegularNominalAttributes())); } } return selection; }
From source file:com.microrisc.hdlcframing.v1.HDLC_DataTransformer.java
/** * Retrieves and returns data from specified HDLC data frame. * @param uartDataFrame HDLC data frame, which the data to retrive from * @return data from specified HDLC data frame * @throws HDLC_FormatException if specified data frame has incorrect format *//*from ww w . j a v a 2 s.c o m*/ public static short[] getDataFromFrame(short[] uartDataFrame) throws HDLC_FormatException { checkUartDataFrame(uartDataFrame); List<Short> dataList = new LinkedList<>(); if (uartDataFrame[0] != FLAG_SEQUENCE) { throw new HDLC_FormatException("First byte must be 0x7e"); } if (uartDataFrame[uartDataFrame.length - 1] != FLAG_SEQUENCE) { throw new HDLC_FormatException("Last byte must be 0x7e"); } boolean escapedByte = false; short countedChecksum = -1; // getting starting position of a checksum int checksumStartPos = uartDataFrame.length - 2; if (uartDataFrame[uartDataFrame.length - 3] == CONTROL_ESCAPE) { checksumStartPos = uartDataFrame.length - 3; } for (int dataId = 1; dataId < checksumStartPos; dataId++) { short dataItem = uartDataFrame[dataId]; if (dataItem == CONTROL_ESCAPE) { escapedByte = true; continue; } // previous byte was CONTROL ESCAPE if (escapedByte) { if ((dataItem & ESCAPE_BIT) == 0) { dataItem |= ESCAPE_BIT; } else { dataItem ^= ESCAPE_BIT; } escapedByte = false; } if (countedChecksum == -1) { countedChecksum = (short) (0x5F ^ dataItem); } else { countedChecksum ^= dataItem; } dataList.add(dataItem); } short packetChecksum = uartDataFrame[uartDataFrame.length - 2]; if (uartDataFrame[uartDataFrame.length - 3] == CONTROL_ESCAPE) { packetChecksum = uartDataFrame[uartDataFrame.length - 2]; if ((packetChecksum & ESCAPE_BIT) == 0) { packetChecksum |= ESCAPE_BIT; } else { packetChecksum ^= ESCAPE_BIT; } } if (countedChecksum != packetChecksum) { throw new HDLC_FormatException( "Checksum mismatch. " + "Counted: " + countedChecksum + " Get: " + packetChecksum); } Short[] data = dataList.toArray(new Short[] {}); return ArrayUtils.toPrimitive(data); }