List of usage examples for java.util HashSet remove
public boolean remove(Object o)
From source file:org.apache.lens.cli.doc.TestGenerateCLIUserDoc.java
@Test public void generateDoc() throws IOException { BufferedWriter bw = new BufferedWriter(new FileWriter(new File(APT_FILE))); StringBuilder sb = new StringBuilder(); sb.append(getCLIIntroduction()).append("\n\n\n"); List<Class<? extends CommandMarker>> classes = Lists.newArrayList(LensConnectionCommands.class, LensDatabaseCommands.class, LensStorageCommands.class, LensCubeCommands.class, LensDimensionCommands.class, LensFactCommands.class, LensDimensionTableCommands.class, LensNativeTableCommands.class, LensQueryCommands.class, LensLogResourceCommands.class, LensSchemaCommands.class); for (Class claz : classes) { UserDocumentation doc = (UserDocumentation) claz.getAnnotation(UserDocumentation.class); if (doc != null && StringUtils.isNotBlank(doc.title())) { sb.append("** ").append(doc.title()).append("\n\n ").append(doc.description()).append("\n\n"); }/* www .j a v a 2s . c om*/ sb.append("*--+--+\n" + "|<<Command>>|<<Description>>|\n" + "*--+--+\n"); TreeSet<Method> methods = Sets.newTreeSet(new Comparator<Method>() { @Override public int compare(Method o1, Method o2) { return o1.getAnnotation(CliCommand.class).value()[0] .compareTo(o2.getAnnotation(CliCommand.class).value()[0]); } }); for (Method method : claz.getMethods()) { if (method.getAnnotation(CliCommand.class) != null) { methods.add(method); } else { log.info("Not adding " + method.getDeclaringClass().getSimpleName() + "#" + method.getName()); } } List<DocEntry> docEntries = Lists.newArrayList(); for (Method method : methods) { CliCommand annot = method.getAnnotation(CliCommand.class); StringBuilder commandBuilder = new StringBuilder(); String sep = ""; for (String value : annot.value()) { commandBuilder.append(sep).append(value); sep = "/"; } for (Annotation[] annotations : method.getParameterAnnotations()) { for (Annotation paramAnnot : annotations) { if (paramAnnot instanceof CliOption) { CliOption cliOption = (CliOption) paramAnnot; HashSet<String> keys = Sets.newHashSet(cliOption.key()); boolean optional = false; if (keys.contains("")) { optional = true; keys.remove(""); } if (!keys.isEmpty()) { commandBuilder.append(" "); if (!cliOption.mandatory()) { commandBuilder.append("["); } if (optional) { commandBuilder.append("["); } sep = ""; for (String key : keys) { commandBuilder.append(sep).append("--").append(key); sep = "/"; } if (optional) { commandBuilder.append("]"); } sep = ""; } commandBuilder.append(" ") .append(cliOption.help().replaceAll("<", "\\\\<").replaceAll(">", "\\\\>")); if (!cliOption.mandatory()) { commandBuilder.append("]"); } } } } docEntries.add(new DocEntry(commandBuilder.toString(), annot.help().replaceAll("<", "<<<").replaceAll(">", ">>>"))); } for (DocEntry entry : docEntries) { for (int i = 0; i < entry.getHelp().length; i++) { sb.append("|").append(i == 0 ? entry.getCommand() : entry.getCommand().replaceAll(".", " ")) .append("|").append(entry.getHelp()[i]).append("|").append("\n"); } sb.append("*--+--+\n"); } sb.append(" <<").append(getReadableName(claz.getSimpleName())).append(">>\n\n===\n\n"); } bw.write(sb.toString()); bw.close(); }
From source file:org.magnum.mobilecloud.video.controller.VideoController.java
@RequestMapping(value = VIDEO_SVC_PATH + "/{id}" + "/unlike", method = RequestMethod.POST) public @ResponseBody Video unlikeVideo(@PathVariable("id") long id, HttpServletResponse response, Principal p) { String username = p.getName(); Video v = videos.findById(id);/*from w w w.j a va2s . co m*/ if (v != null) { HashSet<String> videoLikes = v.getUserLikes(); if (videoLikes.contains(username)) { System.out.print("These are the videoLikes: " + videoLikes); videoLikes.remove(username); System.out.print("These are the videoLikes: " + videoLikes); v.setLikes((long) (v.getLikes() - 1)); v.setUserLikes(videoLikes); response.setStatus(200); videos.save(v); return v; } else { response.setStatus(400); return v; } } response.setStatus(404); return null; }
From source file:org.tridas.io.util.ITRDBTaxonConverter.java
/** * Returns a ControlledVoc of the best match from the ITRDB taxon dictionary. Takes a string ArrayList * of possible search terms which can be codes and/or full names. If conflicting search terms are * provided (e.g. QUER, Pinus sylvestris) then it returns null. If no matches are found then it returns null. * // w w w. j a v a 2 s .c o m * @param searchStrings * @return */ public static ControlledVoc getBestSpeciesMatch(ArrayList<String> searchStrings) throws ConversionWarningException { if (searchStrings == null || searchStrings.size() == 0) return ITRDBTaxonConverter.getControlledVocFromCode("UNKN"); HashSet<String> codelist = new HashSet<String>(); for (String str : searchStrings) { if (str == null) continue; if (str.length() == 0) continue; if (!getNameFromCode(str).equals(str.toUpperCase())) { codelist.add(str); } else if (!getCodeFromName(str).equals(str)) { codelist.add(getCodeFromName(str)); } } if (codelist.size() == 0) { // None of the search strings matched if (searchStrings.size() == 1) { // Only one string passed to this function so just return as an non-standard string return getControlledVocFromName(searchStrings.get(0)); } else { // Multiple strings passed so we have no way of knowing which is valid throw new ConversionWarningException( new ConversionWarning(WarningType.AMBIGUOUS, "Ambiguous taxon information supplied.")); } } else if (codelist.size() == 2 && codelist.contains("UNKN")) { // List contains 2 values, one of which is UNKN. Just remove it and use the other codelist.remove("UNKN"); } else if (codelist.size() > 1) { throw new ConversionWarningException( new ConversionWarning(WarningType.AMBIGUOUS, "Ambiguous taxon information supplied.")); } Iterator<String> itr = codelist.iterator(); return getControlledVocFromCode(itr.next()); }
From source file:pt.lsts.neptus.console.plugins.AirOSPeers.java
@Periodic private void update() { if (System.currentTimeMillis() - lastUpdateMillis < seconds * 1000) return;//from w ww. j a va 2 s .com lastUpdateMillis = System.currentTimeMillis(); Future<String> result = SSHUtil.exec(host, port, credentials.getUsername(), credentials.getPassword(), "wstalist"); try { String json = result.get(5, TimeUnit.SECONDS); if (logToDisk) { DevDataText txt = new DevDataText(); txt.setValue(json); txt.setSrcEnt(ImcMsgManager.getManager().getEntityId()); txt.setSrc(ImcMsgManager.getManager().getLocalId().intValue()); LsfMessageLogger.log(txt); } HashSet<String> series = new HashSet<>(); for (Object o : tsc.getSeries()) { TimeSeries tseries = (TimeSeries) o; series.add("" + tseries.getKey()); } for (Station station : new StationList(json).stations) { series.remove(nameOf(station)); process(station); } for (String name : series) { TimeSeries ts = tsc.getSeries(name); if (ts != null) ts.addOrUpdate(new Millisecond(new Date(System.currentTimeMillis())), null); } } catch (TimeoutException timeout) { NeptusLog.pub().error("Timeout while trying to connect to " + host + ":" + port); } catch (Exception e) { e.printStackTrace(); NeptusLog.pub().error(e); } }
From source file:org.b3log.latke.plugin.PluginManager.java
/** * Updates the specified plugin.// w w w .j a v a2 s . c o m * * @param plugin the specified plugin */ public void update(final AbstractPlugin plugin) { final String rendererId = plugin.getRendererId(); HashMap<String, HashSet<AbstractPlugin>> holder = pluginCache.get(PLUGIN_CACHE_NAME); if (null == holder) { LOGGER.info("Plugin cache miss, reload"); load(); holder = pluginCache.get(PLUGIN_CACHE_NAME); if (null == holder) { throw new IllegalStateException("Plugin cache state error!"); } } final HashSet<AbstractPlugin> set = holder.get(rendererId); // Refresh set.remove(plugin); set.add(plugin); plugin.changeStatus(); pluginCache.put(PLUGIN_CACHE_NAME, holder); }
From source file:edu.tum.cs.conqat.quamoco.qiesl.QIESLEngine.java
/** * @param expression/* www. ja v a 2 s .c o m*/ * @param mandatoryVariables * @param nameMapping * @param usedTechnicalNames * @throws QIESLException */ private void checkMandatoryVariables(String expression, Map<String, Object> mandatoryVariables, Map<String, String> nameMapping, HashSet<String> usedTechnicalNames) throws QIESLException { HashSet<String> unusedModelVariables = new HashSet<String>(mandatoryVariables.keySet()); for (String technicalName : usedTechnicalNames) { unusedModelVariables.remove(nameMapping.get(technicalName)); } if (!unusedModelVariables.isEmpty() && !usedTechnicalNames.contains(ALL_IMPACTS_AND_REFINEMENTS_LITERAL)) { throw new QIESLException("Expression " + expression + " does not use mandatory variables: " + StringUtils.concat(unusedModelVariables, ", ")); } }
From source file:thingynet.hierarchy.HierarchyTest.java
@Test public void getDescendantsWithLevelShouldReturnExpectedHierarchies() { Hierarchy parent = hierarchyService.createRoot(PARENT, null); Hierarchy child = hierarchyService.createChild(parent, CHILD, null); hierarchyService.createChild(parent, SIBLING, null); Hierarchy grandChild = hierarchyService.createChild(child, GRAND_CHILD, null); Hierarchy greatGrandChild = hierarchyService.createChild(grandChild, GREAT_GRAND_CHILD, null); hierarchyService.createChild(greatGrandChild, CHILD, null); HashSet<String> expectedIds = new HashSet<>(); expectedIds.add(grandChild.getPath()); expectedIds.add(greatGrandChild.getPath()); Iterable<Hierarchy> actual = hierarchyService.getDescendants(child, 2); while (actual.iterator().hasNext()) { Hierarchy descendant = actual.iterator().next(); assertThat(expectedIds.remove(descendant.getPath()), is(true)); }//ww w. j a v a 2 s .com assertThat(expectedIds.size(), is(0)); }
From source file:voldemort.NamedZone.java
public ClusterBuilder verify() throws Exception { // Verify that no zone has an unknown zone id for (Zone zone : cluster.getZones()) { if (NamedZone.getById(zone.getId()) == null) throw new Exception("Zone " + zone.getId() + " has unexpected zone id"); }/*www . ja v a2 s. co m*/ // Verify that no zone has duplicates in its proximity list for (Zone zone : cluster.getZones()) { HashSet<Integer> seenProximates = new HashSet<Integer>(); for (Integer proxZoneId : zone.getProximityList()) { Integer id = new Integer(proxZoneId); if (seenProximates.contains(id)) throw new Exception("Zone " + zone.getId() + " has duplicate proximate " + proxZoneId); seenProximates.add(id); } } // Verify that no zone is recorded as proximate to itself for (Zone zone : cluster.getZones()) { for (Integer proxZoneId : zone.getProximityList()) { if (proxZoneId == zone.getId()) throw new Exception("Zone " + zone.getId() + " is proximate to itself"); } } // Verify that each zone is proximate to all the other zones // and only to listed zones HashSet<Integer> seenZones = new HashSet<Integer>(); for (Zone zone : cluster.getZones()) seenZones.add(new Integer(zone.getId())); for (Zone zone : cluster.getZones()) { HashSet<Integer> expectProxes = (HashSet<Integer>) seenZones.clone(); expectProxes.remove(new Integer(zone.getId())); for (Integer proxZoneId : zone.getProximityList()) { Integer id = new Integer(proxZoneId); if (!expectProxes.contains(id)) throw new Exception("Zone " + zone.getId() + " has unknown proximate zone " + proxZoneId); expectProxes.remove(id); } if (expectProxes.size() > 0) { StringBuffer buf = new StringBuffer(); for (Integer id : expectProxes) buf.append(" ").append(id); throw new Exception("Zone " + zone.getId() + " is missing proximates to " + buf); } } return this; }
From source file:edu.cornell.mannlib.vitro.webapp.reasoner.ABoxRecomputer.java
private Set<String> getSameAsIndividuals(String individualURI) { HashSet<String> sameAsInds = new HashSet<String>(); sameAsInds.add(individualURI);// w w w .j av a 2 s.com getSameAsIndividuals(individualURI, sameAsInds); sameAsInds.remove(individualURI); return sameAsInds; }
From source file:com.google.code.maven.plugin.http.client.transformer.JiraRssLinkedIssuesEnricher.java
private void enrich(final BufferedWriter writer, final HashSet<String> linkedIssues, final int depth) throws ClientProtocolException, IOException { // removes duplicates for (String jira : rssIssues) { linkedIssues.remove(jira); }//from w w w .ja va 2 s .c o m // request for jira missing in the rss for (final String issue : linkedIssues) { remaining.incrementAndGet(); asyncTaskExecutor.execute(new Runnable() { public void run() { try { rssIssues.add(issue); String content = queryForJira(issue); if (content != null) { synchronized (writer) { writer.write(content); writer.newLine(); writer.flush(); } log.warn("issue [" + issue + "] added"); if (depth > 0) { enrich(writer, inspectItem(content), depth - 1); } } else { log.warn("issue [" + issue + "] not found"); } } catch (MojoExecutionException e) { log.warn("issue [" + issue + "] not found"); } catch (ClientProtocolException e) { log.warn("issue [" + issue + "] not found"); } catch (IOException e) { log.warn("issue [" + issue + "] not found"); } remaining.decrementAndGet(); } }); } }