List of usage examples for java.util ArrayList clear
public void clear()
From source file:com.vicmns.demoinboxlikefab.BaseItemAnimator.java
@Override public void runPendingAnimations() { boolean removalsPending = !mPendingRemovals.isEmpty(); boolean movesPending = !mPendingMoves.isEmpty(); boolean additionsPending = !mPendingAdditions.isEmpty(); boolean changesPending = !mPendingChanges.isEmpty(); if (!removalsPending && !movesPending && !additionsPending && !changesPending) { // nothing to animate return;/* w w w .java 2s. c o m*/ } // First, remove stuff for (RecyclerView.ViewHolder holder : mPendingRemovals) { animateRemoveImpl(holder); } mPendingRemovals.clear(); // Next, move stuff if (movesPending) { mMoves.addAll(mPendingMoves); mPendingMoves.clear(); Runnable mover = new Runnable() { @Override public void run() { for (MoveInfo moveInfo : mMoves) { animateMoveImpl(moveInfo.holder, moveInfo.fromX, moveInfo.fromY, moveInfo.toX, moveInfo.toY); } mMoves.clear(); } }; if (removalsPending) { View view = mMoves.get(0).holder.itemView; ViewCompat.postOnAnimationDelayed(view, mover, getRemoveDuration()); } else { mover.run(); } } // Next, change stuff, to run in parallel with move animations if (changesPending) { final ArrayList<ChangeInfo> changes = new ArrayList<ChangeInfo>(); changes.addAll(mPendingChanges); mChangesList.add(changes); mPendingChanges.clear(); Runnable changer = new Runnable() { @Override public void run() { for (ChangeInfo change : changes) { animateChangeImpl(change); } changes.clear(); mChangesList.remove(changes); } }; if (removalsPending) { RecyclerView.ViewHolder holder = changes.get(0).oldHolder; ViewCompat.postOnAnimationDelayed(holder.itemView, changer, getRemoveDuration()); } else { changer.run(); } } // Next, add stuff if (additionsPending) { mAdditions.addAll(mPendingAdditions); mPendingAdditions.clear(); Runnable adder = new Runnable() { public void run() { for (RecyclerView.ViewHolder holder : mAdditions) { animateAddImpl(holder); } mAdditions.clear(); } }; if (removalsPending || movesPending) { View view = mAdditions.get(0).itemView; ViewCompat.postOnAnimationDelayed(view, adder, (removalsPending ? getRemoveDuration() : 0) + (movesPending ? getMoveDuration() : 0)); } else { adder.run(); } } }
From source file:com.caju.uheer.app.services.infrastructure.ContactablesLoaderCallbacks.java
@Override public void onLoadFinished(Loader<Cursor> arg0, Cursor cursor) { final ArrayList<String> infoAndName = new ArrayList<String>(); try {/* ww w.j a v a2s . c o m*/ for (int i = 0; i < usersFound.length(); i++) { infoAndName.add(usersFound.getJSONObject(i).getString("name")); } } catch (JSONException e) { e.printStackTrace(); } LocationManager locationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE); LocationListener locationListener = new LocationListener() { @Override public void onLocationChanged(Location location) { Location geoPointLocation = new Location("geoPoint"); try { infoAndName.clear(); for (int i = 0; i < usersFound.length(); i++) { String appendedText = ""; if (!usersFound.getJSONObject(i).has("channel")) { geoPointLocation.setLongitude(usersFound.getJSONObject(i).getDouble("lon")); geoPointLocation.setLatitude(usersFound.getJSONObject(i).getDouble("lat")); float distance = location.distanceTo(geoPointLocation) / 1000; appendedText = String.format("%.1f", distance) + "Km"; } else { appendedText = usersFound.getJSONObject(i).getString("channel"); } infoAndName.add(appendedText + usersFound.getJSONObject(i).getString("name")); Log.e("infoandname", infoAndName.toString() + infoAndName.get(0) + infoAndName.get(1)); Toast.makeText(mContext, infoAndName.toString() + infoAndName.get(0) + infoAndName.get(1), Toast.LENGTH_LONG).show(); // infoAndName tem a informacao de distancia ou canal e o nome. Precisa editar //essa parte de baixo pra usar o infoAndName. ArrayList<String> friendsEmails = new ArrayList<>(); friendsEmails.addAll(infoAndName); friendsEmails = new ArrayList<>(); for (ArrayList<String> array : ServerInformation.getAllActiveListeners()) { friendsEmails.addAll(array); while (friendsEmails.contains(connectedEmail)) friendsEmails.remove(connectedEmail); } EmailListAdapter listAdapter = new EmailListAdapter(mContext, R.layout.adapter_email_list, friendsEmails); ListView emails = (ListView) ((Activity) mContext) .findViewById(R.id.gps_friends_from_drawer); emails.setAdapter(listAdapter); } } catch (JSONException e) { e.printStackTrace(); } } @Override public void onStatusChanged(String provider, int status, Bundle extras) { } @Override public void onProviderEnabled(String provider) { } @Override public void onProviderDisabled(String provider) { } }; // Minimum of 2 minutes between checks (120000 milisecs). locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 120000, 0, locationListener); }
From source file:com.gs.jrpip.client.ThankYouWriter.java
@Override public void run() { ArrayList<CoalesceThankYouNotesKey> urlsToSend = new ArrayList<CoalesceThankYouNotesKey>(6); while (!this.done) { try {/*from w w w . j av a2 s.c om*/ synchronized (this) { if (this.requestMap.isEmpty()) { this.wait(); } } Thread.sleep(SLEEP_TIME); this.getUrlsToSend(urlsToSend); for (int i = 0; i < urlsToSend.size(); i++) { CoalesceThankYouNotesKey key = urlsToSend.get(i); if (!this.done) { this.sendThankYouRequest(key); } } urlsToSend.clear(); } catch (InterruptedException e) { // ok, nothing to do } catch (Throwable t) { // this is impossible, but let's not take any chances. LOGGER.error("Unexpected exception", t); } } }
From source file:gdsc.smlm.results.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.j a va 2 s . c o 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) { dThreshold *= dThreshold; // We will use the squared distance final int predictedPointsLength = (predictedPoints != null) ? predictedPoints.length : 0; final int actualPointsLength = (actualPoints != null) ? actualPoints.length : 0; 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; 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 boolean[] resultAssignment = new boolean[predictedPointsLength]; boolean[] roiAssignment = new boolean[fn]; ArrayList<Assignment> assignments = new ArrayList<Assignment>(predictedPointsLength); int[] falsePositives = null, falseNegatives = null; if (FP != null) { falsePositives = ascendingArray(predictedPointsLength); } if (FN != null) { falseNegatives = ascendingArray(actualPointsLength); } // Pre-calculate all-vs-all distance matrix if it can fit in memory int size = predictedPointsLength * actualPointsLength; float[][] dMatrix = null; if (size < 200 * 200) { dMatrix = new float[predictedPointsLength][actualPointsLength]; for (int predictedId = predictedPointsLength; predictedId-- > 0;) { float x = predictedPoints[predictedId].getX(); float y = predictedPoints[predictedId].getY(); float z = predictedPoints[predictedId].getZ(); for (int actualId = actualPointsLength; actualId-- > 0;) { double d2 = actualPoints[actualId].distance2(x, y, z); dMatrix[predictedId][actualId] = (float) d2; } } } 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 if (dMatrix != null) { if (dMatrix[predictedId][actualId] <= d2Min) { d2Min = dMatrix[predictedId][actualId]; targetId = actualId; } } else { 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 Assignment(targetId, predictedId, d2Min)); } } // If there are assignments if (!assignments.isEmpty()) { // Pick the closest pair to be assigned Collections.sort(assignments); // Process in order for (Assignment 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); }
From source file:io.apptik.multiview.animators.BaseItemAnimator.java
@Override public void runPendingAnimations() { boolean removalsPending = !mPendingRemovals.isEmpty(); boolean movesPending = !mPendingMoves.isEmpty(); boolean changesPending = !mPendingChanges.isEmpty(); boolean additionsPending = !mPendingAdditions.isEmpty(); if (!removalsPending && !movesPending && !additionsPending && !changesPending) { // nothing to animate return;//from ww w.j a v a 2s .com } // First, remove stuff for (ViewHolder holder : mPendingRemovals) { animateRemoveImpl(holder); } mPendingRemovals.clear(); // Next, move stuff if (movesPending) { final ArrayList<MoveInfo> moves = new ArrayList<MoveInfo>(); moves.addAll(mPendingMoves); mMovesList.add(moves); mPendingMoves.clear(); Runnable mover = new Runnable() { @Override public void run() { for (MoveInfo moveInfo : moves) { animateMoveImpl(moveInfo.holder, moveInfo); } moves.clear(); mMovesList.remove(moves); } }; if (removalsPending) { View view = moves.get(0).holder.itemView; ViewCompat.postOnAnimationDelayed(view, mover, getRemoveDuration()); } else { mover.run(); } } // Next, change stuff, to run in parallel with move animations if (changesPending) { final ArrayList<ChangeInfo> changes = new ArrayList<ChangeInfo>(); changes.addAll(mPendingChanges); mChangesList.add(changes); mPendingChanges.clear(); Runnable changer = new Runnable() { @Override public void run() { for (ChangeInfo change : changes) { animateChangeImpl(change); } changes.clear(); mChangesList.remove(changes); } }; if (removalsPending) { ViewHolder holder = changes.get(0).oldHolder; ViewCompat.postOnAnimationDelayed(holder.itemView, changer, getRemoveDuration()); } else { changer.run(); } } // Next, add stuff if (additionsPending) { final ArrayList<ViewHolder> additions = new ArrayList<ViewHolder>(); additions.addAll(mPendingAdditions); mAdditionsList.add(additions); mPendingAdditions.clear(); Runnable adder = new Runnable() { public void run() { for (ViewHolder holder : additions) { animateAddImpl(holder); } additions.clear(); mAdditionsList.remove(additions); } }; if (removalsPending || movesPending || changesPending) { long removeDuration = removalsPending ? getRemoveDuration() : 0; long moveDuration = movesPending ? getMoveDuration() : 0; long changeDuration = changesPending ? getChangeDuration() : 0; long totalDelay = removeDuration + Math.max(moveDuration, changeDuration); View view = additions.get(0).itemView; ViewCompat.postOnAnimationDelayed(view, adder, totalDelay); } else { adder.run(); } } }
From source file:com.yoctopuce.YoctoAPI.YTemperature.java
/** * Retrieves the thermistor response table previously configured using the * set_thermistorResponseTable function. This function can only be used with a * temperature sensor based on thermistors. * * @param tempValues : array of floating point numbers, that is filled by the function * with all temperatures (in degrees Celcius) for which the resistance * of the thermistor is specified. * @param resValues : array of floating point numbers, that is filled by the function * with the value (in Ohms) for each of the temperature included in the * first argument, index by index. * * @return YAPI.SUCCESS if the call succeeds. * * @throws YAPI_Exception on error//from www . jav a 2s . com */ public int loadThermistorResponseTable(ArrayList<Double> tempValues, ArrayList<Double> resValues) throws YAPI_Exception { String id; byte[] bin_json; ArrayList<String> paramlist = new ArrayList<String>(); ArrayList<Double> templist = new ArrayList<Double>(); int siz; int idx; double temp; int found; double prev; double curr; double currRes; tempValues.clear(); resValues.clear(); // may throw an exception id = get_functionId(); id = (id).substring(11, 11 + (id).length() - 11); bin_json = _download(String.format("extra.json?page=%s", id)); paramlist = _json_get_array(bin_json); // first convert all temperatures to float siz = ((paramlist.size()) >> (1)); templist.clear(); idx = 0; while (idx < siz) { temp = Double.valueOf(paramlist.get(2 * idx + 1)) / 1000.0; templist.add(temp); idx = idx + 1; } // then add records in growing temperature value tempValues.clear(); resValues.clear(); found = 1; prev = -999999.0; while (found > 0) { found = 0; curr = 999999.0; currRes = -999999.0; idx = 0; while (idx < siz) { temp = templist.get(idx).doubleValue(); if ((temp > prev) && (temp < curr)) { curr = temp; currRes = Double.valueOf(paramlist.get(2 * idx)) / 1000.0; found = 1; } idx = idx + 1; } if (found > 0) { tempValues.add(curr); resValues.add(currRes); prev = curr; } } return YAPI.SUCCESS; }
From source file:com.hippo.nimingban.itemanimator.FloatItemAnimator.java
@Override public void runPendingAnimations() { if (!mPendingAdditions.isEmpty()) { final ArrayList<RecyclerView.ViewHolder> additions = new ArrayList<>(); additions.addAll(mPendingAdditions); mAdditionsList.add(additions);/*from w w w. ja va 2s .c om*/ mPendingAdditions.clear(); Runnable adder = new Runnable() { @Override public void run() { float translationY = 0; int height = mRecyclerView.getHeight(); for (RecyclerView.ViewHolder holder : additions) { final View view = holder.itemView; translationY = Math.max(translationY, height - view.getX()); } for (RecyclerView.ViewHolder holder : additions) { animateAddImpl(holder, translationY); } additions.clear(); mAdditionsList.remove(additions); } }; adder.run(); } }
From source file:it.cnr.icar.eric.server.cms.CMSManagerImpl.java
/** * * Gets the Associations that have the specified assocType and have * as targetObject the ClassificationNode pointed to by objectType * or an ancestor of the ClassificationNode pointed to by * objectType.//from www.j a va 2 s. c o m * */ private List<IdentifiableType> getAssociations(ServerRequestContext context, String objectType, String assocType) throws RegistryException { List<IdentifiableType> associations = new ArrayList<IdentifiableType>(); try { RegistryObjectType ro = pm.getRegistryObject(context, objectType, "ClassificationNode"); ResponseOptionType ebResponseOptionType = bu.queryFac.createResponseOptionType(); ebResponseOptionType.setReturnType(ReturnType.LEAF_CLASS); ebResponseOptionType.setReturnComposedObjects(false); ArrayList<Object> objectRefs = new ArrayList<Object>(); if ((ro != null) && (ro instanceof ClassificationNodeType)) { ClassificationNodeType node = (ClassificationNodeType) ro; String query = "SELECT ass.* from Association ass " + " WHERE ass.targetObject = '" + node.getId() + "' AND ass.associationType = '" + assocType + "' "; objectRefs.clear(); associations = pm.executeSQLQuery(context, query, ebResponseOptionType, "Association", objectRefs); //TODO: Fix following design bug... //If there is a CatalogingService defined at //sub-class of XML (e.g. CPP) level then it will //not look at XML level even for a different type //of service such as FilteringService. //Base class lookup should be done if no service //is found for a specific type of CMS service. if (associations.size() == 0) { //Check if an Association exists for the parent node Object parent = node.getParent(); if ((parent != null)) { String parentId = bu.getObjectId(parent); associations = getAssociations(context, parentId, assocType); } } } } catch (JAXRException e) { throw new RegistryException(e); } return associations; }
From source file:org.apache.hadoop.hbase.TestPartialResultsFromClientSide.java
public void testPartialResultsReassembly(Scan scanBase) throws Exception { Scan partialScan = new Scan(scanBase); partialScan.setMaxResultSize(1);//www . j av a 2s.c o m partialScan.setAllowPartialResults(true); ResultScanner partialScanner = TABLE.getScanner(partialScan); Scan oneShotScan = new Scan(scanBase); oneShotScan.setMaxResultSize(Long.MAX_VALUE); ResultScanner oneShotScanner = TABLE.getScanner(oneShotScan); ArrayList<Result> partials = new ArrayList<>(); for (int i = 0; i < NUM_ROWS; i++) { Result partialResult = null; Result completeResult = null; Result oneShotResult = null; partials.clear(); do { partialResult = partialScanner.next(); partials.add(partialResult); } while (partialResult != null && partialResult.isPartial()); completeResult = Result.createCompleteResult(partials); oneShotResult = oneShotScanner.next(); compareResults(completeResult, oneShotResult, null); } assertTrue(oneShotScanner.next() == null); assertTrue(partialScanner.next() == null); oneShotScanner.close(); partialScanner.close(); }
From source file:com.chinamobile.bcbsp.comm.ProducerTool.java
/** * Send message into messageQueue and update information. * @param session/*from w ww .j ava 2s . c o m*/ * @param producer * @throws Exception * e */ private void sendLoop(final Session session, final MessageProducer producer) throws Exception { IMessage msg; int count = 0; BSPMessagesPack pack = new BSPMessagesPack(); ArrayList<IMessage> content = new ArrayList<IMessage>(); while ((msg = messageQueue.poll()) != null) { content.add(msg); count++; this.messageCount++; // enough for a pack. if (count == this.packSize) { pack.setPack(content); long start = System.currentTimeMillis(); /** Clock */ ObjectMessage message = session.createObjectMessage(pack); producer.send(message); this.sendTime += (System.currentTimeMillis() - start); /** Clock */ content.clear(); count = 0; } } // remaining messages into a pack. if (content.size() > 0) { pack.setPack(content); long start = System.currentTimeMillis(); /* Clock */ ObjectMessage message = session.createObjectMessage(pack); producer.send(message); this.sendTime += (System.currentTimeMillis() - start); /* Clock */ content.clear(); } }