List of usage examples for java.util ArrayList subList
public List<E> subList(int fromIndex, int toIndex)
From source file:org.apache.ode.daohib.bpel.BpelDAOConnectionImpl.java
@SuppressWarnings("unchecked") public Map<Long, Collection<CorrelationSetDAO>> getCorrelationSets(Collection<ProcessInstanceDAO> instances) { if (instances.size() == 0) { return new HashMap<Long, Collection<CorrelationSetDAO>>(); }/*from w ww .j av a 2s. c o m*/ ArrayList<Long> iids = new ArrayList<Long>(instances.size()); int i = 0; for (ProcessInstanceDAO dao : instances) { iids.add(dao.getInstanceId()); i++; } Collection<HCorrelationSet> csets = new ArrayList<HCorrelationSet>(); // some databases don't like long lists of values with IN operator // so we select in batches. Oracle 9i, for instance, doesn't support // more than 1000 -- we opt to be conservative. final int batchSize = 100; int index = 0; while (index < iids.size()) { List<Long> subList = iids.subList(index, Math.min(index + batchSize, iids.size())); csets.addAll(getSession().getNamedQuery(HCorrelationSet.SELECT_CORSETS_BY_INSTANCES) .setParameterList("instances", subList).list()); index += batchSize; } Map<Long, Collection<CorrelationSetDAO>> map = new HashMap<Long, Collection<CorrelationSetDAO>>(); for (HCorrelationSet cset : csets) { Long id = cset.getInstance().getId(); Collection<CorrelationSetDAO> existing = map.get(id); if (existing == null) { existing = new ArrayList<CorrelationSetDAO>(); map.put(id, existing); } existing.add(new CorrelationSetDaoImpl(_sm, cset)); } return map; }
From source file:com.hygenics.parser.Upload.java
private void doScp() { ArrayList<String> files = new ArrayList<String>(); File fp = new File(localPath); if (fp.isDirectory()) { for (String f : fp.list()) { files.add(localPath + f);//from w ww .ja v a2s. c om } } else { files.add(localPath); } int p = 0; int partsize = files.size() / MAXFILESPERTHREAD; int offset = 0; if (partsize < 100) { partsize = files.size(); } ExecutorService exec = Executors.newFixedThreadPool(this.numthreads); do { List<String> subset = files.subList(offset, offset + partsize); exec.execute(new SCP(subset, this.remotePath)); p++; if (p == numthreads) { try { exec.awaitTermination(timeout, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { e.printStackTrace(); } p = 0; } offset += partsize; } while (offset < files.size()); if (p > 0) { try { exec.awaitTermination(timeout, TimeUnit.MILLISECONDS); exec.shutdown(); } catch (InterruptedException e) { e.printStackTrace(); } } }
From source file:org.ncic.bioinfo.sparkseq.algorithms.utils.MathUtils.java
/** * Returns n random indices drawn without replacement from the range 0..(k-1) * * @param n the total number of indices sampled from * @param k the number of random indices to draw (without replacement) * @return a list of k random indices ranging from 0 to (n-1) without duplicates *//* w w w .j a va 2s . c o m*/ static public ArrayList<Integer> sampleIndicesWithoutReplacement(final int n, final int k) { ArrayList<Integer> chosen_balls = new ArrayList<Integer>(k); for (int i = 0; i < n; i++) { chosen_balls.add(i); } Collections.shuffle(chosen_balls, RandomGenerator.getRandomGenerator()); //return (ArrayList<Integer>) chosen_balls.subList(0, k); return new ArrayList<Integer>(chosen_balls.subList(0, k)); }
From source file:org.broadinstitute.gatk.utils.MathUtils.java
/** * Returns n random indices drawn without replacement from the range 0..(k-1) * * @param n the total number of indices sampled from * @param k the number of random indices to draw (without replacement) * @return a list of k random indices ranging from 0 to (n-1) without duplicates */// ww w . j ava 2 s . c om static public ArrayList<Integer> sampleIndicesWithoutReplacement(final int n, final int k) { ArrayList<Integer> chosen_balls = new ArrayList<Integer>(k); for (int i = 0; i < n; i++) { chosen_balls.add(i); } Collections.shuffle(chosen_balls, Utils.getRandomGenerator()); //return (ArrayList<Integer>) chosen_balls.subList(0, k); return new ArrayList<Integer>(chosen_balls.subList(0, k)); }
From source file:com.example.lijingjiang.mobile_sensor_display.SimplePedometerActivity.java
public double[] SleepEfficiency(ArrayList<Integer> sleep, double targetRating) { int LF = 0;// ww w . j av a2 s .c om int HF = 0; int window = 60; int index = 0; while (index + window < sleep.size()) { List<Integer> subSleep = sleep.subList(index, index + window); if (Collections.max(subSleep) - Collections.min(subSleep) < 9) { LF++; } else { HF++; } index = index + window; } List<Integer> subSleep = sleep.subList(index, sleep.size() - 1); if (Collections.max(subSleep) - Collections.min(subSleep) < 9) { LF++; } else { HF++; } double data[] = new double[2]; data[0] = LF / HF; //rating data[1] = 1 - (Math.abs(targetRating - data[0]) / data[0]); //efficiency return data; }
From source file:in.ac.iitb.cse.cartsbusboarding.acc.FeatureCalculator.java
/** * Calculates Standard Deviation on windows of currentBuffer * * @param windowSize/*from w w w . jav a2 s . c o m*/ * @return array of std on currentBuffer data divided into windows */ public double[] getStd(int windowSize) { ArrayList data = new ArrayList(mCurrentBuffer); int noOfWindows = data.size() / windowSize; double[] windowStd = new double[noOfWindows + 1]; int index = 0; int startIndex = 0; int endIndex = 0; /*Loop will only read upto windows in multiples of windowSize(Last window with values less than windowSize is delt in next if condition) */ LOGV(TAG, "STD ARRAY: "); while (endIndex < (noOfWindows * windowSize)) { startIndex = endIndex; endIndex += windowSize; ArrayList<AccData> temp = new ArrayList(data.subList(startIndex, endIndex)); windowStd[index++] = getStd(temp); LOGV(TAG, "std" + (index - 1) + " " + windowStd[index - 1]); } if (endIndex < data.size()) { startIndex = endIndex; ArrayList<AccData> temp = new ArrayList(data.subList(startIndex, data.size())); windowStd[index] = getStd(temp); LOGV(TAG, "std" + (index) + " " + windowStd[index]); } return windowStd; }
From source file:in.ac.iitb.cse.cartsbusboarding.acc.FeatureCalculator.java
/** * Calculates mean on windows of currentBuffer * * @param windowSize/*ww w . jav a 2 s . co m*/ * @return array of means on currentBuffer data divided into windows */ public double[] getMean(int windowSize) { ArrayList data = new ArrayList(mCurrentBuffer); int noOfWindows = data.size() / windowSize; double[] windowMeans = new double[noOfWindows + 1]; int index = 0; int startIndex = 0; int endIndex = 0; /*Loop will only read upto windows in multiples of windowSize(Last window with values less than windowSize is delt in next if condition) */ LOGV(TAG, "MEAN ARRAY: "); while (endIndex < (noOfWindows * windowSize)) { startIndex = endIndex; endIndex += windowSize; ArrayList<AccData> temp = new ArrayList(data.subList(startIndex, endIndex)); windowMeans[index++] = getMean(temp); LOGV(TAG, "mean" + (index - 1) + " " + windowMeans[index - 1]); } if (endIndex < data.size()) { startIndex = endIndex; ArrayList<AccData> temp = new ArrayList(data.subList(startIndex, data.size())); windowMeans[index] = getMean(temp); LOGV(TAG, "mean" + (index) + " " + windowMeans[index]); } return windowMeans; }
From source file:in.ac.iitb.cse.cartsbusboarding.acc.FeatureCalculator.java
/** * finds dcComponent for windows of currentBuffer * * @param windowSize/* w w w . j av a 2 s. c o m*/ * @return array of dcComp on currentBuffer data divided into windows */ public double[] getDCComponent(int windowSize) { ArrayList data = new ArrayList(mCurrentBuffer); int noOfWindows = data.size() / windowSize; double[] windowdc = new double[noOfWindows + 1]; int index = 0; int startIndex = 0; int endIndex = 0; /*Loop will only read upto windows in multiples of windowSize(Last window with values less than windowSize is delt in next if condition) */ LOGV(TAG, "DC Comp. ARRAY: "); while (endIndex < (noOfWindows * windowSize)) { startIndex = endIndex; endIndex += windowSize; ArrayList<AccData> temp = new ArrayList(data.subList(startIndex, endIndex)); windowdc[index++] = getDCComponent(temp); LOGV(TAG, "dc comp" + (index - 1) + " " + windowdc[index - 1]); } if (endIndex < data.size()) { startIndex = endIndex; ArrayList<AccData> temp = new ArrayList(data.subList(startIndex, data.size())); windowdc[index] = getDCComponent(temp); LOGV(TAG, "dc comp" + (index) + " " + windowdc[index]); } return windowdc; }
From source file:in.ac.iitb.cse.cartsbusboarding.acc.FeatureCalculator.java
/** * finds energy for windows of currentBuffer * * @param windowSize/*from w ww. j a v a 2 s . c o m*/ * @return array of energy on currentBuffer data divided into windows */ public double[] getEnergy(int windowSize) { ArrayList data = new ArrayList(mCurrentBuffer); int noOfWindows = data.size() / windowSize; double[] windowEnergy = new double[noOfWindows + 1]; int index = 0; int startIndex = 0; int endIndex = 0; /*Loop will only read upto windows in multiples of windowSize(Last window with values less than windowSize is delt in next if condition) */ LOGV(TAG, "ENERGY ARRAY: "); while (endIndex < (noOfWindows * windowSize)) { startIndex = endIndex; endIndex += windowSize; ArrayList<AccData> temp = new ArrayList(data.subList(startIndex, endIndex)); windowEnergy[index++] = getEnergy(temp); LOGV(TAG, "energy" + (index - 1) + " " + windowEnergy[index - 1]); } if (endIndex < data.size()) { startIndex = endIndex; ArrayList<AccData> temp = new ArrayList(data.subList(startIndex, data.size())); windowEnergy[index] = getEnergy(temp); LOGV(TAG, "energy" + (index) + " " + windowEnergy[index]); } return windowEnergy; }
From source file:com.hygenics.parser.Mapper.java
/** * Run the Mapper./*from w ww .java 2 s. c om*/ * */ public void run() { log.info("Starting Mapping @ " + Calendar.getInstance().getTime().toString()); log.info("Table Preparation"); String[] tarr = table.split("\\."); if (!this.template.checkSchema(tarr[0])) { this.template.execute("CREATE SCHEMA IF NOT EXISTS " + tarr[0]); } this.template.execute("DROP TABLE IF EXISTS " + table + " CASCADE"); if (!this.template.checkTable(table, tarr[0])) { String sql = "CREATE TABLE IF NOT EXISTS " + table + "(" + hashCol + " text, date TIMESTAMP default now()"; if (!hashCol.equals(mapCol)) { sql += ", " + mapCol + " text"; } if (pathName != null) { sql += ", " + pathName + " text"; } sql += ")"; this.template.execute(sql); } log.info("Getting Data"); ArrayList<String> jsons = this.template.getJsonData(select); log.info("Mapping"); FileOps fops = new FileOps(); ArrayList<String> arr = fops.getLinkedDirectoryIntersection(matches, directory, jsons, hashCol, mapCol, replacementPattern, recursive, table, pathName, delFiles); log.info("Sending to DB"); if (arr.size() > 0) { int start = 0; int end = commitSize * qnum; while (start <= arr.size()) { if (start < arr.size()) { if (end > arr.size()) { end = arr.size(); } this.sendToDb(arr.subList(start, end), true); start += commitSize * qnum; end += commitSize * qnum; } } } log.info("Finished Mapping @ " + Calendar.getInstance().getTime().toString()); }