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:org.tinygroup.jdbctemplatedslsession.SimpleDslSession.java
private int[] executeBatchUpdate(final String sql, Map<String, Object>[] params, int batchSize) { final List<Integer> records = new ArrayList<Integer>(); if (params.length > batchSize) { batchProcess(batchSize, params, new BatchOperateCallback() { public int[] callback(List<Map<String, Object>> params) { return null; }//from www . java 2 s. c o m public int[] callbackList(List<List<Object>> params) { return null; } public int[] callback(Map<String, Object>[] params) { int[] affectedNums = simpleJdbcTemplate.batchUpdate(sql, params); Collections.addAll(records, ArrayUtils.toObject(affectedNums)); return affectedNums; } }); return ArrayUtils.toPrimitive(records.toArray(new Integer[0])); } return simpleJdbcTemplate.batchUpdate(sql, params); }
From source file:org.ut.biolab.medsavant.client.view.component.ListViewTablePanel.java
public void removeRows(Set<Object> keySet) { java.util.List<Integer> rowIndices = new ArrayList<Integer>(keySet.size()); for (Object key : keySet) { Set<Integer> ri = keyRowIndexMap.get(key); if (ri != null) { rowIndices.addAll(ri);/*from w w w . j a va 2s. co m*/ } } removeRows(ArrayUtils.toPrimitive(rowIndices.toArray(new Integer[rowIndices.size()]))); }
From source file:org.ut.biolab.medsavant.client.view.component.ListViewTablePanel.java
private void copyItems(final ListViewTablePanel toList, Set<Object> rowKeys, boolean copy) { Set<Integer> moveRowIndices = new HashSet<Integer>(); Set<Integer> removeRowIndices = new HashSet<Integer>(); for (Object rowKey : rowKeys) { Set<Integer> rowIndicesForObj = keyRowIndexMap.get(rowKey); if (rowIndicesForObj != null) { if (!toList.keyRowIndexMap.containsKey(rowKey)) { moveRowIndices.addAll(rowIndicesForObj); } else { removeRowIndices.addAll(rowIndicesForObj); }/*from w w w .j ava 2s .c o m*/ } } int[] mi = ArrayUtils.toPrimitive(moveRowIndices.toArray(new Integer[moveRowIndices.size()])); moveItemsFromRows(toList, mi, copy); if (!copy) { int[] ri = ArrayUtils.toPrimitive(removeRowIndices.toArray(new Integer[removeRowIndices.size()])); removeRows(ri); } }
From source file:org.yccheok.jstock.charting.TechnicalAnalysis.java
/** * Returns the latest EMA./*from w w w .j a v a2 s. co m*/ * * @param values list of raw data input * @param period the duration period * @return the latest EMA */ public static Double createEMA(java.util.List<Double> values, int period) { if (period <= 0) { throw new java.lang.IllegalArgumentException("period must be greater than 0"); } final int size = values.size(); final Core core = new Core(); final int allocationSize = size - core.emaLookback(period); if (allocationSize <= 0) { return null; } final double[] output = new double[allocationSize]; final MInteger outBegIdx = new MInteger(); final MInteger outNbElement = new MInteger(); double[] _values = ArrayUtils.toPrimitive(values.toArray(new Double[0])); core.ema(0, values.size() - 1, _values, period, outBegIdx, outNbElement, output); return output[outNbElement.value - 1]; }
From source file:org.yccheok.jstock.charting.TechnicalAnalysis.java
/** * Returns the latest MFI.//from w ww.j a va2 s .com * * @param highs list of high price * @param lows list of low price * @param closes list of close price * @param volumes list of volume * @param period the duration period * @return the latest MFI */ public static Double createMFI(java.util.List<Double> highs, java.util.List<Double> lows, java.util.List<Double> closes, // TODO: CRITICAL LONG BUG REVISED NEEDED. java.util.List<Long> volumes, int period) { if (period <= 0) { throw new java.lang.IllegalArgumentException("period must be greater than 0"); } if (highs.size() != lows.size() || highs.size() != closes.size() || highs.size() != volumes.size()) { throw new java.lang.IllegalArgumentException("input list must be same size"); } final int size = highs.size(); final Core core = new Core(); final int allocationSize = size - core.mfiLookback(period); if (allocationSize <= 0) { return null; } final double[] output = new double[allocationSize]; final MInteger outBegIdx = new MInteger(); final MInteger outNbElement = new MInteger(); double[] _highs = ArrayUtils.toPrimitive(highs.toArray(new Double[0])); double[] _lows = ArrayUtils.toPrimitive(lows.toArray(new Double[0])); double[] _closes = ArrayUtils.toPrimitive(closes.toArray(new Double[0])); long[] _volumes = ArrayUtils.toPrimitive(volumes.toArray(new Long[0])); double[] dv = new double[_volumes.length]; // Do not use System.arraycopy. // It will cause java.lang.ArrayStoreException, due to type mismatch. for (int i = 0; i < dv.length; i++) { dv[i] = _volumes[i]; } core.mfi(0, _highs.length - 1, _highs, _lows, _closes, dv, period, outBegIdx, outNbElement, output); return output[outNbElement.value - 1]; }
From source file:org.yccheok.jstock.charting.TechnicalAnalysis.java
/** * Returns the latest RSI.//from www . j a va 2 s . c om * * @param values list of raw data input * @param period the duration period * @return the latest RSI */ public static Double createRSI(java.util.List<Double> values, int period) { if (period <= 0) { throw new java.lang.IllegalArgumentException("period must be greater than 0"); } final int size = values.size(); final Core core = new Core(); final int allocationSize = size - core.rsiLookback(period); if (allocationSize <= 0) { return null; } final double[] output = new double[allocationSize]; final MInteger outBegIdx = new MInteger(); final MInteger outNbElement = new MInteger(); double[] _values = ArrayUtils.toPrimitive(values.toArray(new Double[0])); core.rsi(0, values.size() - 1, _values, period, outBegIdx, outNbElement, output); return output[outNbElement.value - 1]; }
From source file:org.yccheok.jstock.charting.TechnicalAnalysis.java
public static MACD.Result createMACDFix(List<Double> values, int period) { if (period <= 0) { throw new java.lang.IllegalArgumentException("period must be greater than 0"); }//from w w w . j a v a 2s .c o m final int size = values.size(); final Core core = new Core(); final int allocationSize = size - core.macdFixLookback(period); if (allocationSize <= 0) { return null; } final double[] outMACD = new double[allocationSize]; final double[] outMACDSignal = new double[allocationSize]; final double[] outMACDHist = new double[allocationSize]; final MInteger outBegIdx = new MInteger(); final MInteger outNbElement = new MInteger(); double[] _values = ArrayUtils.toPrimitive(values.toArray(new Double[0])); core.macdFix(0, values.size() - 1, _values, period, outBegIdx, outNbElement, outMACD, outMACDSignal, outMACDHist); return MACD.Result.newInstance(outMACD[outNbElement.value - 1], outMACDSignal[outNbElement.value - 1], outMACDHist[outNbElement.value - 1]); }
From source file:parquet.column.statistics.bloomfilter.BloomFilter.java
public void setBitSet(List<Long> data) { bitSet = new BitSet(ArrayUtils.toPrimitive(data.toArray(new Long[] {}))); }
From source file:playground.pieter.singapore.demand.InputDataCollection.java
private void loadSubDGPLocationSamplers() { inputLog.info("Loading locationsamplers for each subdgp and work activity type"); String facilityToSubDGPTable = diverseScriptProperties.getProperty("workFacilitiesToSubDGP"); HashMap<String, Integer> facilityToSubDGP = new HashMap<>(); HashMap<Integer, HashMap<String, Tuple<ArrayList<String>, ArrayList<Double>>>> subDGPActivityMapping = new HashMap<>(); HashMap<Integer, HashMap<String, LocationSampler>> subDGPActivityLocationSamplers = new HashMap<>(); try {/*from w ww . j av a2 s . co m*/ // start by mapping facilities to subdgps inputLog.info("\tMapping facilities to subdgps"); ResultSet rs = dba.executeQuery(String.format("select * from %s", facilityToSubDGPTable)); while (rs.next()) { facilityToSubDGP.put(rs.getString("id"), rs.getInt("subdgp")); } // initialize the hashmaps inputLog.info("\tInitializing hashmaps"); rs = dba.executeQuery( String.format("select distinct subdgp from %s order by subdgp", facilityToSubDGPTable)); while (rs.next()) { subDGPActivityMapping.put(rs.getInt("subdgp"), new HashMap<String, Tuple<ArrayList<String>, ArrayList<Double>>>()); subDGPActivityLocationSamplers.put(rs.getInt("subdgp"), new HashMap<String, LocationSampler>()); } // further initialization of the hashmaps for (String activityType : this.mainActivityTypes) { if (!activityType.startsWith("w_")) continue; rs = dba.executeQuery( String.format("select distinct subdgp from %s order by subdgp", facilityToSubDGPTable)); while (rs.next()) { subDGPActivityMapping.get(rs.getInt("subdgp")).put(activityType, new Tuple<>(new ArrayList<String>(), new ArrayList<Double>())); } } } catch (SQLException | NoConnectionException e) { e.printStackTrace(); } // then, go through the facilities for each work activity, find the subdgp theyre in // put a reference to them in that subdgp's activity type map inputLog.info("\tFilling capacities"); for (String activityType : this.mainActivityTypes) { // only look at work activities if (!activityType.startsWith("w_")) continue; TreeMap<Id<ActivityFacility>, ? extends ActivityFacility> facilities = this.scenario .getActivityFacilities().getFacilitiesForActivityType(activityType); for (Entry<Id<ActivityFacility>, ? extends ActivityFacility> e : facilities.entrySet()) { String currid = e.getKey().toString(); double currcap = e.getValue().getActivityOptions().get(activityType).getCapacity(); // TODO: check spatial join of facilities to subdgps // there are a few facilities that havent spatially joined properly, skip over them try { int subDGP = facilityToSubDGP.get(currid); subDGPActivityMapping.get(subDGP).get(activityType).getFirst().add(currid); subDGPActivityMapping.get(subDGP).get(activityType).getSecond().add(currcap); } catch (NullPointerException ne) { } } } // now, convert all the arraylists to arrays, and create location samplers inputLog.info("\tConverting to arrays"); for (int subdgp : subDGPActivityMapping.keySet()) { for (String acttype : subDGPActivityMapping.get(subdgp).keySet()) { ArrayList ids = subDGPActivityMapping.get(subdgp).get(acttype).getFirst(); ArrayList caps = subDGPActivityMapping.get(subdgp).get(acttype).getSecond(); String[] idsA = (String[]) ids.toArray(new String[ids.size()]); double[] capsA = ArrayUtils.toPrimitive((Double[]) caps.toArray(new Double[caps.size()])); subDGPActivityLocationSamplers.get(subdgp).put(acttype, new LocationSampler(acttype, idsA, capsA)); } } this.subDGPActivityLocationSamplers = subDGPActivityLocationSamplers; this.facilityToSubDGP = facilityToSubDGP; inputLog.info("DONE: Loading locationsamplers for each subdgp and work activity type"); }
From source file:spout.mddb.MddbFeatureExtractorSpout.java
/** * When this method is called, Storm is requesting that the Spout emit tuples to the * output collector. This method should be non-blocking, so if the Spout has no tuples * to emit, this method should return. nextTuple, ack, and fail are all called in a tight * loop in a single thread in the spout task. When there are no tuples to emit, it is courteous * to have nextTuple sleep for a short amount of time (like a single millisecond) * so as not to waste too much CPU./*from w w w. j av a2 s. com*/ */ @Override public synchronized void nextTuple() { if (peekableScanner == null) { Logger.getAnonymousLogger().log(Level.INFO, MessageFormat.format("No more featureVectors. Visit {0} later", taskId)); } else { try { if (peekableScanner.hasNext()) { tupleBeingProcessed = peekableScanner.next(); } final List<Map<String, List<Double>>> dict = SpoutUtils.pythonDictToJava(tupleBeingProcessed); for (Map<String, List<Double>> map : dict) { // hack //noinspection ToArrayCallWithZeroLengthArrayArgument final Double[] features = map.get("chi2").toArray(new Double[0]); //noinspection ToArrayCallWithZeroLengthArrayArgument final Double[] moreFeatures = map.get("chi1").toArray(new Double[0]); final Double[] both = (Double[]) ArrayUtils.addAll(features, moreFeatures); collector.emit(new Values(messageId++, ArrayUtils.toPrimitive(both))); } peekableScanner = moveSpoutForward(); } catch (Exception e) { throw new IllegalStateException(e); } } }