List of usage examples for org.apache.commons.lang3 ArrayUtils toPrimitive
public static boolean[] toPrimitive(final Boolean[] array)
Converts an array of object Booleans to primitives.
This method returns null for a null input array.
From source file:com.log4ic.compressor.utils.MemcachedUtils.java
private static AddressConfig biludAddrMapConfig(List<Node> nodeList) { AddressConfig config = new AddressConfig(); config.addressMap = new LinkedHashMap<InetSocketAddress, InetSocketAddress>(); List<Integer> weightsList = new ArrayList<Integer>(); for (Node node : nodeList) { Node masterNode = node.selectSingleNode("master"); Node weightsNode = ((Element) node).attribute("weights"); int weights = 1; if (weightsNode != null) { try { weights = Integer.parseInt(weightsNode.getText()); } catch (Exception e) { //fuck ide }/*from w ww .j a v a2s. c om*/ } weightsList.add(weights); InetSocketAddress masterAddr; if (masterNode != null) { masterAddr = biludAddr(masterNode); } else { masterAddr = biludAddr(node); } Node standbyNode = node.selectSingleNode("standby"); InetSocketAddress standbyAddr = null; if (standbyNode != null) { standbyAddr = biludAddr(standbyNode); } config.addressMap.put(masterAddr, standbyAddr); } config.widgets = ArrayUtils.toPrimitive(weightsList.toArray(new Integer[weightsList.size()])); return config; }
From source file:de.hsheilbronn.mi.domain.SvmMetaInformationImpl.java
@Override public void setProbabilityB(List<Double> probabilityB) { svmModel.probB = (ArrayUtils.toPrimitive(probabilityB.toArray(new Double[probabilityB.size()]))); }
From source file:main.java.miro.browser.browser.widgets.browser.views.LazyTreeViewContentProvider.java
public int getChildCount(ResourceHoldingObject parent, ViewerFilter[] filters) { if (parent instanceof RoaObject) return 0; int childCount = 0; CertificateObject ca = (CertificateObject) parent; ResourceHoldingObject obj;//ww w. ja v a 2s . c om ArrayList<Integer> list = new ArrayList<Integer>(); for (int i = 0; i < ca.getChildren().size(); i++) { obj = ca.getChildren().get(i); if (matchesFilters(ca, obj, filters)) { childCount++; list.add(i); } } int[] ar = ArrayUtils.toPrimitive(list.toArray(new Integer[list.size()])); indexMap.put(ca, ar); return childCount; }
From source file:net.larry1123.elec.util.test.config.AbstractConfigTest.java
public void ByteArrayListTest(String fieldName, Field testField) { try {// www . j a v a2 s . c o m //noinspection unchecked byte[] testFieldValue = ArrayUtils.toPrimitive( ((ArrayList<Byte>) testField.get(getConfigBase())).toArray(ArrayUtils.EMPTY_BYTE_OBJECT_ARRAY)); Assert.assertTrue(ArrayUtils.isEquals(getPropertiesFile().getByteArray(fieldName), testFieldValue)); } catch (IllegalAccessException e) { assertFailFieldError(fieldName); } }
From source file:de.hsheilbronn.mi.domain.SvmMetaInformationImpl.java
@Override public void setNumberOfSupportVectorsForEachClass(List<Integer> numberOfSupportVectorsForEachClass) { svmModel.nSV = (ArrayUtils.toPrimitive(numberOfSupportVectorsForEachClass .toArray(new Integer[numberOfSupportVectorsForEachClass.size()]))); }
From source file:ca.craigthomas.visualclassifier.dataset.DataSet.java
/** * Adds a list of samples to the DataSet. Each element in the list contains * a list of Doubles, which are assumed to be the samples to add. If the * DataSet has ground truth, the last element in each of the list of samples * is assumed to be the ground truth label. * /*from w w w . j a v a2 s.c o m*/ * @param samples the list of samples to add */ public void addSamples(List<List<Double>> samples) { for (List<Double> row : samples) { Double[] temp = row.toArray(new Double[row.size()]); double[] sampleRow = ArrayUtils.toPrimitive(temp); double[][] matrix = new double[1][sampleRow.length]; if (sHasTruth) { matrix[0] = ArrayUtils.subarray(sampleRow, 0, sampleRow.length - 1); addSampleRow(new DoubleMatrix(matrix)); matrix[0] = ArrayUtils.subarray(sampleRow, sampleRow.length - 1, sampleRow.length); addTruthRow(new DoubleMatrix(matrix)); } else { matrix[0] = sampleRow; addSampleRow(new DoubleMatrix(matrix)); } } }
From source file:engine.resources.objects.Baseline.java
public static Object checkArray(Object o) { if (o != null && o.getClass().isArray()) { if (o.getClass().isPrimitive() || o instanceof byte[]) { if (o instanceof boolean[]) { return ArrayUtils.toObject((boolean[]) o); } else if (o instanceof byte[]) { return ArrayUtils.toObject((byte[]) o); } else if (o instanceof char[]) { return ArrayUtils.toObject((char[]) o); } else if (o instanceof short[]) { return ArrayUtils.toObject((short[]) o); } else if (o instanceof int[]) { return ArrayUtils.toObject((int[]) o); } else if (o instanceof float[]) { return ArrayUtils.toObject((float[]) o); } else if (o instanceof double[]) { return ArrayUtils.toObject((double[]) o); } else if (o instanceof long[]) { return ArrayUtils.toObject((long[]) o); }//from ww w. j av a2s . c o m } else { if (o instanceof Boolean[]) { return ArrayUtils.toPrimitive((Boolean[]) o); } else if (o instanceof Byte[]) { return ArrayUtils.toPrimitive((Byte[]) o); } else if (o instanceof Character[]) { return ArrayUtils.toPrimitive((Character[]) o); } else if (o instanceof Short[]) { return ArrayUtils.toPrimitive((Short[]) o); } else if (o instanceof Integer[]) { return ArrayUtils.toPrimitive((Integer[]) o); } else if (o instanceof Float[]) { return ArrayUtils.toPrimitive((Float[]) o); } else if (o instanceof Double[]) { return ArrayUtils.toPrimitive((Double[]) o); } else if (o instanceof Long[]) { return ArrayUtils.toPrimitive((Long[]) o); } } } return o; }
From source file:dk.dma.ais.packet.AisPacketFiltersStateful.java
/** * Return false if this message is known to be related to a target with an IMO outside the given list. *//*from w w w . ja v a 2 s.co m*/ public Predicate<AisPacket> filterOnTargetImo(Integer[] imos) { final int[] list = ArrayUtils.toPrimitive(imos); Arrays.sort(list); return new Predicate<AisPacket>() { public boolean test(AisPacket p) { aisPacketStream.add(p); // Update state final int mmsi = getMmsi(p); // Get MMSI in question final int imo = getImo(mmsi); // Extract IMO no. - if we know it return imo < 0 ? false : Arrays.binarySearch(list, imo) >= 0; } public String toString() { return "imo in " + skipBrackets(Arrays.toString(list)); } }; }
From source file:eu.crisis_economics.abm.algorithms.series.TestAbstractSeries.java
/** * Assert that the long term mean of values drawn from a {@link RandomSeries} object * is as expected./* w w w. j a v a 2s. c o m*/ * * @param series (<code>S</code>) <br> * The {@link RandomSeries} object to test. * @param numberOfSamples <br> * The number of samples to draw from <code>S</code>. * @param expectedLongTermStd <br> * The expected long term standard deviation of the series. */ protected void assertLongTermStd(RandomSeries series, final int numberOfSamples, final double expectedLongTermStd) { final List<Double> observations = new ArrayList<Double>(); for (int i = 0; i < numberOfSamples; ++i) observations.add(series.next()); final double observedMean = (new StandardDeviation()) .evaluate(ArrayUtils.toPrimitive(observations.toArray(new Double[observations.size()]))); Assert.assertEquals(observedMean, expectedLongTermStd, 1.e-1); }
From source file:de.biomedical_imaging.traJ.features.PowerLawFeature.java
/** * @return An double array with the elements [0]= alpha, [1]=diffusion coefficient [2]=goodness of fit *///from w w w . ja va 2s. c om @Override public double[] evaluate() { ArrayList<Double> xDataList = new ArrayList<Double>(); ArrayList<Double> yDataList = new ArrayList<Double>(); msdeval.setTrajectory(t); double[][] data = new double[maxlag - minlag + 1][3]; for (int i = minlag; i <= maxlag; i++) { msdeval.setTimelag(i); data[i - minlag][0] = i * timelag; double[] res = msdeval.evaluate(); data[i - minlag][1] = res[evaluateIndex]; data[i - minlag][2] = (int) res[2]; } //Weightening for (int i = 0; i < (maxlag - minlag + 1); i++) { double x = data[i][0]; double y = data[i][1]; int np = (int) data[i][2]; for (int j = 0; j < np; j++) { xDataList.add(x); yDataList.add(y); } } double[] xData = ArrayUtils.toPrimitive(xDataList.toArray(new Double[0])); double[] yData = ArrayUtils.toPrimitive(yDataList.toArray(new Double[0])); PowerLawCurveFit pwFit = new PowerLawCurveFit(); if (useInitialGuess) { pwFit.doFit(xData, yData, initalAlpha, initalDiffusionCoefficient); } else { pwFit.doFit(xData, yData); } result = new double[] { pwFit.getAlpha(), pwFit.getDiffusionCoefficient(), pwFit.getGoodness() }; return result; }