List of usage examples for java.util ArrayList clear
public void clear()
From source file:com.actionbarsherlock.internal.view.menu.MenuBuilder.java
@SuppressWarnings("deprecation") MenuItemImpl findItemWithShortcutForKey(int keyCode, KeyEvent event) { // Get all items that can be associated directly or indirectly with the keyCode ArrayList<MenuItemImpl> items = mTempShortcutItemList; items.clear();/*from w ww . j ava 2s .c om*/ findItemsWithShortcutForKey(items, keyCode, event); if (items.isEmpty()) { return null; } final int metaState = event.getMetaState(); final KeyCharacterMap.KeyData possibleChars = new KeyCharacterMap.KeyData(); // Get the chars associated with the keyCode (i.e using any chording combo) event.getKeyData(possibleChars); // If we have only one element, we can safely returns it final int size = items.size(); if (size == 1) { return items.get(0); } final boolean qwerty = isQwertyMode(); // If we found more than one item associated with the key, // we have to return the exact match for (int i = 0; i < size; i++) { final MenuItemImpl item = items.get(i); final char shortcutChar = qwerty ? item.getAlphabeticShortcut() : item.getNumericShortcut(); if ((shortcutChar == possibleChars.meta[0] && (metaState & KeyEvent.META_ALT_ON) == 0) || (shortcutChar == possibleChars.meta[2] && (metaState & KeyEvent.META_ALT_ON) != 0) || (qwerty && shortcutChar == '\b' && keyCode == KeyEvent.KEYCODE_DEL)) { return item; } } return null; }
From source file:com.battlelancer.seriesguide.util.TraktTools.java
/** * Applies database ops in small increments for the given episodes, setting the appropriate * flag//from w w w . ja v a2 s.com * in the given column. * * @param episodeFlagColumn Which flag column the given data should change. Supports {@link * com.battlelancer.seriesguide.provider.SeriesGuideContract.Episodes#WATCHED} * and {@link com.battlelancer.seriesguide.provider.SeriesGuideContract.Episodes#COLLECTED}. * @param clearExistingFlags If set, existing flags for all of this shows episodes will be set * to the default flag prior applying other changes. */ public static void applyEpisodeFlagChanges(Context context, TvShow tvShow, String episodeFlagColumn, boolean clearExistingFlags) { if (tvShow.seasons == null) { return; } int episodeFlag; int episodeDefaultFlag; String clearSelection; switch (episodeFlagColumn) { case SeriesGuideContract.Episodes.WATCHED: episodeFlag = EpisodeFlags.WATCHED; episodeDefaultFlag = EpisodeFlags.UNWATCHED; // do not remove flag of skipped episodes, only for watched ones clearSelection = SeriesGuideContract.Episodes.WATCHED + "=" + EpisodeFlags.WATCHED; break; case SeriesGuideContract.Episodes.COLLECTED: episodeFlag = 1; episodeDefaultFlag = 0; // only remove flags for already collected episodes clearSelection = SeriesGuideContract.Episodes.COLLECTED + "=1"; break; default: return; } ArrayList<ContentProviderOperation> batch = new ArrayList<>(); if (clearExistingFlags) { // remove all flags for episodes of this show // loop below will run at least once (would not be here if not at least one season), // so op-apply is ensured batch.add(ContentProviderOperation .newUpdate(SeriesGuideContract.Episodes.buildEpisodesOfShowUri(tvShow.tvdb_id)) .withSelection(clearSelection, null).withValue(episodeFlagColumn, episodeDefaultFlag).build()); } for (TvShowSeason season : tvShow.seasons) { if (season == null || season.season == null || season.episodes == null || season.episodes.numbers == null) { continue; } // build db ops to flag episodes according to given data for (Integer episode : season.episodes.numbers) { batch.add(ContentProviderOperation .newUpdate(SeriesGuideContract.Episodes.buildEpisodesOfShowUri(tvShow.tvdb_id)) .withSelection(SeriesGuideContract.Episodes.SEASON + "=" + season.season + " AND " + SeriesGuideContract.Episodes.NUMBER + "=" + episode, null) .withValue(episodeFlagColumn, episodeFlag).build()); } // apply batch of this season try { DBUtils.applyInSmallBatches(context, batch); } catch (OperationApplicationException e) { Timber.e("Applying flag changes failed: " + tvShow.tvdb_id + " season: " + season.season + " column: " + episodeFlagColumn, e); // do not abort, try other seasons // some episodes might be in incorrect state, but next update should fix that // this includes the clear flags op failing } batch.clear(); } }
From source file:org.apache.asterix.optimizer.rules.am.AbstractIntroduceAccessMethodRule.java
/** * Removes irrelevant access methods candidates, based on whether the * expressions in the query match those in the index. For example, some * index may require all its expressions to be matched, and some indexes may * only require a match on a prefix of fields to be applicable. This methods * removes all index candidates indexExprs that are definitely not * applicable according to the expressions involved. * * @throws AlgebricksException/*w w w.j av a 2s . c o m*/ */ public void pruneIndexCandidates(IAccessMethod accessMethod, AccessMethodAnalysisContext analysisCtx, IOptimizationContext context, IVariableTypeEnvironment typeEnvironment) throws AlgebricksException { Iterator<Map.Entry<Index, List<Pair<Integer, Integer>>>> indexExprAndVarIt = analysisCtx.indexExprsAndVars .entrySet().iterator(); // Used to keep track of matched expressions (added for prefix search) int numMatchedKeys = 0; ArrayList<Integer> matchedExpressions = new ArrayList<Integer>(); while (indexExprAndVarIt.hasNext()) { Map.Entry<Index, List<Pair<Integer, Integer>>> indexExprAndVarEntry = indexExprAndVarIt.next(); Index index = indexExprAndVarEntry.getKey(); boolean allUsed = true; int lastFieldMatched = -1; boolean foundKeyField = false; matchedExpressions.clear(); numMatchedKeys = 0; for (int i = 0; i < index.getKeyFieldNames().size(); i++) { List<String> keyField = index.getKeyFieldNames().get(i); final IAType keyType = index.getKeyFieldTypes().get(i); Iterator<Pair<Integer, Integer>> exprsAndVarIter = indexExprAndVarEntry.getValue().iterator(); while (exprsAndVarIter.hasNext()) { final Pair<Integer, Integer> exprAndVarIdx = exprsAndVarIter.next(); final IOptimizableFuncExpr optFuncExpr = analysisCtx.matchedFuncExprs.get(exprAndVarIdx.first); // If expr is not optimizable by concrete index then remove // expr and continue. if (!accessMethod.exprIsOptimizable(index, optFuncExpr)) { exprsAndVarIter.remove(); continue; } boolean typeMatch = true; //Prune indexes based on field types List<IAType> matchedTypes = new ArrayList<>(); //retrieve types of expressions joined/selected with an indexed field for (int j = 0; j < optFuncExpr.getNumLogicalVars(); j++) { if (j != exprAndVarIdx.second) { matchedTypes.add(optFuncExpr.getFieldType(j)); } } if (matchedTypes.size() < 2 && optFuncExpr.getNumLogicalVars() == 1) { matchedTypes.add((IAType) AqlExpressionTypeComputer.INSTANCE.getType( optFuncExpr.getConstantAtRuntimeExpr(0), context.getMetadataProvider(), typeEnvironment)); } //infer type of logicalExpr based on index keyType matchedTypes.add((IAType) AqlExpressionTypeComputer.INSTANCE.getType( optFuncExpr.getLogicalExpr(exprAndVarIdx.second), null, new IVariableTypeEnvironment() { @Override public Object getVarType(LogicalVariable var) throws AlgebricksException { if (var.equals(optFuncExpr.getSourceVar(exprAndVarIdx.second))) { return keyType; } throw new IllegalArgumentException(); } @Override public Object getVarType(LogicalVariable var, List<LogicalVariable> nonNullVariables, List<List<LogicalVariable>> correlatedNullableVariableLists) throws AlgebricksException { if (var.equals(optFuncExpr.getSourceVar(exprAndVarIdx.second))) { return keyType; } throw new IllegalArgumentException(); } @Override public void setVarType(LogicalVariable var, Object type) { throw new IllegalArgumentException(); } @Override public Object getType(ILogicalExpression expr) throws AlgebricksException { return AqlExpressionTypeComputer.INSTANCE.getType(expr, null, this); } @Override public boolean substituteProducedVariable(LogicalVariable v1, LogicalVariable v2) throws AlgebricksException { throw new IllegalArgumentException(); } })); //for the case when jaccard similarity is measured between ordered & unordered lists boolean jaccardSimilarity = optFuncExpr.getFuncExpr().getFunctionIdentifier().getName() .startsWith("similarity-jaccard-check"); for (int j = 0; j < matchedTypes.size(); j++) { for (int k = j + 1; k < matchedTypes.size(); k++) { typeMatch &= isMatched(matchedTypes.get(j), matchedTypes.get(k), jaccardSimilarity); } } // Check if any field name in the optFuncExpr matches. if (optFuncExpr.findFieldName(keyField) != -1) { foundKeyField = typeMatch && optFuncExpr.getOperatorSubTree(exprAndVarIdx.second).hasDataSourceScan(); if (foundKeyField) { matchedExpressions.add(exprAndVarIdx.first); numMatchedKeys++; if (lastFieldMatched == i - 1) { lastFieldMatched = i; } break; } } } if (!foundKeyField) { allUsed = false; // if any expression was matched, remove the non-matched expressions, otherwise the index is unusable if (lastFieldMatched >= 0) { exprsAndVarIter = indexExprAndVarEntry.getValue().iterator(); while (exprsAndVarIter.hasNext()) { if (!matchedExpressions.contains(exprsAndVarIter.next().first)) { exprsAndVarIter.remove(); } } } break; } } // If the access method requires all exprs to be matched but they // are not, remove this candidate. if (!allUsed && accessMethod.matchAllIndexExprs()) { indexExprAndVarIt.remove(); continue; } // A prefix of the index exprs may have been matched. if (accessMethod.matchPrefixIndexExprs()) { if (lastFieldMatched < 0) { indexExprAndVarIt.remove(); continue; } } analysisCtx.indexNumMatchedKeys.put(index, new Integer(numMatchedKeys)); } }
From source file:com.yoctopuce.YoctoAPI.YColorLedCluster.java
/** * Returns a list on sequence index for each RGB LED. The first number represents the * sequence index for the the first LED, the second number represents the sequence * index for the second LED, etc.//from w ww . j a va 2 s .com * * @param ledIndex : index of the first LED which should be returned * @param count : number of LEDs which should be returned * * @return a list of integers with sequence index * * @throws YAPI_Exception on error */ public ArrayList<Integer> get_linkedSeqArray(int ledIndex, int count) throws YAPI_Exception { byte[] buff; ArrayList<Integer> res = new ArrayList<Integer>(); int idx; int seq; // may throw an exception buff = _download(String.format("rgb.bin?typ=1&pos=%d&len=%d", ledIndex, count)); res.clear(); idx = 0; while (idx < count) { seq = buff[idx]; res.add(seq); idx = idx + 1; } return res; }
From source file:com.yoctopuce.YoctoAPI.YColorLedCluster.java
/** * Returns a list of integers with the "auto-start at power on" flag state for specified blinking sequences. * * @param seqIndex : index of the first blinking sequence which should be returned * @param count : number of blinking sequences which should be returned * * @return a list of integers, 0 for sequences turned off and 1 for sequences running * * @throws YAPI_Exception on error// w w w .j a v a 2 s .c o m */ public ArrayList<Integer> get_blinkSeqStateAtPowerOn(int seqIndex, int count) throws YAPI_Exception { byte[] buff; ArrayList<Integer> res = new ArrayList<Integer>(); int idx; int started; // may throw an exception buff = _download(String.format("rgb.bin?typ=5&pos=%d&len=%d", seqIndex, count)); res.clear(); idx = 0; while (idx < count) { started = buff[idx]; res.add(started); idx = idx + 1; } return res; }
From source file:com.yoctopuce.YoctoAPI.YColorLedCluster.java
/** * Returns a list of integers with the started state for specified blinking sequences. * * @param seqIndex : index of the first blinking sequence which should be returned * @param count : number of blinking sequences which should be returned * * @return a list of integers, 0 for sequences turned off and 1 for sequences running * * @throws YAPI_Exception on error//from w ww. j a v a2s. c o m */ public ArrayList<Integer> get_blinkSeqState(int seqIndex, int count) throws YAPI_Exception { byte[] buff; ArrayList<Integer> res = new ArrayList<Integer>(); int idx; int started; // may throw an exception buff = _download(String.format("rgb.bin?typ=3&pos=%d&len=%d", seqIndex, count)); res.clear(); idx = 0; while (idx < count) { started = buff[idx]; res.add(started); idx = idx + 1; } return res; }
From source file:de.dfki.km.perspecting.obie.model.Document.java
/** * @return the tokens// ww w . j a v a2 s .c o m */ public List<Token> getTokens(int start, int end) { ArrayList<Token> list = new ArrayList<Token>(); ArrayList<Integer> keys = new ArrayList<Integer>(this.data.getIntegerKeys(TokenSequence.TOKEN)); for (int i = 0; i < keys.size() && keys.get(i) <= start; i++) { if (keys.get(i) == start) { Token t; int i1 = i; do { t = new Token(keys.get(i1), this); if (t.getEnd() < end) { list.add(t); } if (t.getEnd() == end) { list.add(t); } i1++; } while (t.getEnd() <= end); } } if (list.get(list.size() - 1).getEnd() != end) { list.clear(); } return list; }
From source file:com.yoctopuce.YoctoAPI.YColorLedCluster.java
/** * Returns a list of integers with the current speed for specified blinking sequences. * * @param seqIndex : index of the first sequence speed which should be returned * @param count : number of sequence speeds which should be returned * * @return a list of integers, 0 for sequences turned off and 1 for sequences running * * @throws YAPI_Exception on error//from w w w .ja va2 s .co m */ public ArrayList<Integer> get_blinkSeqStateSpeed(int seqIndex, int count) throws YAPI_Exception { byte[] buff; ArrayList<Integer> res = new ArrayList<Integer>(); int idx; int lh; int ll; // may throw an exception buff = _download(String.format("rgb.bin?typ=6&pos=%d&len=%d", seqIndex, count)); res.clear(); idx = 0; while (idx < count) { lh = buff[2 * idx]; ll = buff[2 * idx + 1]; res.add(((lh) << (8)) + ll); idx = idx + 1; } return res; }
From source file:net.sf.jclal.sampling.unsupervised.Resample.java
/** * creates the subsample with replacement * * @param dataSet The dataset to extract a percent of instances * @param sampleSize the size to generate *///ww w . ja v a 2 s.com public void createSubsampleWithReplacement(IDataset dataSet, int sampleSize) { int origSize = dataSet.getNumInstances(); Set<Integer> indexes = new HashSet<Integer>(); Instances labeledInstances = new Instances(dataSet.getDataset(), sampleSize); //Fill the labeled set for (int i = 0; i < sampleSize; i++) { int index = getRandgen().choose(0, origSize); labeledInstances.add((Instance) dataSet.instance(index).copy()); indexes.add(index); } if (dataSet instanceof WekaDataset) { setLabeledData(new WekaDataset(labeledInstances)); } if (dataSet instanceof MulanDataset) { setLabeledData(new MulanDataset(labeledInstances, ((MulanDataset) dataSet).getLabelsMetaData())); } ArrayList<Container> indexesArray = new ArrayList<Container>(); for (Integer i : indexes) { indexesArray.add(new Container(i, i)); } //The array is ordered in descendent order OrderUtils.mergeSort(indexesArray, true); //Copy the entire dataset into unlabeled set Instances unlabeledInstances = new Instances(dataSet.getDataset()); //remove the instances that have been selected previously for (Container pair : indexesArray) { unlabeledInstances.remove(Integer.parseInt(pair.getValue().toString())); } if (dataSet instanceof WekaDataset) { setUnlabeledData(new WekaDataset(unlabeledInstances)); } if (dataSet instanceof MulanDataset) { setUnlabeledData(new MulanDataset(unlabeledInstances, ((MulanDataset) dataSet).getLabelsMetaData())); } // clean up unlabeledInstances.clear(); labeledInstances.clear(); unlabeledInstances = null; labeledInstances = null; indexes.clear(); indexesArray.clear(); indexes = null; indexesArray = null; }
From source file:org.akvo.caddisfly.sensor.colorimetry.liquid.ColorimetryLiquidActivity.java
/** * Get the test result by analyzing the bitmap. * * @param bitmap the bitmap of the photo taken during analysis *//*from w w w . j a va2s . c om*/ private void getAnalyzedResult(@NonNull Bitmap bitmap) { //Extract the color from the photo which will be used for comparison ColorInfo photoColor = ColorUtil.getColorFromBitmap(bitmap, ColorimetryLiquidConfig.SAMPLE_CROP_LENGTH_DEFAULT); //Quality too low reject this result // if (photoColor.getQuality() < 20) { // return; // } TestInfo testInfo = CaddisflyApp.getApp().getCurrentTestInfo(); ArrayList<ResultDetail> results = new ArrayList<>(); //In diagnostic mode show results based on other color models / number of calibration steps if (AppPreferences.isDiagnosticMode()) { ArrayList<Swatch> swatches = new ArrayList<>(); //1 step analysis try { swatches.add((Swatch) testInfo.getSwatch(0).clone()); SwatchHelper.generateSwatches(swatches, testInfo.getSwatches()); results.add(SwatchHelper.analyzeColor(1, photoColor, swatches, ColorUtil.ColorModel.LAB)); results.add(SwatchHelper.analyzeColor(1, photoColor, swatches, ColorUtil.ColorModel.RGB)); swatches.clear(); //add only the first and last swatch for a 2 step analysis swatches.add((Swatch) testInfo.getSwatch(0).clone()); swatches.add((Swatch) testInfo.getSwatch(testInfo.getSwatches().size() - 1).clone()); SwatchHelper.generateSwatches(swatches, testInfo.getSwatches()); results.add(SwatchHelper.analyzeColor(2, photoColor, swatches, ColorUtil.ColorModel.LAB)); results.add(SwatchHelper.analyzeColor(2, photoColor, swatches, ColorUtil.ColorModel.RGB)); swatches.clear(); //add the middle swatch for a 3 step analysis swatches.add((Swatch) testInfo.getSwatch(0).clone()); swatches.add((Swatch) testInfo.getSwatch(testInfo.getSwatches().size() - 1).clone()); swatches.add(1, (Swatch) testInfo.getSwatch(testInfo.getSwatches().size() / 2).clone()); SwatchHelper.generateSwatches(swatches, testInfo.getSwatches()); results.add(SwatchHelper.analyzeColor(3, photoColor, swatches, ColorUtil.ColorModel.LAB)); results.add(SwatchHelper.analyzeColor(3, photoColor, swatches, ColorUtil.ColorModel.RGB)); } catch (CloneNotSupportedException e) { Timber.e(e); } //use all the swatches for an all steps analysis results.add(SwatchHelper.analyzeColor(testInfo.getSwatches().size(), photoColor, CaddisflyApp.getApp().getCurrentTestInfo().getSwatches(), ColorUtil.ColorModel.RGB)); results.add(SwatchHelper.analyzeColor(testInfo.getSwatches().size(), photoColor, CaddisflyApp.getApp().getCurrentTestInfo().getSwatches(), ColorUtil.ColorModel.LAB)); } results.add(0, SwatchHelper.analyzeColor(testInfo.getSwatches().size(), photoColor, CaddisflyApp.getApp().getCurrentTestInfo().getSwatches(), ColorUtil.DEFAULT_COLOR_MODEL)); Result result = new Result(bitmap, results); mResults.add(result); }