List of usage examples for java.util ArrayList clear
public void clear()
From source file:org.opendatakit.database.data.ColumnDefinition.java
/** * This must match the code in the javascript layer * <p>//from w w w.j av a 2 s .c o m * See databaseUtils.markUnitOfRetention * <p> * Sweeps through the collection of ColumnDefinition objects and marks the * ones that exist in the actual database table. * * @param defn the map of column definitions to mark */ private static void markUnitOfRetention(Map<String, ColumnDefinition> defn) { // for all arrays, mark all descendants of the array as not-retained // because they are all folded up into the json representation of the array for (Map.Entry<String, ColumnDefinition> stringColumnDefinitionEntry : defn.entrySet()) { ColumnDefinition colDefn = stringColumnDefinitionEntry.getValue(); if (!colDefn.isUnitOfRetention()) { // this has already been processed continue; } ElementType type = colDefn.getType(); if (ElementDataType.array == type.getDataType()) { ArrayList<ColumnDefinition> descendantsOfArray = new ArrayList<>(colDefn.getChildren()); ArrayList<ColumnDefinition> scratchArray = new ArrayList<>(); while (true) { for (ColumnDefinition subDefn : descendantsOfArray) { if (!subDefn.isUnitOfRetention()) { // this has already been processed continue; } subDefn.setNotUnitOfRetention(); scratchArray.addAll(subDefn.getChildren()); } descendantsOfArray.clear(); descendantsOfArray.addAll(scratchArray); scratchArray.clear(); if (descendantsOfArray.isEmpty()) { break; } } } } // and mark any non-arrays with multiple fields as not retained for (Map.Entry<String, ColumnDefinition> stringColumnDefinitionEntry : defn.entrySet()) { ColumnDefinition colDefn = stringColumnDefinitionEntry.getValue(); if (!colDefn.isUnitOfRetention()) { // this has already been processed continue; } ElementType type = colDefn.getType(); if (ElementDataType.array != type.getDataType()) { if (!colDefn.getChildren().isEmpty()) { colDefn.setNotUnitOfRetention(); } } } }
From source file:eulermind.importer.LineNode.java
private static LineNode tooManySiblingsToSubTree(LineNode root) { if (root.getChildCount() == 0) { return root; }/*from w w w . jav a2s . com*/ ArrayList<LineNode> children = new ArrayList<LineNode>(); moveChildrenToList(root, children); ArrayList<LineNode> newParents = new ArrayList<LineNode>(); // ???? while (children.size() > MAX_CHILD_COUNT) { for (int i = 0; i < children.size(); i++) { if (i / MAX_CHILD_COUNT >= newParents.size()) { int childBlankLines = children.get(i).m_blankLines; newParents.add(new LineNode(childBlankLines > 0 ? childBlankLines : 1)); } newParents.get(newParents.size() - 1).add(children.get(i)); } children.clear(); ArrayList<LineNode> tmp = children; children = newParents; newParents = tmp; } for (LineNode child : children) { root.add(tooManySiblingsToSubTree(child)); } return root; }
From source file:com.globalsight.everest.webapp.pagehandler.projects.workflows.WorkflowHandlerHelper.java
public static Map<File, String> getEntryFileToFileNameMap(Set<File> entryFiles, Set<Long> jobIdSet, Set<String> locales, String cxeDocsDirPath) { Map<File, String> entryFileToFileNameMap = new HashMap<File, String>(); File tempFile;/* www . ja v a 2s . c om*/ for (Long jobId : jobIdSet) { ArrayList<String> entryNames = new ArrayList<String>(); for (String locale : locales) { entryNames.clear(); String prefixStr1 = cxeDocsDirPath + File.separator + jobId + File.separator + locale; for (File entryFile : entryFiles) { String entryFilePath = entryFile.getPath(); if (entryFilePath.startsWith(prefixStr1)) { entryNames.add(entryFilePath.replaceAll("\\\\", "/")); } } if (entryNames.size() > 0) { Map<String, String> tempMap = ZipIt.getEntryNamesMap(entryNames); for (String key : tempMap.keySet()) { tempFile = new File(key); entryFileToFileNameMap.put(tempFile, locale + File.separator + jobId + File.separator + tempMap.get(key)); } } } } return entryFileToFileNameMap; }
From source file:cz.pichlik.goodsentiment.common.CSVReader.java
public void readLines(RowProcessor processor) { ArrayList<String> val = new ArrayList<>(); AtomicInteger counter = new AtomicInteger(0); csvParser.forEach((r) -> {//from w w w . j a v a 2s .c om try { r.forEach((s) -> val.add(s)); processor.accept(val, counter.getAndIncrement()); } finally { val.clear(); } }); }
From source file:com.example.avjindersinghsekhon.minimaltodo.TestStoreRetrieveData.java
@Override protected void setUp() throws Exception { super.setUp(); mMainActivity = getActivity();// w ww . j ava 2s .c om mOriginalData = new ArrayList<>(); // Save the original data and wipe out the storage StoreRetrieveData dataStorage = getDataStorage(); try { ArrayList<ToDoItem> items = dataStorage.loadFromFile(); if (items.size() > 0) { mOriginalData.clear(); mOriginalData.addAll(items); items.clear(); dataStorage.saveToFile(items); } } catch (Exception e) { fail("Couldn't store data: " + e.getMessage()); } }
From source file:com.microsoft.live.sample.hotmail.ContactsActivity.java
private void loadContacts() { final ProgressDialog progDialog = ProgressDialog.show(this, "", "Loading. Please wait...", true); mClient.getAsync("me/contacts", new LiveOperationListener() { @Override/*from w w w. ja v a2s. c o m*/ public void onError(LiveOperationException exception, LiveOperation operation) { progDialog.dismiss(); showToast(exception.getMessage()); } @Override public void onComplete(LiveOperation operation) { progDialog.dismiss(); JSONObject result = operation.getResult(); if (result.has(JsonKeys.ERROR)) { JSONObject error = result.optJSONObject(JsonKeys.ERROR); String message = error.optString(JsonKeys.MESSAGE); String code = error.optString(JsonKeys.CODE); showToast(code + ": " + message); return; } ArrayList<Contact> contacts = mAdapter.getContacts(); contacts.clear(); JSONArray data = result.optJSONArray(JsonKeys.DATA); for (int i = 0; i < data.length(); i++) { Contact contact = new Contact(data.optJSONObject(i)); contacts.add(contact); } mAdapter.notifyDataSetChanged(); } }); }
From source file:cn.kavelcortex.bookpriceculculator.TotalPrice.java
private void setList(ArrayList<Map<String, Object>> toList, int itemCount) { if (!toList.isEmpty()) toList.clear(); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); for (int i = 0; i < itemCount; i++) { Map<String, Object> map = new HashMap<>(); String stringValue = preferences.getString(BOOK_SERIAL + i, "0.0"); BigDecimal price = new BigDecimal(stringValue); map.put(BOOK_SERIAL, i);// w w w. ja v a2 s . c o m map.put(BOOK_TITLE, "" + (i + 1)); map.put(BOOK_PRICE, price); toList.add(i, map); } }
From source file:com.onpositive.semantic.wikipedia.abstracts.svc.HtmlRendererBase.java
private void printPart(String format, ArrayList<Object> a, int last, int i) { if (i - last > 0) { String f = format.substring(last, i); if (a.isEmpty()) { p.print(f);/*from ww w . ja v a 2 s . c o m*/ } else { p.print(String.format(f, a.toArray())); a.clear(); } } }
From source file:gdsc.core.match.MatchCalculator.java
/** * Calculate the match results for the given actual and predicted points. * Points that are within the distance threshold are identified as a match. * The number of true positives, false positives and false negatives are calculated. * //from w w w . ja va 2 s. co m * @param actualPoints * @param predictedPoints * @param dThreshold * The distance threshold * @param TP * True Positives * @param FP * False Positives * @param FN * False Negatives * @param matches * The matched true positives (point1 = actual, point2 = predicted) * @return The match results */ public static MatchResult analyseResults2D(Coordinate[] actualPoints, Coordinate[] predictedPoints, double dThreshold, List<Coordinate> TP, List<Coordinate> FP, List<Coordinate> FN, List<PointPair> matches) { final int predictedPointsLength = (predictedPoints != null) ? predictedPoints.length : 0; final int actualPointsLength = (actualPoints != null) ? actualPoints.length : 0; // If the number of possible pairs is small then use a one pass algorithm if (predictedPointsLength * actualPointsLength < 100000) return analyseResults2DSinglePass(actualPoints, predictedPoints, dThreshold, TP, FP, FN, matches); dThreshold *= dThreshold; // We will use the squared distance int tp = 0; // true positives (actual with matched predicted point) int fp = predictedPointsLength; // false positives (actual with no matched predicted point) int fn = actualPointsLength; // false negatives (predicted point with no actual point) double rmsd = 0; clear(TP, FP, FN, matches); if (predictedPointsLength == 0 || actualPointsLength == 0) { if (FP != null) FP.addAll(asList(predictedPoints)); if (FN != null) FN.addAll(asList(actualPoints)); return new MatchResult(tp, fp, fn, rmsd); } // loop over the two arrays assigning the closest unassigned pair final boolean[] resultAssignment = new boolean[predictedPointsLength]; final boolean[] roiAssignment = new boolean[fn]; final ArrayList<ImmutableAssignment> assignments = new ArrayList<ImmutableAssignment>( predictedPointsLength); int[] falsePositives = null, falseNegatives = null; if (FP != null) { falsePositives = ascendingArray(predictedPointsLength); } if (FN != null) { falseNegatives = ascendingArray(actualPointsLength); } do { assignments.clear(); // Process each result for (int predictedId = predictedPointsLength; predictedId-- > 0;) { if (resultAssignment[predictedId]) continue; // Already assigned final float x = predictedPoints[predictedId].getX(); final float y = predictedPoints[predictedId].getY(); // Find closest ROI point float d2Min = (float) dThreshold; //Float.MAX_VALUE; int targetId = -1; for (int actualId = actualPointsLength; actualId-- > 0;) { if (roiAssignment[actualId]) continue; // Already assigned Coordinate actualPoint = actualPoints[actualId]; // Calculate in steps for increased speed (allows early exit) float dx = actualPoint.getX() - x; dx *= dx; if (dx <= d2Min) { float dy = actualPoint.getY() - y; dy *= dy; if (dy <= d2Min) { final float d2 = dx + dy; if (d2 <= d2Min) { d2Min = d2; targetId = actualId; } } } } // Store closest ROI point if (targetId > -1) { assignments.add(new ImmutableAssignment(targetId, predictedId, d2Min)); } } // If there are assignments if (!assignments.isEmpty()) { // Pick the closest pair to be assigned AssignmentComparator.sort(assignments); // Process in order for (ImmutableAssignment closest : assignments) { // Skip those that have already been assigned since this will be a lower score. // Note at least one assignment should be processed as potential assignments are made // using only unassigned points. if (resultAssignment[closest.getPredictedId()] || roiAssignment[closest.getTargetId()]) continue; resultAssignment[closest.getPredictedId()] = true; roiAssignment[closest.getTargetId()] = true; // If within accuracy then classify as a match if (closest.getDistance() <= dThreshold) { tp++; fn--; fp--; rmsd += closest.getDistance(); // Already a squared distance if (TP != null) { TP.add(predictedPoints[closest.getPredictedId()]); } if (FP != null) { falsePositives[closest.getPredictedId()] = -1; } if (FN != null) { falseNegatives[closest.getTargetId()] = -1; } if (matches != null) matches.add(new PointPair(actualPoints[closest.getTargetId()], predictedPoints[closest.getPredictedId()])); } else { // No more assignments within the distance threshold break; } } } } while (!assignments.isEmpty()); // Add to lists if (FP != null) { for (int i = 0; i < predictedPointsLength; i++) { if (falsePositives[i] >= 0) FP.add(predictedPoints[i]); } } if (FN != null) { for (int i = 0; i < actualPointsLength; i++) { if (falseNegatives[i] >= 0) FN.add(actualPoints[i]); } } if (tp > 0) rmsd = Math.sqrt(rmsd / tp); return new MatchResult(tp, fp, fn, rmsd); }
From source file:gdsc.core.match.MatchCalculator.java
/** * Calculate the match results for the given actual and predicted points. * Points that are within the distance threshold are identified as a match. * The number of true positives, false positives and false negatives are calculated. * /*from w w w . jav a2 s. co m*/ * @param actualPoints * @param predictedPoints * @param dThreshold * The distance threshold * @param TP * True Positives * @param FP * False Positives * @param FN * False Negatives * @param matches * The matched true positives (point1 = actual, point2 = predicted) * @return The match results */ public static MatchResult analyseResults3D(Coordinate[] actualPoints, Coordinate[] predictedPoints, double dThreshold, List<Coordinate> TP, List<Coordinate> FP, List<Coordinate> FN, List<PointPair> matches) { final int predictedPointsLength = (predictedPoints != null) ? predictedPoints.length : 0; final int actualPointsLength = (actualPoints != null) ? actualPoints.length : 0; // If the number of possible pairs is small then use a one pass algorithm if (predictedPointsLength * actualPointsLength < 100000) return analyseResults3DSinglePass(actualPoints, predictedPoints, dThreshold, TP, FP, FN, matches); dThreshold *= dThreshold; // We will use the squared distance int tp = 0; // true positives (actual with matched predicted point) int fp = predictedPointsLength; // false positives (actual with no matched predicted point) int fn = actualPointsLength; // false negatives (predicted point with no actual point) double rmsd = 0; clear(TP, FP, FN, matches); if (predictedPointsLength == 0 || actualPointsLength == 0) { if (FP != null) FP.addAll(asList(predictedPoints)); if (FN != null) FN.addAll(asList(actualPoints)); return new MatchResult(tp, fp, fn, rmsd); } // loop over the two arrays assigning the closest unassigned pair final boolean[] resultAssignment = new boolean[predictedPointsLength]; final boolean[] roiAssignment = new boolean[fn]; final ArrayList<ImmutableAssignment> assignments = new ArrayList<ImmutableAssignment>( predictedPointsLength); int[] falsePositives = null, falseNegatives = null; if (FP != null) { falsePositives = ascendingArray(predictedPointsLength); } if (FN != null) { falseNegatives = ascendingArray(actualPointsLength); } do { assignments.clear(); // Process each result for (int predictedId = predictedPointsLength; predictedId-- > 0;) { if (resultAssignment[predictedId]) continue; // Already assigned final float x = predictedPoints[predictedId].getX(); final float y = predictedPoints[predictedId].getY(); final float z = predictedPoints[predictedId].getZ(); // Find closest ROI point float d2Min = (float) dThreshold; //Float.MAX_VALUE; int targetId = -1; for (int actualId = actualPointsLength; actualId-- > 0;) { if (roiAssignment[actualId]) continue; // Already assigned Coordinate actualPoint = actualPoints[actualId]; // Calculate in steps for increased speed (allows early exit) float dx = actualPoint.getX() - x; dx *= dx; if (dx <= d2Min) { float dy = actualPoint.getY() - y; dy *= dy; if (dy <= d2Min) { float dz = actualPoint.getZ() - z; dz *= dz; if (dz <= d2Min) { final float d2 = dx + dy + dz; if (d2 <= d2Min) { d2Min = d2; targetId = actualId; } } } } } // Store closest ROI point if (targetId > -1) { assignments.add(new ImmutableAssignment(targetId, predictedId, d2Min)); } } // If there are assignments if (!assignments.isEmpty()) { // Pick the closest pair to be assigned AssignmentComparator.sort(assignments); // Process in order for (ImmutableAssignment closest : assignments) { // Skip those that have already been assigned since this will be a lower score. // Note at least one assignment should be processed as potential assignments are made // using only unassigned points. if (resultAssignment[closest.getPredictedId()] || roiAssignment[closest.getTargetId()]) continue; resultAssignment[closest.getPredictedId()] = true; roiAssignment[closest.getTargetId()] = true; // If within accuracy then classify as a match if (closest.getDistance() <= dThreshold) { tp++; fn--; fp--; rmsd += closest.getDistance(); if (TP != null) { TP.add(predictedPoints[closest.getPredictedId()]); } if (FP != null) { falsePositives[closest.getPredictedId()] = -1; } if (FN != null) { falseNegatives[closest.getTargetId()] = -1; } if (matches != null) matches.add(new PointPair(actualPoints[closest.getTargetId()], predictedPoints[closest.getPredictedId()])); } else { // No more assignments within the distance threshold break; } } } } while (!assignments.isEmpty()); // Add to lists if (FP != null) { for (int i = 0; i < predictedPointsLength; i++) { if (falsePositives[i] >= 0) FP.add(predictedPoints[i]); } } if (FN != null) { for (int i = 0; i < actualPointsLength; i++) { if (falseNegatives[i] >= 0) FN.add(actualPoints[i]); } } if (tp > 0) rmsd = Math.sqrt(rmsd / tp); return new MatchResult(tp, fp, fn, rmsd); }