List of usage examples for java.util ArrayList clear
public void clear()
From source file:accumulo.balancer.GroupBalancer.java
private void balanceExtraExtra(Map<TServerInstance, TserverGroupInfo> tservers, int maxExtraGroups, Moves moves) {/* w ww .ja v a 2 s. c om*/ Table<String, TServerInstance, TserverGroupInfo> surplusExtra = HashBasedTable.create(); for (TserverGroupInfo tgi : tservers.values()) { Map<String, Integer> extras = tgi.getExtras(); if (extras.size() > maxExtraGroups) { for (String group : extras.keySet()) { surplusExtra.put(group, tgi.getTserverInstance(), tgi); } } } ArrayList<Pair<String, TServerInstance>> serversGroupsToRemove = new ArrayList<>(); ArrayList<TServerInstance> serversToRemove = new ArrayList<>(); for (TserverGroupInfo destTgi : tservers.values()) { if (surplusExtra.size() == 0) { break; } Map<String, Integer> extras = destTgi.getExtras(); if (extras.size() < maxExtraGroups) { serversToRemove.clear(); serversGroupsToRemove.clear(); for (String group : surplusExtra.rowKeySet()) { if (!extras.containsKey(group)) { TserverGroupInfo srcTgi = surplusExtra.row(group).values().iterator().next(); moves.move(group, 1, srcTgi, destTgi); if (srcTgi.getExtras().size() <= maxExtraGroups) { serversToRemove.add(srcTgi.getTserverInstance()); } else { serversGroupsToRemove .add(new Pair<String, TServerInstance>(group, srcTgi.getTserverInstance())); } if (destTgi.getExtras().size() >= maxExtraGroups || moves.size() >= getMaxMigrations()) { break; } } } if (serversToRemove.size() > 0) { surplusExtra.columnKeySet().removeAll(serversToRemove); } for (Pair<String, TServerInstance> pair : serversGroupsToRemove) { surplusExtra.remove(pair.getFirst(), pair.getSecond()); } if (moves.size() >= getMaxMigrations()) { break; } } } }
From source file:com.chaosinmotion.securechat.network.SCNetwork.java
/** * Iterate through all queued calls forcing them to be canceled *//*from w ww . j av a 2s. c o m*/ public void cancelRequestsWithCaller(Object caller) { ArrayList<Request> remove = new ArrayList<Request>(); for (Request req : callQueue) { if (req.caller == caller) { if (req.taskFuture != null) { req.taskFuture.cancel(true); } remove.add(req); if (req.waitFlag && ((req.caller instanceof WaitSpinner))) { ((WaitSpinner) req.caller).stopWaitSpinner(); req.waitFlag = false; } } } callQueue.removeAll(remove); remove.clear(); for (Request req : retryQueue) { if (req.caller == caller) { if (req.taskFuture != null) { req.taskFuture.cancel(true); } remove.add(req); if (req.waitFlag && ((req.caller instanceof WaitSpinner))) { ((WaitSpinner) req.caller).stopWaitSpinner(); req.waitFlag = false; } } } retryQueue.removeAll(remove); }
From source file:com.yoctopuce.YoctoAPI.YCellular.java
/** * Returns the list detected cell operators in the neighborhood. * This function will typically take between 30 seconds to 1 minute to * return. Note that any SIM card can usually only connect to specific * operators. All networks returned by this function might therefore * not be available for connection.// w w w. j a va 2s . co m * * @return a list of string (cell operator names). */ public ArrayList<String> get_availableOperators() throws YAPI_Exception { String cops; int idx; int slen; ArrayList<String> res = new ArrayList<String>(); // may throw an exception cops = _AT("+COPS=?"); slen = (cops).length(); res.clear(); idx = (cops).indexOf("("); while (idx >= 0) { slen = slen - (idx + 1); cops = (cops).substring(idx + 1, idx + 1 + slen); idx = (cops).indexOf("\""); if (idx > 0) { slen = slen - (idx + 1); cops = (cops).substring(idx + 1, idx + 1 + slen); idx = (cops).indexOf("\""); if (idx > 0) { res.add((cops).substring(0, 0 + idx)); } } idx = (cops).indexOf("("); } return res; }
From source file:geva.Operator.Operations.FullInitialiser.java
/** * Recursively builds a tree.//from w ww . jav a 2 s .c o m * @param dt Tree to grow on * @return If the tree is valid **/ @Override public boolean grow(NimbleTree<Symbol> dt) { Rule rule; Iterator<Production> prodIt; ArrayList<Integer> possibleRules = new ArrayList<Integer>(); boolean recursiveRules; Production prod; int prodVal; boolean result; int newMaxDepth; Iterator<Symbol> symIt; Symbol symbol; try { if (dt.getCurrentNode().getData().getType() == Enums.SymbolType.TSymbol) { //Check if it is for ADF if (dt.getCurrentNode().getData().getSymbolString().contains("BRR")) { this.extraCodons++; } return true; } if (dt.getCurrentLevel() > this.maxDepth) { logger.warn("Too deep:" + dt.getCurrentLevel() + ">" + this.maxDepth); return false; } rule = grammar.findRule(dt.getCurrentNode().getData()); if (rule != null) { prodIt = rule.iterator(); possibleRules.clear(); int ii = 0; recursiveRules = false; // System.out.print(rule.getLHS().getSymbolString()+" minD:"+rule.getMinimumDepth()+" maxD:"+maxDepth+" cD:"+dt.getCurrentLevel()); while (prodIt.hasNext()) { prod = prodIt.next(); if ((dt.getCurrentLevel() + prod.getMinimumDepth()) <= this.maxDepth) { if (!recursiveRules && prod.getRecursive()) { recursiveRules = true; possibleRules.clear(); //Only recursive rules allowed? What about non-recursive rules with the proper length?? } if (!recursiveRules || (recursiveRules && prod.getRecursive())) { possibleRules.add(ii); } } ii++; } // System.out.print(" \n"); if (possibleRules.isEmpty()) { logger.info("EmptyPossible rules:" + rule); return false; } else { prodVal = this.rng.nextInt(possibleRules.size()); int modVal = possibleRules.get(prodVal); int tmp1 = this.rng.nextInt((Integer.MAX_VALUE - rule.size())); int tmp; int mod = tmp1 % rule.size(); int diff; if (mod > modVal) { diff = mod - modVal; tmp = tmp1 - diff; } else { diff = modVal - mod; tmp = tmp1 + diff; } int newMod = tmp % rule.size(); if (newMod != modVal) { logger.info("modVal:" + modVal + " tmp1:" + tmp1 + " mod:" + mod + " tmp:" + tmp + " rule.size():" + rule.size() + " newMod:" + newMod); } if (rule.size() > 1) { this.chromosome.add(tmp); //correct choosing of production?? prod = rule.get(possibleRules.get(prodVal)); } else { // only one rule does not use a codon //this.chromosome.add(tmp); //correct choosing of production?? prod = rule.get(0); } } result = true; newMaxDepth = dt.getDepth(); symIt = prod.iterator(); while (symIt.hasNext() && result) { symbol = symIt.next(); dt.addChild(symbol); dt.setCurrentNode(dt.getCurrentNode().getEnd()); dt.setCurrentLevel(dt.getCurrentLevel() + 1); result = grow(dt); dt.setCurrentLevel(dt.getCurrentLevel() - 1); if (newMaxDepth < dt.getDepth()) { newMaxDepth = dt.getDepth(); } } chromosome.setValid(result); dt.setDepth(newMaxDepth); return result; } else { if (!checkGECodonValue(dt)) { throw new InitializationException("Non-existent rule, maybe GECODON not yet impelemnted"); } return true; } } catch (InitializationException e) { e.printStackTrace(); return false; } }
From source file:aloha.shiningstarbase.util.itemanimator.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;//w w w. j a v a 2 s .co m } // First, remove stuff for (RecyclerView.ViewHolder holder : mPendingRemovals) { animateRemoveImpl(holder); } mPendingRemovals.clear(); // Next, move stuff if (movesPending) { final ArrayList<MoveInfo> moves = new ArrayList<>(); moves.addAll(mPendingMoves); mMovesList.add(moves); mPendingMoves.clear(); Runnable mover = new Runnable() { @Override public void run() { for (MoveInfo moveInfo : moves) { animateMoveImpl(moveInfo.holder, moveInfo.fromX, moveInfo.fromY, moveInfo.toX, moveInfo.toY); } 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<>(); 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) { final ArrayList<RecyclerView.ViewHolder> additions = new ArrayList<>(); additions.addAll(mPendingAdditions); mAdditionsList.add(additions); mPendingAdditions.clear(); Runnable adder = new Runnable() { public void run() { for (RecyclerView.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:net.fenyo.gnetwatch.activities.MergeQueue.java
final void mergeEventsOfTarget(final Target target, final String event_type, final Long s, final EventGeneric ev_first) { if (ev_first == null) return;//from www . j a va 2 s . c om final org.hibernate.Query query = getGUI().getSynchro().getSessionFactory().getCurrentSession() .createQuery("from EventGeneric as ev " + "where ev.eventList = :event_list " + "and ev.date < :stop_date " + "and ev.merged != :s order by ev.date asc") .setString("event_list", target.getEventLists().get(event_type).getId().toString()).setLong("s", s) .setString("stop_date", ev_first.getDate().toString()); // log.debug("stop date : " + ev_first.getDate().toString()); final List<EventGeneric> results = query.list(); if (results.size() > 0) { EventGeneric prev_event = null; final ArrayList<EventGeneric> events = new ArrayList<EventGeneric>(); for (final EventGeneric event : results) { event.setMerged(s); if (prev_event != null) { if (event.getDate().getTime() - event.getDate().getTime() % (s * 1000) == prev_event.getDate().getTime() - prev_event.getDate().getTime() % (s * 1000)) { if (!events.contains(prev_event)) events.add(prev_event); if (!events.contains(event)) events.add(event); } else { if (events.size() > 0) mergeEventsChunk(events, new java.util.Date(events.get(0).getDate().getTime() - events.get(0).getDate().getTime() % (s * 1000) + s * 500)); events.clear(); events.add(event); } } prev_event = event; } if (events.size() > 0) mergeEventsChunk(events, new java.util.Date(events.get(0).getDate().getTime() - events.get(0).getDate().getTime() % (s * 1000) + s * 500)); events.clear(); } }
From source file:android.support.v7.widget.DefaultItemAnimatorEx.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 2 s . c om*/ } // 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.fromX, moveInfo.fromY, moveInfo.toX, moveInfo.toY); } 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.datatorrent.demos.wordcount.FileWordCount.java
private void getTopNMap(final Map<String, WCPair> map, List<Map<String, Object>> result) { final ArrayList<WCPair> list = new ArrayList<>(map.values()); // sort entries in descending order of frequency Collections.sort(list, new Comparator<WCPair>() { @Override//from w ww . jav a 2 s. co m public int compare(WCPair o1, WCPair o2) { return (int) (o2.freq - o1.freq); } }); if (topN > 0) { list.subList(topN, map.size()).clear(); // retain only the first topN entries } // convert each pair (word, freq) of list to a map with 2 elements // {("word": <word>, "count": freq)} and append to list // result.clear(); for (WCPair pair : list) { Map<String, Object> wmap = new HashMap<>(2); wmap.put("word", pair.word); wmap.put("count", pair.freq); result.add(wmap); } LOG.info("FileWordCount:getTopNMap: result.size = {}", result.size()); list.clear(); }
From source file:com.android.calendar.alerts.AlertService.java
/** * Redistributes events in the priority lists based on the max # of notifications we * can show./*from w w w . j av a 2 s . co m*/ */ static void redistributeBuckets(ArrayList<NotificationInfo> highPriorityEvents, ArrayList<NotificationInfo> mediumPriorityEvents, ArrayList<NotificationInfo> lowPriorityEvents, int maxNotifications) { // If too many high priority alerts, shift the remaining high priority and all the // medium priority ones to the low priority bucket. Note that order is important // here; these lists are sorted by descending start time. Maintain that ordering // so posted notifications are in the expected order. if (highPriorityEvents.size() > maxNotifications) { // Move mid-priority to the digest. lowPriorityEvents.addAll(0, mediumPriorityEvents); // Move the rest of the high priority ones (latest ones) to the digest. List<NotificationInfo> itemsToMoveSublist = highPriorityEvents.subList(0, highPriorityEvents.size() - maxNotifications); // TODO: What order for high priority in the digest? lowPriorityEvents.addAll(0, itemsToMoveSublist); if (DEBUG) { logEventIdsBumped(mediumPriorityEvents, itemsToMoveSublist); } mediumPriorityEvents.clear(); // Clearing the sublist view removes the items from the highPriorityEvents list. itemsToMoveSublist.clear(); } // Bump the medium priority events if necessary. if (mediumPriorityEvents.size() + highPriorityEvents.size() > maxNotifications) { int spaceRemaining = maxNotifications - highPriorityEvents.size(); // Reached our max, move the rest to the digest. Since these are concurrent // events, we move the ones with the earlier start time first since they are // further in the past and less important. List<NotificationInfo> itemsToMoveSublist = mediumPriorityEvents.subList(spaceRemaining, mediumPriorityEvents.size()); lowPriorityEvents.addAll(0, itemsToMoveSublist); if (DEBUG) { logEventIdsBumped(itemsToMoveSublist, null); } // Clearing the sublist view removes the items from the mediumPriorityEvents list. itemsToMoveSublist.clear(); } }
From source file:com.andrew67.ddrfinder.adapters.MapLoaderV1.java
@Override protected ApiResult doInBackground(LatLngBounds... boxes) { // Fetch machine data in JSON format JSONArray jArray = new JSONArray(); try {// ww w .j a va 2 s .c om if (boxes.length == 0) throw new IllegalArgumentException("No boxes passed to doInBackground"); final LatLngBounds box = boxes[0]; final OkHttpClient client = new OkHttpClient(); final String LOADER_API_URL = sharedPref.getString(SettingsActivity.KEY_PREF_API_URL, ""); final HttpUrl requestURL = HttpUrl.parse(LOADER_API_URL).newBuilder() .addQueryParameter("source", "android") .addQueryParameter("latupper", "" + box.northeast.latitude) .addQueryParameter("longupper", "" + box.northeast.longitude) .addQueryParameter("latlower", "" + box.southwest.latitude) .addQueryParameter("longlower", "" + box.southwest.longitude).build(); Log.d("api", "Request URL: " + requestURL); final Request get = new Request.Builder().header("User-Agent", BuildConfig.APPLICATION_ID + " " + BuildConfig.VERSION_NAME + "/Android?SDK=" + Build.VERSION.SDK_INT).url(requestURL).build(); final Response response = client.newCall(get).execute(); final int statusCode = response.code(); Log.d("api", "Status code: " + statusCode); // Data loaded OK if (statusCode == 200) { final String jResponse = response.body().string(); Log.d("api", "Raw API result: " + jResponse); jArray = new JSONArray(jResponse); } // Code used for invalid parameters; in this case exceeding // the limits of the boundary box else if (statusCode == 400) { return new ApiResultV1(ApiResultV1.ERROR_ZOOM); } // Unexpected error code else { return new ApiResultV1(ApiResultV1.ERROR_API); } } catch (Exception e) { e.printStackTrace(); } // Return list ArrayList<ArcadeLocation> out = new ArrayList<>(); try { for (int i = 0; i < jArray.length(); ++i) { final JSONObject obj = (JSONObject) jArray.get(i); final String name = obj.getString("name"); boolean closed = false; if (ArcadeLocation.CLOSED.matcher(name).matches()) { closed = true; } // Fields added after ddr-finder 1.0 API should be // explicitly tested for, in order to maintain // compatibility with deployments of older versions boolean hasDDR = false; if (obj.has("hasDDR") && obj.getInt("hasDDR") == 1) { hasDDR = true; } out.add(new ArcadeLocationV1(obj.getInt("id"), name, obj.getString("city"), new LatLng(obj.getDouble("latitude"), obj.getDouble("longitude")), hasDDR, closed)); } } catch (Exception e) { out.clear(); } return new ApiResultV1(out, boxes[0]); }