List of usage examples for java.util ArrayList remove
public boolean remove(Object o)
From source file:it.univpm.deit.semedia.musicuri.core.Toolset.java
/** * Extracts a list of keywords from an audio file (currently only using its filename), * after ignoring certain words that are either among the 50 most common english words, * or are frequently occuring music-related terms commonly found in music filenames * @param audiofile the audio file to extract keywords from * @return an aArrayList object containing the extracted keywordss *///from ww w . j ava 2 s . com public static ArrayList ExtractKeywords(File audiofile) { // Idea taken from: Franois Pachet and Damien Laigre, //"A Naturalist Approach to Music File Name Analysis" // Delimiter Hypothesis, Constant Term Hypothesis, Canonical Representation // of Identifiers (so that different spellings of a given identifier yield the same representation) // list of words to return ArrayList keywords = new ArrayList(); // list of words to ignore ArrayList ignored = new ArrayList(); // The 50 most common words in the english language // http://esl.about.com/library/vocabulary/bl1000_list1.htm // http://www.world-english.org/english500.htm // http://www.duboislc.org/EducationWatch/First100Words.html ignored.add("the"); ignored.add("of"); ignored.add("and"); ignored.add("a"); ignored.add("to"); ignored.add("in"); ignored.add("is"); ignored.add("you"); ignored.add("that"); ignored.add("it"); ignored.add("he"); ignored.add("was"); ignored.add("for"); ignored.add("on"); ignored.add("are"); ignored.add("as"); ignored.add("with"); ignored.add("his"); ignored.add("they"); ignored.add("i"); ignored.add("at"); ignored.add("be"); ignored.add("this"); ignored.add("have"); ignored.add("from"); ignored.add("or"); ignored.add("one"); ignored.add("had"); ignored.add("by"); ignored.add("word"); ignored.add("but"); ignored.add("not"); ignored.add("what"); ignored.add("all"); ignored.add("were"); ignored.add("we"); ignored.add("when"); ignored.add("your"); ignored.add("can"); ignored.add("said"); ignored.add("there"); ignored.add("use"); ignored.add("an"); ignored.add("each"); ignored.add("which"); ignored.add("she"); ignored.add("do"); ignored.add("how"); ignored.add("their"); ignored.add("if"); // Some frequently occuring words related to music filenames ignored.add("mp3"); ignored.add("&"); ignored.add("featuring"); ignored.add("+"); ignored.add("feat"); ignored.add("presenting"); ignored.add("pres"); ignored.add("live"); ignored.add("track"); ignored.add("album"); ignored.add("various"); ignored.add("artists"); ignored.add("artist"); ignored.add("va"); ignored.add("collection"); ignored.add("sampler"); ignored.add("mix"); ignored.add("complilation"); ignored.add("mixed"); ignored.add("remix"); ignored.add("remixed"); ignored.add("lp"); ignored.add("ep"); ignored.add("cd"); ignored.add(""); // replace all contents of the ignored list with lowercase for (int i = 0; i < ignored.size(); i++) { String tmp = (String) ignored.get(i); ignored.remove(i); tmp = tmp.toLowerCase(); ignored.add(tmp); } // the source used for token extraction is currently the filename String name = audiofile.getName(); // the delimiters to use when tokenizing StringTokenizer st = new StringTokenizer(name, " ,._-~\"'`/()[]:{}+#\t\n\r"); // loop over all tokens in string while (st.hasMoreTokens()) { // get the next String token = st.nextToken(); // convert it to lowercase token = token.toLowerCase(); // if it's on the list of ignored keywords if (!ignored.contains(token)) { // try to cast it to an integer try { // if it was an integer, do nothing Integer.parseInt(token); } catch (NumberFormatException e) { // if it wasn't, add it to the keywords list keywords.add(token); } } } return keywords; }
From source file:org.powertac.server.CompetitionControlService.java
private boolean configurePlugins() { List<InitializationService> initializers = SpringApplicationContext .listBeansOfType(InitializationService.class); ArrayList<String> completedPlugins = new ArrayList<String>(); ArrayList<InitializationService> deferredInitializers = new ArrayList<InitializationService>(); for (InitializationService initializer : initializers) { if (bootstrapMode) { if (initializer.equals(visualizerProxyService) || initializer.equals(jmsManagementService)) { log.info("Skipping initialization of " + initializer.toString()); continue; }/*from ww w . j av a 2 s . co m*/ } log.info("attempt to initialize " + initializer.toString()); String success = initializer.initialize(competition, completedPlugins); if (success == null) { // defer this one log.info("deferring " + initializer.toString()); deferredInitializers.add(initializer); } else if (success.equals("fail")) { log.error("Failed to initialize plugin " + initializer.toString()); return false; } else { log.info("completed " + success); completedPlugins.add(success); } } int tryCounter = deferredInitializers.size(); while (deferredInitializers.size() > 0 && tryCounter > 0) { InitializationService initializer = deferredInitializers.get(0); log.info("additional attempt to initialize " + initializer.toString()); if (deferredInitializers.size() > 1) { deferredInitializers.remove(0); } else { deferredInitializers.clear(); } String success = initializer.initialize(competition, completedPlugins); if (success == null) { // defer this one log.info("deferring " + initializer.toString()); deferredInitializers.add(initializer); tryCounter -= 1; } else { log.info("completed " + success); completedPlugins.add(success); } } for (InitializationService initializer : deferredInitializers) { log.error("Failed to initialize " + initializer.toString()); } return true; }
From source file:com.facebook.tsdb.tsdash.server.model.Metric.java
public void alignAllTimeSeries() { long cycle = guessTimeCycle(); // wrap the time stamps to a multiple of cycle for (ArrayList<DataPoint> points : timeSeries.values()) { for (DataPoint p : points) { p.ts -= p.ts % cycle;//ww w . j av a 2 s .com } } // do the actual aligning TreeMap<TagsArray, ArrayList<DataPoint>> aligned = new TreeMap<TagsArray, ArrayList<DataPoint>>( Tag.arrayComparator()); for (TagsArray header : timeSeries.keySet()) { aligned.put(header, TimeSeries.align(timeSeries.get(header), cycle)); } // align the time series between each other long maxmin = Long.MIN_VALUE; long minmax = Long.MAX_VALUE; long maxmax = Long.MIN_VALUE; for (ArrayList<DataPoint> points : aligned.values()) { if (points.size() == 0) { logger.error("We have found an empty timeseries"); continue; } DataPoint first = points.get(0); if (points.size() > 0 && points.get(0).ts > maxmin) { maxmin = first.ts; } DataPoint last = points.get(points.size() - 1); if (last.ts < minmax) { minmax = last.ts; } if (last.ts > maxmax) { maxmax = last.ts; } } if (maxmax - minmax > DATA_MISSING_THOLD) { // we've just detected missing data from this set of time series logger.error("Missing data detected"); // add padding to maxmax for (ArrayList<DataPoint> points : aligned.values()) { if (points.size() == 0) { continue; } long max = points.get(points.size() - 1).ts; for (long ts = max + cycle; ts <= maxmax; ts += cycle) { points.add(new DataPoint(ts, 0.0)); } } } else { // cut off the tail for (ArrayList<DataPoint> points : aligned.values()) { while (points.size() > 0 && points.get(points.size() - 1).ts > minmax) { points.remove(points.size() - 1); } } } // cut off the head for (ArrayList<DataPoint> points : aligned.values()) { while (points.size() > 0 && points.get(0).ts < maxmin) { points.remove(0); } } this.timeSeries = aligned; }
From source file:com.collabnet.ccf.pi.qc.v90.QCHandler.java
/** * Return all defects modified between the given time range, in a map * // w w w . j a va2s . c o m */ public List<ArtifactState> getLatestChangedDefects(IConnection qcc, String transactionId) { int rc = 0; String sql = "SELECT AU_ENTITY_ID, AU_ACTION_ID, AU_TIME FROM AUDIT_LOG WHERE AU_ENTITY_TYPE = 'BUG' AND AU_ACTION_ID > '" + transactionId + "' AND AU_ACTION!='DELETE' AND AU_FATHER_ID = '-1' ORDER BY AU_ACTION_ID"; log.debug(sql); ArrayList<ArtifactState> changedDefects = new ArrayList<ArtifactState>(); HashMap<String, ArtifactState> artifactIdStateMap = new HashMap<String, ArtifactState>(); IRecordSet rs = null; try { rs = qcc.executeSQL(sql); if (rs != null) rc = rs.getRecordCount(); for (int cnt = 0; cnt < rc; cnt++, rs.next()) { String bugId = rs.getFieldValueAsString("AU_ENTITY_ID"); String actionIdStr = rs.getFieldValueAsString("AU_ACTION_ID"); int actionId = Integer.parseInt(actionIdStr); String actionDateStr = rs.getFieldValueAsString("AU_TIME"); Date actionDate = DateUtil.parseQCDate(actionDateStr); if (artifactIdStateMap.containsKey(bugId)) { ArtifactState state = artifactIdStateMap.get(bugId); changedDefects.remove(state); state.setArtifactLastModifiedDate(actionDate); state.setArtifactVersion(actionId); changedDefects.add(state); } else { ArtifactState state = new ArtifactState(); state.setArtifactId(bugId); state.setArtifactLastModifiedDate(actionDate); state.setArtifactVersion(actionId); changedDefects.add(state); artifactIdStateMap.put(bugId, state); } } } finally { if (rs != null) { rs.safeRelease(); rs = null; } } return changedDefects; }
From source file:com.collabnet.ccf.pi.qc.v90.QCHandler.java
public List<ArtifactState> getLatestChangedRequirements(IConnection qcc, String transactionId, String technicalRequirementsId, boolean ignoreRequirementRootFolder) { int rc = 0;// www . ja v a2 s .com String sql = sqlQueryToRetrieveLatestRequirement(transactionId, technicalRequirementsId, ignoreRequirementRootFolder); log.debug(sql); ArrayList<ArtifactState> changedRequirements = new ArrayList<ArtifactState>(); HashMap<String, ArtifactState> artifactIdStateMap = new HashMap<String, ArtifactState>(); IRecordSet rs = null; try { rs = qcc.executeSQL(sql); if (rs != null) rc = rs.getRecordCount(); for (int cnt = 0; cnt < rc; cnt++, rs.next()) { String reqId = rs.getFieldValueAsString("AU_ENTITY_ID"); String actionIdStr = rs.getFieldValueAsString("AU_ACTION_ID"); int actionId = Integer.parseInt(actionIdStr); String actionDateStr = rs.getFieldValueAsString("AU_TIME"); Date actionDate = DateUtil.parseQCDate(actionDateStr); if (artifactIdStateMap.containsKey(reqId)) { ArtifactState state = artifactIdStateMap.get(reqId); changedRequirements.remove(state); state.setArtifactLastModifiedDate(actionDate); state.setArtifactVersion(actionId); changedRequirements.add(state); } else { ArtifactState state = new ArtifactState(); state.setArtifactId(reqId); state.setArtifactLastModifiedDate(actionDate); state.setArtifactVersion(actionId); changedRequirements.add(state); artifactIdStateMap.put(reqId, state); } } } finally { if (rs != null) { rs.safeRelease(); rs = null; } } return changedRequirements; }
From source file:org.mwc.debrief.sensorfusion.views.DataSupport.java
/** * Deletes all blocks of sensor data that are more than 45 degrees from an * secondary track.//from www .ja v a2 s . co m * * @return */ public static ArrayList<SensorWrapper> trimToSensorNearSubjectTracks(final TrackWrapper primary, final WatchableList[] secondaries) { ArrayList<SensorWrapper> toRemove = new ArrayList<SensorWrapper>(); ArrayList<SensorWrapper> toKeep = new ArrayList<SensorWrapper>(); if (primary == null || secondaries == null) return toRemove; Enumeration<Editable> sensors = primary.getSensors().elements(); while (sensors.hasMoreElements()) { SensorWrapper sensor = (SensorWrapper) sensors.nextElement(); // ok, remember this one toRemove.add(sensor); final Enumeration<Editable> contacts = sensor.elements(); // loop though the individual sensor contact objects while (sensor != null && (contacts.hasMoreElements())) { final SensorContactWrapper contact = (SensorContactWrapper) contacts.nextElement(); // check this sensor contact has a bearing if (!contact.getHasBearing()) { // hey, no bearing - we aren't sufficiently able to decide if // it can be ditched. toKeep.add(sensor); sensor = null; } else { final HiResDate contactTime = contact.getDTG(); // loop through each secondary track for (int i = 0; i < secondaries.length; i++) { final WatchableList thisS = secondaries[i]; final Watchable[] secondaryFixes = thisS.getNearestTo(contactTime); final Watchable[] primaryFixes = primary.getNearestTo(contactTime); double bearing = 0; if (secondaryFixes != null && secondaryFixes.length > 0) { if (primaryFixes != null && primaryFixes.length > 0) { WorldLocation wl1 = secondaryFixes[0].getLocation(); WorldLocation wl2 = primaryFixes[0].getLocation(); bearing = wl1.bearingFrom(wl2); } } double bearingDelta = contact.getBearing() - Math.toDegrees(bearing); if (Math.abs(bearingDelta) < THRESHOLD_FOR_IRRELEVANT_DATA) { // ok, this sensor is relevant toKeep.add(sensor); // now clear the sensor, as a marker to move on to the next // sensor sensor = null; } } } } // end loop through sensor contacts } // ok, we've built up a list of sensors to keep. We now need to get rid of // the other ones Iterator<SensorWrapper> keepers = toKeep.iterator(); while (keepers.hasNext()) { SensorWrapper keepMe = (SensorWrapper) keepers.next(); toRemove.remove(keepMe); } return toRemove; }
From source file:com.krawler.esp.servlets.AdminServlet.java
public static String makeNickName(Connection conn, String name, int flag) throws ServiceException { String nickName = name.toLowerCase().trim().replaceAll("\\s+", "-").replaceAll("[^\\w|\\-]", ""); String sql = "select nickName from " + (flag == 1 ? "project" : "community") + " where nickName like ?"; DbResults rs = DbUtil.executeQuery(conn, sql, nickName + "%"); java.util.ArrayList<String> namesArray = new java.util.ArrayList<String>(); while (rs.next()) { namesArray.add(rs.getString(1)); }//from w w w. j av a2 s . c o m int i = 0; while (namesArray.indexOf(nickName) != -1) { namesArray.remove(nickName); i++; nickName = nickName + i; } return nickName; }
From source file:edu.eurac.commul.pepperModules.mmax2.MMAX22SaltMapper.java
private void completeSPointer(SPointingRelation sPointingRelation, SaltExtendedMarkable markable) { MarkableAttribute sourceAttribute = null; MarkableAttribute sourceSchemeAttribute = null; MarkableAttribute targetAttribute = null; MarkableAttribute targetSchemeAttribute = null; MarkableAttribute containerPointerAttribute = null; ArrayList<MarkableAttribute> markableAttributes = markable.getAttributes(); for (MarkableAttribute markableAttribute : markableAttributes) { if (markableAttribute.getName().equals("source")) { sourceAttribute = markableAttribute; } else if (markableAttribute.getName().equals("source_attr")) { containerPointerAttribute = markableAttribute; } else if (markableAttribute.getName().equals("target")) { targetAttribute = markableAttribute; } else if (markableAttribute.getName().equals("target_scheme")) { targetSchemeAttribute = markableAttribute; } else if (markableAttribute.getName().equals("source_scheme")) { sourceSchemeAttribute = markableAttribute; }/*from w ww .ja v a2 s .c o m*/ } if (sourceAttribute == null) throw new PepperModuleDataException(this, "'source' attribute is missing on Saltextended markable '" + markable + "' representing an SPointingRelation"); markableAttributes.remove(sourceAttribute); if (sourceSchemeAttribute == null) throw new PepperModuleDataException(this, "'source_scheme' attribute is missing on Saltextended markable '" + markable + "' representing an SPointingRelation"); markableAttributes.remove(sourceSchemeAttribute); SaltExtendedMarkable sourceMarkable = getMarkable(sourceAttribute.getValue(), sourceSchemeAttribute.getValue()); if (sourceMarkable == null) throw new PepperModuleDataException(this, "An unknown markable is referenced as the source for the SPointingRelation represented by markable '" + markable + "'"); SNode sSource = null; SNode sTarget = null; if (sourceMarkable.getSType().equals(SaltExtendedMmax2Infos.SALT_INFO_TYPE_SCONTAINER)) { SaltExtendedMarkable sourceContainedMarkable = this.claimSContainer.get(sourceMarkable); sSource = getSNode(sourceContainedMarkable); if (containerPointerAttribute == null) throw new PepperModuleDataException(this, "'source_attr' attribute is missing on Saltextended markable '" + markable + "' representing an SPointingRelation"); markableAttributes.remove(containerPointerAttribute); MarkableAttribute pointer = null; String sourcePointerAttribute = containerPointerAttribute.getValue(); for (MarkableAttribute sourceMarkableAttribute : sourceMarkable.getAttributes()) { if (sourceMarkableAttribute.getName().equals(sourcePointerAttribute)) { pointer = sourceMarkableAttribute; break; } } if (pointer == null) throw new PepperModuleDataException(this, "'" + sourcePointerAttribute + "' attribute is missing on SContainer markable '" + sourceMarkable + "'"); sourceMarkable.removeAttribute(pointer); MarkablePointerAttributeFactory pointerFactory = (MarkablePointerAttributeFactory) pointer.getFactory(); SaltExtendedMarkable targetMarkable = getMarkable(pointer.getValue(), pointerFactory.getTargetSchemeName()); if (targetMarkable == null) throw new PepperModuleDataException(this, " An unknown markable is referenced as the target of Saltextended markable '" + markable + "' representing an SPointingRelation"); SaltExtendedMarkable targetContainedMarkable = this.claimSContainer.get(targetMarkable); sTarget = getSNode(targetContainedMarkable); if (sTarget == null) throw new PepperModuleDataException(this, "An unknown target node is referenced as the target for the SPointingRelation represented by markable '" + markable + "'"); } else { sSource = getSNode(sourceMarkable); if (sSource == null) throw new PepperModuleDataException(this, "An unknown SNode node is referenced as the source for the SPointingRelation represented by markable '" + markable + "'"); if (targetAttribute == null) throw new PepperModuleDataException(this, "'target' attribute is missing on Saltextended markable '" + markable + "' representing an SPointingRelation"); markableAttributes.remove(targetAttribute); if (targetSchemeAttribute == null) throw new PepperModuleDataException(this, "'target_scheme' attribute is missing on Saltextended markable '" + markable + "' representing an SPointingRelation"); markableAttributes.remove(targetSchemeAttribute); SaltExtendedMarkable targetMarkable = getMarkable(targetAttribute.getValue(), targetSchemeAttribute.getValue()); if (targetMarkable == null) throw new PepperModuleDataException(this, " An unknown markable is referenced as the target of Saltextended markable '" + markable + "' representing an SPointingRelation"); sTarget = getSNode(targetMarkable); if (sTarget == null) throw new PepperModuleDataException(this, "An unknown target node is referenced as the target for the SPointingRelation represented by markable '" + markable + "'"); } sPointingRelation.setSource((SStructuredNode) sSource); sPointingRelation.setTarget((SStructuredNode) sTarget); }
From source file:com.eleybourn.bookcatalogue.utils.Utils.java
/** * Passed a list of Objects, remove duplicates based on the toString result. * // www. ja v a2 s . c o m * ENHANCE Add author_aliases table to allow further pruning (eg. Joe Haldeman == Jow W Haldeman). * ENHANCE Add series_aliases table to allow further pruning (eg. 'Amber Series' <==> 'Amber'). * * @param db Database connection to lookup IDs * @param list List to clean up */ public static <T extends ItemWithIdFixup> boolean pruneList(CatalogueDBAdapter db, ArrayList<T> list) { Hashtable<String, Boolean> names = new Hashtable<String, Boolean>(); Hashtable<Long, Boolean> ids = new Hashtable<Long, Boolean>(); // We have to go forwards through the list because 'first item' is important, // but we also can't delete things as we traverse if we are going forward. So // we build a list of items to delete. ArrayList<Integer> toDelete = new ArrayList<Integer>(); for (int i = 0; i < list.size(); i++) { T item = list.get(i); Long id = item.fixupId(db); String name = item.toString().trim().toUpperCase(); // Series special case - same name different series number. // This means different series positions will have the same ID but will have // different names; so ItemWithIdFixup contains the 'isUniqueById()' method. if (ids.containsKey(id) && !names.containsKey(name) && !item.isUniqueById()) { ids.put(id, true); names.put(name, true); } else if (names.containsKey(name) || (id != 0 && ids.containsKey(id))) { toDelete.add(i); } else { ids.put(id, true); names.put(name, true); } } for (int i = toDelete.size() - 1; i >= 0; i--) list.remove(toDelete.get(i).intValue()); return toDelete.size() > 0; }
From source file:com.dtolabs.rundeck.core.authorization.providers.TestYamlPolicy.java
public void testSetContainsPredicate() { final YamlPolicy.SetContainsPredicate blah = new YamlPolicy.SetContainsPredicate("blah"); final ArrayList<String> strings = new ArrayList<String>(); assertFalse(blah.evaluate(strings)); assertFalse(blah.evaluate("")); assertFalse(blah.evaluate(null));//from ww w .j a v a 2 s . co m strings.add("nomatch"); assertFalse(blah.evaluate(strings)); assertFalse(blah.evaluate("nomatch")); strings.add("blah"); assertTrue(blah.evaluate(strings)); assertTrue(blah.evaluate("blah")); assertTrue(blah.evaluate("blah, nomatch")); final ArrayList<String> input = new ArrayList<String>(); input.add("test1"); input.add("test2"); final YamlPolicy.SetContainsPredicate multiple = new YamlPolicy.SetContainsPredicate(input); final ArrayList<String> strings2 = new ArrayList<String>(); assertFalse(multiple.evaluate(strings2)); assertFalse(multiple.evaluate("")); assertFalse(multiple.evaluate(null)); strings2.add("nomatch"); assertFalse(multiple.evaluate(strings2)); assertFalse(multiple.evaluate("nomatch")); strings2.add("blah"); assertFalse(multiple.evaluate(strings2)); assertFalse(multiple.evaluate("nomatch, blah")); strings2.add("test1"); assertFalse(multiple.evaluate(strings2)); assertFalse(multiple.evaluate("nomatch, blah, test1")); strings2.remove("test1"); strings2.add("test2"); assertFalse(multiple.evaluate(strings2)); assertFalse(multiple.evaluate("nomatch, blah, test2")); strings2.add("test1"); assertTrue(multiple.evaluate(strings2)); assertTrue(multiple.evaluate("nomatch, blah, test1, test2")); }