List of usage examples for java.util ArrayList remove
public boolean remove(Object o)
From source file:gate.creole.orthomatcher.OrthoMatcher.java
protected void normalizePersonName(Annotation annot) throws ExecutionException { ArrayList<Annotation> tokens = (ArrayList<Annotation>) normalizedTokensMap.get(annot.getId()); for (int i = tokens.size() - 1; i >= 0; i--) { String tokenString = ((String) tokens.get(i).getFeatures().get(TOKEN_STRING_FEATURE_NAME)); String kind = (String) tokens.get(i).getFeatures().get(TOKEN_KIND_FEATURE_NAME); //String category = (String) tokens.get(i).getFeatures().get(TOKEN_CATEGORY_FEATURE_NAME); if (!caseSensitive) { tokenString = tokenString.toLowerCase(); }/* w w w .jav a 2 s . c om*/ // log.debug("tokenString: " + tokenString + " kind: " + kind + " category: " + category); if (kind.equals(PUNCTUATION_VALUE)) { // log.debug("Now tagging it!"); tokens.get(i).getFeatures().put("ortho_stop", true); } } ArrayList<Annotation> normalizedTokens = new ArrayList<Annotation>(tokens); for (int j = normalizedTokens.size() - 1; j >= 0; j--) { if (normalizedTokens.get(j).getFeatures().containsKey("ortho_stop")) { // log.debug("Now removing " + normalizedTokens.get(j).getFeatures().get(TOKEN_STRING_FEATURE_NAME)); normalizedTokens.remove(j); } } // log.debug("normalizedTokens size is: " + normalizedTokens.size()); normalizedTokensMap.put(annot.getId(), normalizedTokens); }
From source file:com.openddal.test.BaseTestCase.java
/** * Check if two databases contain the same met data. * * @param stat1 the connection to the first database * @param stat2 the connection to the second database * @throws AssertionError if the databases don't match *///from ww w . j av a2 s. c o m protected void assertEqualDatabases(Statement stat1, Statement stat2) throws SQLException { ResultSet rs = stat1 .executeQuery("select value from information_schema.settings " + "where name='ANALYZE_AUTO'"); int analyzeAuto = rs.next() ? rs.getInt(1) : 0; if (analyzeAuto > 0) { stat1.execute("analyze"); stat2.execute("analyze"); } ResultSet rs1 = stat1.executeQuery("SCRIPT simple NOPASSWORDS"); ResultSet rs2 = stat2.executeQuery("SCRIPT simple NOPASSWORDS"); ArrayList<String> list1 = new ArrayList<String>(); ArrayList<String> list2 = new ArrayList<String>(); while (rs1.next()) { String s1 = rs1.getString(1); s1 = removeRowCount(s1); if (!rs2.next()) { fail("expected: " + s1); } String s2 = rs2.getString(1); s2 = removeRowCount(s2); if (!s1.equals(s2)) { list1.add(s1); list2.add(s2); } } for (String s : list1) { if (!list2.remove(s)) { fail("only found in first: " + s + " remaining: " + list2); } } Assert.assertEquals("remaining: " + list2, 0, list2.size()); assertFalse(rs2.next()); }
From source file:br.unicamp.cst.behavior.bn.Behavior.java
public boolean removeByInfo(ArrayList<MemoryObject> moList, Object target) { boolean removed = false; MemoryObject mustRemove = null;//ww w. j a v a 2 s . co m for (MemoryObject mo : moList) { if (mo.getI().equals(target)) { mustRemove = mo; break; } } if (mustRemove != null) { moList.remove(mustRemove); removed = true; } return removed; }
From source file:com.ichi2.libanki.Stats.java
public boolean calculateDone(int type, boolean reps) { mHasColoredCumulative = true;//ww w . j av a 2 s . co m mDynamicAxis = true; mType = type; mBackwards = true; if (reps) { mTitle = R.string.stats_review_count; mAxisTitles = new int[] { type, R.string.stats_answers, R.string.stats_cumulative_answers }; } else { mTitle = R.string.stats_review_time; } mValueLabels = new int[] { R.string.statistics_learn, R.string.statistics_relearn, R.string.statistics_young, R.string.statistics_mature, R.string.statistics_cram }; mColors = new int[] { R.color.stats_learn, R.color.stats_relearn, R.color.stats_young, R.color.stats_mature, R.color.stats_cram }; int num = 0; int chunk = 0; switch (type) { case TYPE_MONTH: num = 31; chunk = 1; break; case TYPE_YEAR: num = 52; chunk = 7; break; case TYPE_LIFE: num = -1; chunk = 30; break; } ArrayList<String> lims = new ArrayList<String>(); if (num != -1) { lims.add("id > " + ((mCol.getSched().getDayCutoff() - ((num + 1) * chunk * 86400)) * 1000)); } String lim = _revlogLimit().replaceAll("[\\[\\]]", ""); if (lim.length() > 0) { lims.add(lim); } if (lims.size() > 0) { lim = "WHERE "; while (lims.size() > 1) { lim += lims.remove(0) + " AND "; } lim += lims.remove(0); } else { lim = ""; } String ti; String tf; if (!reps) { ti = "time/1000"; if (mType == TYPE_MONTH) { tf = "/60.0"; // minutes mAxisTitles = new int[] { type, R.string.stats_minutes, R.string.stats_cumulative_time_minutes }; } else { tf = "/3600.0"; // hours mAxisTitles = new int[] { type, R.string.stats_hours, R.string.stats_cumulative_time_hours }; } } else { ti = "1"; tf = ""; } ArrayList<double[]> list = new ArrayList<double[]>(); Cursor cur = null; String query = "SELECT (cast((id/1000 - " + mCol.getSched().getDayCutoff() + ") / 86400.0 AS INT))/" + chunk + " AS day, " + "sum(CASE WHEN type = 0 THEN " + ti + " ELSE 0 END)" + tf + ", " // lrn + "sum(CASE WHEN type = 1 AND lastIvl < 21 THEN " + ti + " ELSE 0 END)" + tf + ", " // yng + "sum(CASE WHEN type = 1 AND lastIvl >= 21 THEN " + ti + " ELSE 0 END)" + tf + ", " // mtr + "sum(CASE WHEN type = 2 THEN " + ti + " ELSE 0 END)" + tf + ", " // lapse + "sum(CASE WHEN type = 3 THEN " + ti + " ELSE 0 END)" + tf // cram + " FROM revlog " + lim + " GROUP BY day ORDER BY day"; Timber.d("ReviewCount query: %s", query); try { cur = mCol.getDb().getDatabase().rawQuery(query, null); while (cur.moveToNext()) { list.add(new double[] { cur.getDouble(0), cur.getDouble(1), cur.getDouble(4), cur.getDouble(2), cur.getDouble(3), cur.getDouble(5) }); } } finally { if (cur != null && !cur.isClosed()) { cur.close(); } } // small adjustment for a proper chartbuilding with achartengine if (type != TYPE_LIFE && (list.size() == 0 || list.get(0)[0] > -num)) { list.add(0, new double[] { -num, 0, 0, 0, 0, 0 }); } else if (type == TYPE_LIFE && list.size() == 0) { list.add(0, new double[] { -12, 0, 0, 0, 0, 0 }); } if (list.get(list.size() - 1)[0] < 0) { list.add(new double[] { 0, 0, 0, 0, 0, 0 }); } mSeriesList = new double[6][list.size()]; for (int i = 0; i < list.size(); i++) { double[] data = list.get(i); mSeriesList[0][i] = data[0]; // day mSeriesList[1][i] = data[1] + data[2] + data[3] + data[4] + data[5]; // lrn mSeriesList[2][i] = data[2] + data[3] + data[4] + data[5]; // relearn mSeriesList[3][i] = data[3] + data[4] + data[5]; // young mSeriesList[4][i] = data[4] + data[5]; // mature mSeriesList[5][i] = data[5]; // cram if (mSeriesList[1][i] > mMaxCards) mMaxCards = (int) Math.round(data[1] + data[2] + data[3] + data[4] + data[5]); if (data[5] >= 0.999) mFoundCramCards = true; if (data[1] >= 0.999) mFoundLearnCards = true; if (data[2] >= 0.999) mFoundRelearnCards = true; if (data[0] > mLastElement) mLastElement = data[0]; if (data[0] < mFirstElement) mFirstElement = data[0]; if (data[0] == 0) { mZeroIndex = i; } } mMaxElements = list.size() - 1; mCumulative = new double[6][]; mCumulative[0] = mSeriesList[0]; for (int i = 1; i < mSeriesList.length; i++) { mCumulative[i] = createCumulative(mSeriesList[i]); if (i > 1) { for (int j = 0; j < mCumulative[i - 1].length; j++) { mCumulative[i - 1][j] -= mCumulative[i][j]; } } } switch (mType) { case TYPE_MONTH: mFirstElement = -31; break; case TYPE_YEAR: mFirstElement = -52; break; default: } mMcount = 0; // we could assume the last element to be the largest, // but on some collections that may not be true due some negative values //so we search for the largest element: for (int i = 1; i < mCumulative.length; i++) { for (int j = 0; j < mCumulative[i].length; j++) { if (mMcount < mCumulative[i][j]) mMcount = mCumulative[i][j]; } } //some adjustments to not crash the chartbuilding with emtpy data if (mMaxCards == 0) mMaxCards = 10; if (mMaxElements == 0) { mMaxElements = 10; } if (mMcount == 0) { mMcount = 10; } if (mFirstElement == mLastElement) { mFirstElement = -10; mLastElement = 0; } return list.size() > 0; }
From source file:com.ichi2.libanki.test.SchedTestCase.java
@MediumTest public void test_deckTree() { Collection d = Shared.getEmptyDeck(getInstrumentation().getContext()); assertNotNull(d);/*from w ww . j av a2 s. c om*/ d.getDecks().id("new::b::c"); d.getDecks().id("new2"); // new should not appear twice in tree ArrayList<String> names = new ArrayList<String>(); TreeSet<Object[]> tree = d.getSched().deckDueTree(Sched.DECK_INFORMATION_SIMPLE_COUNTS); for (Object[] n : tree) { names.add(((String[]) n[0])[((String[]) n[0]).length - 1]); } names.remove("new"); assertTrue(names.indexOf("new") == -1); }
From source file:com.hygenics.parser.ForceConformityWithReference.java
private void iter() { log.info("Starting Enforcement @ " + Calendar.getInstance().getTime().toString() + " | UTC " + Calendar.getInstance().getTimeInMillis()); String sql;//from w ww . java 2 s. co m boolean add = true; ArrayList<String> columns = null; ArrayList<String> tablecolumns = null; Quicksort<String> qs = new Quicksort<String>(); Levenshtein lev = new Levenshtein(); // iterate through each table for (String table : schema_columns.keySet()) { log.info("Checking for Table Existance " + table); String schema = this.baseschema; log.info("Checking table: " + table + "&& schema: " + schema); if (template.checkTable(this.baseschema + "." + table, schema)) { log.info("Conforming: " + table); // get the arraylist tablecolumns = template.getColumns(this.baseschema + "." + table); if (insensitive == true) { for (int i = 0; i < tablecolumns.size(); i++) { tablecolumns.set(i, tablecolumns.get(i).toLowerCase()); } } columns = (ArrayList<String>) schema_columns.get(table); if (insensitive == true) { for (int i = 0; i < columns.size(); i++) { columns.set(i, columns.get(i).toLowerCase()); } } if (exclude != null) { // remove unmatchable columns if (exclude.size() > 0) { for (String col : exclude) { tablecolumns.remove(col); columns.remove(col); } } } // sort each arraylist qs.setTosortlist(columns); columns = qs.sort(); qs.setTosortlist(tablecolumns); tablecolumns = qs.sort(); // check each remaining column for (int i = 0; i < columns.size(); i++) { if (tablecolumns.contains(columns.get(i).trim()) == false || (insensitive == true && tablecolumns.contains(columns.get(i).toLowerCase().trim()) == false)) { if (correct) { int dist = Levenshtein.getLevenshteinDistance(tablecolumns.get(i), columns.get(i)); add = false; log.info("Distance was " + dist + " Cutoff is " + levcutoff); // check lev. distances if requested and ensure some // match with fuzzy (use at your own risk) if (levcutoff > -1 & dist <= levcutoff) { log.info("Approximate Match: Correcting Column"); // if distance is within 1 or specified // distances, correct it sql = "ALTER TABLE " + this.baseschema + "." + table + " RENAME COLUMN " + tablecolumns.get(i) + " TO " + columns.get(i); template.execute(sql); // get the table columns tablecolumns = template.getColumns(this.baseschema + "." + table); qs.setTosortlist(tablecolumns); tablecolumns = qs.sort(); } } else { add = true; } if (add) { // add column if necessary sql = "Alter Table " + this.baseschema + "." + table + " ADD COLUMN " + columns.get(i) + " text"; template.execute(sql); // get the table columns again and resort them tablecolumns = template.getColumns(this.baseschema + "." + table); if (exclude != null) { if (exclude.size() > 0) { for (String ex : exclude) { tablecolumns.remove(ex); columns.remove(ex); } } } qs.setTosortlist(tablecolumns); tablecolumns = qs.sort(); } // iterate backward so that the integrety is assured i--; } } } else { try { throw new SQLMalformedException("WARNING: Table " + table + " is missing"); } catch (SQLMalformedException e) { e.printStackTrace(); } } } log.info("Finishing Enforcement @ " + Calendar.getInstance().getTime().toString() + " | UTC " + Calendar.getInstance().getTimeInMillis()); }
From source file:br.unicamp.cst.behavior.bn.Behavior.java
/** * A behavior module is executable at time t when all of its preconditions are observed to be true at time t. * *///from w w w . j ava2s .c o m private boolean checkIfExecutable() { listOfWorldBeliefStates = new ArrayList<Object>(); for (MemoryObject mo : this.getInputsOfType("WORLD_STATE")) { listOfWorldBeliefStates.add(mo.getI()); // System.out.println("###########adding world state"); } ArrayList<MemoryObject> tempPreconList = new ArrayList<MemoryObject>(); //Comparison between two MOs is performed between their infos tempPreconList.addAll(preconList); for (MemoryObject precon : preconList) { for (Object ws : listOfWorldBeliefStates) { if (precon.getI().equals(ws)) { tempPreconList.remove(precon); break; } } } if (tempPreconList.isEmpty()) { setExecutable(true); } else { setExecutable(false); } //TODO I should probably check for conflicts between behaviors here... return executable; }
From source file:de.codesourcery.eve.skills.ui.components.impl.MarketPriceEditorComponent.java
protected void updateMultiplePrices(Map<Long, PriceInfoUpdateRequest> requests, PriceInfo.Type type, UpdateMode mode) throws PriceInfoUnavailableException { if (log.isDebugEnabled()) { log.debug("updateMultiplePrices(): " + requests.size() + " items , query type: " + type + " mode = " + mode);//w w w. j a v a2 s . co m } final Map<Type, Set<InventoryType>> pricesByQueryType = new HashMap<Type, Set<InventoryType>>(); for (PriceInfoUpdateRequest request : requests.values()) { Set<InventoryType> existing = pricesByQueryType.get(request.item); if (existing == null) { existing = new HashSet<InventoryType>(); pricesByQueryType.put(type, existing); } existing.add(request.item); } if (log.isDebugEnabled()) { for (Map.Entry<Type, Set<InventoryType>> entry : pricesByQueryType.entrySet()) { log.debug("updateMultiplePrices(): query type " + entry.getKey() + " : " + entry.getValue().size() + " items."); } } final ArrayList<InventoryType> queryBoth = new ArrayList<InventoryType>(); final ArrayList<InventoryType> queryBuy = new ArrayList<InventoryType>(); final ArrayList<InventoryType> querySell = new ArrayList<InventoryType>(); nullSafeAdd(queryBoth, pricesByQueryType.get(PriceInfo.Type.ANY)); nullSafeAdd(queryBuy, pricesByQueryType.get(PriceInfo.Type.BUY)); nullSafeAdd(querySell, pricesByQueryType.get(PriceInfo.Type.SELL)); for (Iterator<InventoryType> it = queryBuy.iterator(); it.hasNext();) { final InventoryType item = it.next(); if (querySell.contains(item)) { it.remove(); querySell.remove(item); queryBoth.add(item); } } for (Iterator<InventoryType> it = querySell.iterator(); it.hasNext();) { final InventoryType item = it.next(); if (queryBuy.contains(item)) { it.remove(); queryBuy.remove(item); queryBoth.add(item); } } if (log.isDebugEnabled()) { log.debug("updateMultiplePrices(): [ after merge ] Type.ALL = " + queryBoth.size()); log.debug("updateMultiplePrices(): [ after merge ] Type.BUY = " + queryBuy.size()); log.debug("updateMultiplePrices(): [ after merge ] Type.SELL = " + querySell.size()); } final IPriceQueryCallback callback = IPriceQueryCallback.NOP_INSTANCE; if (!queryBoth.isEmpty()) { MarketFilter filter = new MarketFilterBuilder(PriceInfo.Type.ANY, getDefaultRegion()).updateMode(mode) .end(); final IUpdateStrategy updateStrategy = marketDataProvider.createUpdateStrategy(mode, PriceInfo.Type.ANY); if (log.isDebugEnabled()) { log.debug("updateMultiplePrices(): Updating Type.ALL item prices."); } marketDataProvider.updatePriceInfo(filter, queryBoth, callback, updateStrategy); } if (!querySell.isEmpty()) { final MarketFilter filter = new MarketFilterBuilder(PriceInfo.Type.SELL, getDefaultRegion()) .updateMode(mode).end(); if (log.isDebugEnabled()) { log.debug("updateMultiplePrices(): Updating Type.SELL item prices."); } final IUpdateStrategy updateStrategy = marketDataProvider.createUpdateStrategy(mode, PriceInfo.Type.SELL); marketDataProvider.updatePriceInfo(filter, querySell, callback, updateStrategy); } if (!queryBuy.isEmpty()) { final MarketFilter filter = new MarketFilterBuilder(PriceInfo.Type.BUY, getDefaultRegion()) .updateMode(mode).end(); if (log.isDebugEnabled()) { log.debug("updateMultiplePrices(): Updating Type.BUY item prices."); } final IUpdateStrategy updateStrategy = marketDataProvider.createUpdateStrategy(mode, PriceInfo.Type.BUY); marketDataProvider.updatePriceInfo(filter, queryBuy, callback, updateStrategy); } }
From source file:edu.oregonstate.eecs.mcplan.domains.voyager.policies.DefensePolicy.java
@Override public VoyagerAction getAction() { final ArrayList<Planet> friendly = Voyager.playerPlanets(s_, self_); final NavigableMap<Planet, ArrayList<Spaceship>> incoming = new TreeMap<Planet, ArrayList<Spaceship>>(); for (final Spaceship ship : s_.spaceships) { ArrayList<Spaceship> ships = incoming.get(ship.dest); if (ships == null) { ships = new ArrayList<Spaceship>(); incoming.put(ship.dest, ships); }//from ww w . j a v a2 s .c o m ships.add(ship); } for (final ArrayList<Spaceship> ships : incoming.values()) { Collections.sort(ships, Spaceship.ArrivalTimeComparator); } final ArrayList<Pair<Integer, Planet>> events = new ArrayList<Pair<Integer, Planet>>(); for (final Map.Entry<Planet, ArrayList<Spaceship>> ships : incoming.entrySet()) { int t = 0; int strength_balance = Voyager.defense_strength(ships.getKey().population()); for (final Spaceship ship : ships.getValue()) { if (ship.owner == ships.getKey().owner()) { strength_balance += Voyager.defense_strength(ship.population); } else { // TODO: 2.0 is "safety margin"; should be a parameter strength_balance -= 2.0 * Voyager.attack_strength(ship.population); if (strength_balance <= 0) { t = ship.arrival_time; break; } } } if (t > 0) { events.add(Pair.makePair(t, ships.getKey())); friendly.remove(ships.getKey()); } } Collections.sort(events, new Pair.Comparator<Integer, Planet>()); for (final Pair<Integer, Planet> e : events) { for (final Planet src : friendly) { // TODO: Need to account for ship speed if (Voyager.distance(src, e.second) < e.first) { // TODO: Garrison 1 should be parameter final int spare_soldiers = src.population(Unit.Soldier) - 1; if (spare_soldiers > 0) { final int[] pop = new int[Unit.values().length]; pop[Unit.Soldier.ordinal()] = spare_soldiers; return new LaunchAction(src, e.second, pop); } } } } return new NothingAction(); }
From source file:cm.aptoide.pt.ManageRepos.java
private void receiveMyappRepos() { try {/*from w w w .ja v a 2s .c o m*/ final ViewDisplayListRepos myappRepos = serviceDataCaller.callGetWaitingMyappRepos(); //TODO checkServerConnection final CharSequence[] reposArray = new CharSequence[myappRepos.getList().size()]; for (int i = 0; i < myappRepos.getList().size(); i++) { reposArray[i] = (String) myappRepos.getList().get(i).get(Constants.KEY_REPO_URI); } final ArrayList<String> addList = new ArrayList<String>(); AlertDialog.Builder builder = new AlertDialog.Builder(theme); builder.setTitle(getString(R.string.add_repo_choose)); builder.setIcon(R.drawable.ic_menu_add); builder.setMultiChoiceItems(reposArray, null, new DialogInterface.OnMultiChoiceClickListener() { public void onClick(DialogInterface dialog, int whichButton, boolean isChecked) { if (isChecked) { addList.add(reposArray[whichButton].toString()); } else { addList.remove(reposArray[whichButton].toString()); } } }); builder.setPositiveButton(getString(R.string.add), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { for (String repoUri : addList) { addDisplayRepo(new ViewRepository(repoUri)); } alert.dismiss(); handlingMyappRepos = false; refreshReposList(); } }); builder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { alert.dismiss(); handlingMyappRepos = false; finish(); } }); alert = builder.create(); alert.show(); } catch (RemoteException e) { // TODO Auto-generated catch block e.printStackTrace(); } }