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:jat.examples.TwoBodyExample.TwoBodyExample.java
public static void main(String[] args) { TwoBodyExample x = new TwoBodyExample(); // create a TwoBody orbit using orbit elements TwoBodyAPL sat = new TwoBodyAPL(7000.0, 0.3, 0.0, 0.0, 0.0, 0.0); double[] y = sat.randv(); ArrayRealVector v = new ArrayRealVector(y); DecimalFormat df2 = new DecimalFormat("#,###,###,##0.00"); RealVectorFormat format = new RealVectorFormat(df2); System.out.println(format.format(v)); // find out the period of the orbit double period = sat.period(); // set the final time = one orbit period double tf = period; // set the initial time to zero double t0 = 0.0; // propagate the orbit FirstOrderIntegrator dp853 = new DormandPrince853Integrator(1.0e-8, 100.0, 1.0e-10, 1.0e-10); dp853.addStepHandler(sat.stepHandler); // double[] y = new double[] { 7000.0, 0, 0, .0, 8, 0 }; // initial // state/* w w w . j a va 2 s .c o m*/ dp853.integrate(sat, 0.0, y, 8000, y); // now y contains final state at // tf Double[] objArray = sat.time.toArray(new Double[sat.time.size()]); double[] timeArray = ArrayUtils.toPrimitive(objArray); double[] xsolArray = ArrayUtils.toPrimitive(sat.xsol.toArray(new Double[sat.time.size()])); double[] ysolArray = ArrayUtils.toPrimitive(sat.ysol.toArray(new Double[sat.time.size()])); double[][] XY = new double[timeArray.length][2]; // int a=0; // System.arraycopy(timeArray,0,XY[a],0,timeArray.length); // System.arraycopy(ysolArray,0,XY[1],0,ysolArray.length); for (int i = 0; i < timeArray.length; i++) { XY[i][0] = xsolArray[i]; XY[i][1] = ysolArray[i]; } Plot2DPanel p = new Plot2DPanel(); // Plot2DPanel p = new Plot2DPanel(min, max, axesScales, axesLabels); ScatterPlot s = new ScatterPlot("orbit", Color.RED, XY); // LinePlot l = new LinePlot("sin", Color.RED, XY); // l.closed_curve = false; // l.draw_dot = true; p.addPlot(s); p.setLegendOrientation(PlotPanel.SOUTH); double plotSize = 10000.; double[] min = { -plotSize, -plotSize }; double[] max = { plotSize, plotSize }; p.setFixedBounds(min, max); new FrameView(p).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); System.out.println("end"); }
From source file:main.java.utils.Permutation.java
public static Set<IntPair> getPermutations(Set<Integer> list) { Set<IntPair> permutations = new HashSet<IntPair>(); int[] array = ArrayUtils.toPrimitive(list.toArray(new Integer[list.size()])); for (int i = 0; i < array.length; i++) for (int j = i + 1; j < array.length; j++) permutations.add(new IntPair(array[i], array[j])); return permutations; }
From source file:com.linkedin.pinot.common.utils.PrimitiveArrayUtils.java
/** * Turns the passed array into a primitive array, if necessary. * * @param array The array to convert/*from w ww . j a va 2 s.c om*/ * @return A primitive array */ public static Object toPrimitive(Object array) { if (array instanceof int[] || array instanceof long[] || array instanceof short[] || array instanceof byte[] || array instanceof char[] || array instanceof float[] || array instanceof double[] || array instanceof boolean[]) { return array; } else if (array instanceof Integer[]) { return ArrayUtils.toPrimitive((Integer[]) array); } else if (array instanceof Long[]) { return ArrayUtils.toPrimitive((Long[]) array); } else if (array instanceof Short[]) { return ArrayUtils.toPrimitive((Short[]) array); } else if (array instanceof Byte[]) { return ArrayUtils.toPrimitive((Byte[]) array); } else if (array instanceof Character[]) { return ArrayUtils.toPrimitive((Character[]) array); } else if (array instanceof Float[]) { return ArrayUtils.toPrimitive((Float[]) array); } else if (array instanceof Double[]) { return ArrayUtils.toPrimitive((Double[]) array); } else if (array instanceof Boolean[]) { return ArrayUtils.toPrimitive((Boolean[]) array); } else if (array instanceof Object[]) { Object[] objectArray = (Object[]) array; if (objectArray.length == 0) { return array; } Object firstElement = objectArray[0]; if (firstElement == null) { return array; } else if (firstElement instanceof Integer) { int[] newArray = new int[objectArray.length]; for (int i = 0; i < newArray.length; i++) { newArray[i] = (Integer) objectArray[i]; } return newArray; } else if (firstElement instanceof Long) { long[] newArray = new long[objectArray.length]; for (int i = 0; i < newArray.length; i++) { newArray[i] = (Long) objectArray[i]; } return newArray; } else if (firstElement instanceof Short) { short[] newArray = new short[objectArray.length]; for (int i = 0; i < newArray.length; i++) { newArray[i] = (Short) objectArray[i]; } return newArray; } else if (firstElement instanceof Byte) { byte[] newArray = new byte[objectArray.length]; for (int i = 0; i < newArray.length; i++) { newArray[i] = (Byte) objectArray[i]; } return newArray; } else if (firstElement instanceof Character) { char[] newArray = new char[objectArray.length]; for (int i = 0; i < newArray.length; i++) { newArray[i] = (Character) objectArray[i]; } return newArray; } else if (firstElement instanceof Float) { float[] newArray = new float[objectArray.length]; for (int i = 0; i < newArray.length; i++) { newArray[i] = (Float) objectArray[i]; } return newArray; } else if (firstElement instanceof Double) { double[] newArray = new double[objectArray.length]; for (int i = 0; i < newArray.length; i++) { newArray[i] = (Double) objectArray[i]; } return newArray; } else if (firstElement instanceof Boolean) { boolean[] newArray = new boolean[objectArray.length]; for (int i = 0; i < newArray.length; i++) { newArray[i] = (Boolean) objectArray[i]; } return newArray; } else { throw new IllegalArgumentException( "First element of array is of unhandled type " + array.getClass()); } } else { throw new IllegalArgumentException("Not an array, got object of type " + array.getClass()); } }
From source file:io.cortical.retina.model.TestDataHarness.java
/** * Create dummy {@link Fingerprint}./*from ww w .j a v a 2 s .co m*/ * * @return dummy fingerprint. */ public static Fingerprint createFingerprint() { Random random = new Random(SEED); Set<Integer> positionSet = new LinkedHashSet<>(); while (positionSet.size() <= FINGERPRINT_LENGTH) { positionSet.add(random.nextInt(MAX_POSITION)); } Integer[] positionsInteger = new Integer[FINGERPRINT_LENGTH]; positionsInteger = positionSet.toArray(positionsInteger); sort(positionsInteger); return new Fingerprint(ArrayUtils.toPrimitive(positionsInteger)); }
From source file:mase.neat.NEATSerializer.java
public static double[] serializeToArray(NEATNeuralNet net) { NEATNetDescriptor descr = (NEATNetDescriptor) net.netDescriptor(); NEATChromosome chromo = (NEATChromosome) descr.neatStructure(); Gene[] genes = chromo.genes();//from www .j a va 2s .c o m ArrayList<Double> res = new ArrayList<Double>(); for (Gene gene : genes) { if (gene instanceof NEATNodeGene) { NEATNodeGene neatGene = (NEATNodeGene) gene; res.add(NODE); res.add((double) neatGene.id()); res.add(neatGene.sigmoidFactor()); res.add((double) neatGene.getType()); res.add(neatGene.bias()); } else if (gene instanceof NEATLinkGene) { NEATLinkGene neatGene = (NEATLinkGene) gene; res.add(LINK); res.add(neatGene.isEnabled() ? 1d : 0d); res.add((double) neatGene.getFromId()); res.add((double) neatGene.getToId()); res.add(neatGene.getWeight()); } } Double[] array = new Double[res.size()]; res.toArray(array); return ArrayUtils.toPrimitive(array); }
From source file:io.cortical.rest.model.TestDataMother.java
/** * Create dummy {@link Fingerprint}.// w w w . j a va 2 s . co m * * @return dummy fingerprint. */ public static Fingerprint createFingerprint() { Random random = new Random(); Set<Integer> positionSet = new HashSet<>(); while (positionSet.size() <= FINGERPRINT_LENGTH) { positionSet.add(random.nextInt(MAX_POSITION)); } Integer[] positionsInteger = new Integer[FINGERPRINT_LENGTH]; positionsInteger = positionSet.toArray(positionsInteger); sort(positionsInteger); return new Fingerprint(ArrayUtils.toPrimitive(positionsInteger)); }
From source file:com.microsoft.rest.serializer.ByteArraySerializer.java
@Override public void serialize(Byte[] value, JsonGenerator jgen, SerializerProvider provider) throws IOException { jgen.writeBinary(ArrayUtils.toPrimitive(value)); }
From source file:hyperheuristics.algorithm.moeadfrrmab.UCBSelectorVariance.java
protected double calcVariance(String op) { ArrayList<String[]> slOp = slidingwindow.getWindowforOp(op); if (slOp.size() > 1) { ArrayList<Double> values = new ArrayList<>(); for (int i = 0; i < slOp.size(); i++) { String[] data = slOp.get(i); double FIR = Double.valueOf(data[1]); values.add(FIR);/*from www.jav a2 s. co m*/ } double[] arr = ArrayUtils.toPrimitive(values.toArray(new Double[0])); return this.calcVariance(arr); } return 1.0; }
From source file:dk.netdesign.common.osgi.config.filters.StringToCharacterArrayFilter.java
@Override public String revert(Character[] input) throws TypeFilterException { return new String(ArrayUtils.toPrimitive(input)); }
From source file:ca.craigthomas.visualclassifier.dataset.TestDataSetReader.java
@Test public void testReadFromCSVFileSeparatesLabelsCorrectly() throws IOException { double[][] expected = { { 1.0, 1.0, 1.0 }, { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }, { 0.0, 0.0, 0.0 } }; List<List<Double>> result = DataSetReader.readCSVFile(SAMPLE_FILE); assertEquals(expected.length, result.size()); for (int index = 0; index < expected.length; index++) { List<Double> row = result.get(index); Double[] temp = row.toArray(new Double[row.size()]); double[] sampleRow = ArrayUtils.toPrimitive(temp); Assert.assertArrayEquals(expected[index], sampleRow, 0.0001); }// w w w . j a v a 2 s . c o m }