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:net.larry1123.elec.util.test.config.AbstractConfigTest.java
public void LongArrayListTest(String fieldName, Field testField) { try {/* ww w. j a v a 2s . com*/ //noinspection unchecked,unchecked long[] testFieldValue = ArrayUtils.toPrimitive(((ArrayList<Long>) testField.get(getConfigBase())) .toArray(new Long[((ArrayList<Long>) testField.get(getConfigBase())).size()])); Assert.assertTrue(ArrayUtils.isEquals(getPropertiesFile().getLongArray(fieldName), testFieldValue)); } catch (IllegalAccessException e) { assertFailFieldError(fieldName); } }
From source file:net.sf.sessionAnalysis.SessionVisitorArrivalAndCompletionRate.java
/** * Note that metrics other than max, min are more difficult, as we need to include the duration * that this number of sessions is present in the interval (e.g., for mean, median, ...). */// ww w. j a va 2 s . co m private void computeMaxSessionsPerInterval() { final long durationNanos = this.maxTimestampNanos - this.minTimestampNanos; final int numBuckets = (int) Math.ceil((double) durationNanos / this.resolutionValueNanos); // Note that the map must not be filled with 0's, because this introduces errors for // intervals without events. TreeMap<Integer, Integer> numSessionsPerInterval = new TreeMap<Integer, Integer>(); for (Entry<Long, Integer> numSessionChangeEvent : this.numConcurrentSessionsOverTime.entrySet()) { final long eventTimeStamp = numSessionChangeEvent.getKey(); final int numSessionsAtTime = numSessionChangeEvent.getValue(); final int eventTimeStampBucket = (int) ((eventTimeStamp - this.minTimestampNanos) / this.resolutionValueNanos); Integer lastMaxNumForBucket = numSessionsPerInterval.get(eventTimeStampBucket); if (lastMaxNumForBucket == null || numSessionsAtTime > lastMaxNumForBucket) { numSessionsPerInterval.put(eventTimeStampBucket, numSessionsAtTime); } } // Now we need to fill intervals without values with the last non-null value int lastNonNullValue = 0; for (int i = 0; i < numBuckets; i++) { Integer curVal = numSessionsPerInterval.get(i); if (curVal == null) { numSessionsPerInterval.put(i, lastNonNullValue); } else { lastNonNullValue = curVal; } } this.maxNumSessionsPerInterval = ArrayUtils .toPrimitive(numSessionsPerInterval.values().toArray(new Integer[0])); }
From source file:com.github.jessemull.microflex.util.DoubleUtil.java
/** * Converts a list of doubles to an array of floats. * @param List<Double> list of doubles * @return array of floats *//*from w ww . j a v a2 s .c o m*/ public static float[] toFloatArray(List<Double> list) { for (Double val : list) { if (!OverFlowUtil.floatOverflow(val)) { OverFlowUtil.overflowError(val); } } return ArrayUtils.toPrimitive(list.toArray(new Float[list.size()])); }
From source file:com.andrada.sitracker.ui.fragment.AuthorsFragment.java
@Override public void onItemCheckedStateChanged(@NotNull ActionMode mode, int position, long id, boolean checked) { if (checked) { mSelectedAuthors.add(((Author) adapter.getItem(position)).getId()); } else {/*from ww w. java 2s . c o m*/ mSelectedAuthors.remove(((Author) adapter.getItem(position)).getId()); } int numSelectedAuthors = mSelectedAuthors.size(); mode.setTitle(getResources().getQuantityString(R.plurals.authors_selected, numSelectedAuthors, numSelectedAuthors)); checkedItems = ArrayUtils.toPrimitive(mSelectedAuthors.toArray(new Long[mSelectedAuthors.size()])); }
From source file:com.github.jessemull.microflex.util.IntegerUtil.java
/** * Converts a list of integers to an array of floats. * @param List<Integer> list of integers * @return array of floats *//* w w w. ja v a2 s . c om*/ public static float[] toFloatArray(List<Integer> list) { return ArrayUtils.toPrimitive(list.toArray(new Float[list.size()])); }
From source file:net.sf.sessionAnalysis.SessionVisitorArrivalAndCompletionRate.java
public long[] getArrivalTimestamps() { return ArrayUtils.toPrimitive(arrivalTimestamps.toArray(new Long[] {})); }
From source file:net.sf.mzmine.modules.peaklistmethods.peakpicking.adap3decompositionV2.ADAP3DecompositionV2SetupDialog.java
/** * Cluster all peaks in PeakList based on retention time *///from ww w . ja v a2s.c o m private void retTimeCluster() { List<Double> retTimeValues = new ArrayList<>(); List<Double> mzValues = new ArrayList<>(); List<Double> colorValues = new ArrayList<>(); Double minDistance = parameterSet.getParameter(ADAP3DecompositionV2Parameters.MIN_CLUSTER_DISTANCE) .getValue(); Integer minSize = parameterSet.getParameter(ADAP3DecompositionV2Parameters.MIN_CLUSTER_SIZE).getValue(); if (minDistance == null || minSize == null) return; List<RetTimeClustering.Cluster> retTimeClusters = new Decomposition().getRetTimeClusters(peaks, minDistance, minSize); int colorIndex = 0; final int numColors = 7; final double[] colors = new double[numColors]; for (int i = 0; i < numColors; ++i) colors[i] = (double) i / numColors; comboClustersModel.removeAllElements(); // Disable action listeners ActionListener[] comboListeners = cboClusters.getActionListeners(); for (ActionListener l : comboListeners) cboClusters.removeActionListener(l); for (RetTimeClustering.Cluster cluster : retTimeClusters) { for (BetterPeak peak : cluster.peaks) { retTimeValues.add(peak.getRetTime()); mzValues.add(peak.getMZ()); colorValues.add(colors[colorIndex % numColors]); } ++colorIndex; int i; for (i = 0; i < comboClustersModel.getSize(); ++i) { double retTime = comboClustersModel.getElementAt(i).retTime; if (cluster.retTime < retTime) { comboClustersModel.insertElementAt(cluster, i); break; } } if (i == comboClustersModel.getSize()) comboClustersModel.addElement(cluster); } // Enable action listeners for (ActionListener l : comboListeners) cboClusters.addActionListener(l); final int size = retTimeValues.size(); retTimeMZPlot.updateData(ArrayUtils.toPrimitive(retTimeValues.toArray(new Double[size])), ArrayUtils.toPrimitive(mzValues.toArray(new Double[size])), ArrayUtils.toPrimitive(colorValues.toArray(new Double[size]))); shapeCluster(); }
From source file:de.tudarmstadt.ukp.dkpro.core.mallet.lda.MalletLdaTopicModelInferencer.java
/** * Assign topics according to the following formula: * <p>//ww w . ja va 2 s . co m * Topic proportion must be at least the maximum topic's proportion divided by the maximum * number of topics to be assigned. In addition, the topic proportion must not lie under the * minTopicProb. If more topics comply with these criteria, only retain the n * (maxTopicAssignments) largest values. * * @param topicDistribution a double array containing the document's topic proportions * @return an array of integers pointing to the topics assigned to the document * @deprecated this method should be removed at some point because assignment / topic tagging * should be done in a dedicated step (module). */ // TODO: should return a boolean[] of the same size as topicDistribution // TODO: should probably be moved to a dedicated module because assignments (topic tagging) // should not be done at inference level @Deprecated private int[] assignTopics(final double[] topicDistribution) { /* * threshold is the largest value divided by the maximum number of topics or the fixed * number set as minTopicProb parameter. */ double threshold = Math .max(Collections.max(Arrays.asList(ArrayUtils.toObject(topicDistribution))).doubleValue() / maxTopicAssignments, minTopicProb); /* * assign indexes for values that are above threshold */ List<Integer> indexes = new ArrayList<>(topicDistribution.length); for (int i = 0; i < topicDistribution.length; i++) { if (topicDistribution[i] >= threshold) { indexes.add(i); } } /* * Reduce assignments to maximum number of allowed assignments. */ if (indexes.size() > maxTopicAssignments) { /* sort index list by corresponding values */ Collections.sort(indexes, (aO1, aO2) -> Double.compare(topicDistribution[aO1], topicDistribution[aO2])); while (indexes.size() > maxTopicAssignments) { indexes.remove(0); } } return ArrayUtils.toPrimitive(indexes.toArray(new Integer[indexes.size()])); }
From source file:edu.pitt.csb.stability.StabilitySearch.java
public void searchSerial() { long startMain = System.currentTimeMillis(); for (int s = 0; s < numSubs; s++) { DataSet dataSubSamp = data.subsetRows(ArrayUtils.toPrimitive(samps.get(s).toArray(new Integer[0]))); long start = System.currentTimeMillis(); Graph g = gs.search(dataSubSamp); long end = System.currentTimeMillis(); addEdges(g);/* w w w .j a v a2 s .c o m*/ if (runDir != null) { saveNet(s, g); pwTime.write("sn" + s + "\t" + (end - start) / 1000.0 + "\n"); } //DoubleMatrix2D curAdj = MixedUtils.skeletonToMatrix(g); //thetaMat.assign(curAdj, Functions.plus); } //thetaMat.assign(Functions.mult(1.0 / numSubs)); //thetaMat.assign(thetaMat.copy().assign(Functions.minus(1.0)), Functions.mult).assign(Functions.mult(-2.0)); //return thetaMat; updateThetaMat(); if (runDir != null) { pwTime.write("Total\t" + (System.currentTimeMillis() - startMain) / 1000.0 + "\n"); pwTime.flush(); } }
From source file:net.sf.sessionAnalysis.SessionVisitorArrivalAndCompletionRate.java
public long[] getCompletionTimestamps() { return ArrayUtils.toPrimitive(completionTimestamps.toArray(new Long[] {})); }