List of usage examples for java.util HashSet add
public boolean add(E e)
From source file:edu.utexas.cs.tactex.interfaces.TariffOptimizerBase.java
/** * /* ww w .j a v a 2 s. com*/ * @param suggestedSpecs */ private void removeTmpSpecsFromRepo(List<TariffSpecification> suggestedSpecs) { log.info("removing temporary specs from repo"); HashSet<TariffSpecification> specsToRemove = new HashSet<TariffSpecification>(); for (TariffSpecification spec : suggestedSpecs) { specsToRemove.add(spec); } tariffRepoMgr.removeTmpSpecsFromRepo(specsToRemove); }
From source file:com.flipkart.flux.representation.StateMachinePersistenceService.java
/** * Converts state definition to state domain object. * @param stateDefinition//w ww . j a v a2 s .c o m * @return state */ private State convertStateDefinitionToState(StateDefinition stateDefinition) { try { Set<EventDefinition> eventDefinitions = stateDefinition.getDependencies(); HashSet<String> events = new HashSet<>(); if (eventDefinitions != null) { for (EventDefinition e : eventDefinitions) { events.add(e.getName()); } } State state = new State(stateDefinition.getVersion(), stateDefinition.getName(), stateDefinition.getDescription(), stateDefinition.getOnEntryHook(), stateDefinition.getTask(), stateDefinition.getOnExitHook(), events, stateDefinition.getRetryCount(), stateDefinition.getTimeout(), stateDefinition.getOutputEvent() != null ? objectMapper.writeValueAsString(stateDefinition.getOutputEvent()) : null, Status.initialized, null, 0l); return state; } catch (Exception e) { throw new IllegalRepresentationException("Unable to create state domain object", e); } }
From source file:edu.stanford.junction.provider.xmpp.JunctionProvider.java
private synchronized XMPPConnection getXMPPConnection(XMPPSwitchboardConfig config, String roomid) throws JunctionException { final CountDownLatch waitForConnect = new CountDownLatch(1); ConnectionThread t = new ConnectionThread(config, waitForConnect); t.start();//from w w w . j a v a 2s . co m boolean timedOut = false; try { timedOut = !(waitForConnect.await(config.connectionTimeout, TimeUnit.MILLISECONDS)); } catch (InterruptedException e) { throw new JunctionException("Interrupted while waiting for connection."); } if (timedOut) { System.out.println("Connection timed out after " + config.connectionTimeout + " milliseconds."); t.interrupt(); // Thread may still be looping... String msg = "Connection attempt failed to complete within provided timeout of " + config.connectionTimeout + " milliseconds."; throw new JunctionException(msg, new ConnectionTimeoutException(msg)); } if (t.success) { if (DBG) System.out.println("Connection succeeded."); sConnections.add(t.connection); HashSet<String> set = new HashSet<String>(); set.add(roomid); sConnectionSessions.add(set); return t.connection; } else { if (t.failureReason != null) { throw new JunctionException("Connection attempt failed.", t.failureReason); } else { throw new JunctionException("Connection attempt failed for unknown reason.", t.failureReason); } } }
From source file:eionet.cr.web.util.JstlFunctions.java
/** * * @param coll//from w ww. j a v a2 s . c o m * @param separator * @param sort * @param max * @return */ public static String joinCollection(Collection coll, char separator, boolean sort, int max) { if (coll == null || coll.isEmpty()) { return ""; } // First, convert the collection objects to set (i.e. excluding duplicates) of strings, using every object's toString(), // or if the object is ObjectDTO, then special treatment. HashSet<String> set = new HashSet<String>(); for (Object object : coll) { if (object != null) { String str = null; if (object instanceof ObjectDTO) { ObjectDTO objectDTO = (ObjectDTO) object; str = objectDTO.getValue(); if (!objectDTO.isLiteral()) { str = URIUtil.extractURILabel(str, str); } } else { str = object.toString(); } if (StringUtils.isNotBlank(str)) { set.add(str); } } } // If set empty, then return. if (set.isEmpty()) { return ""; } // Now convert the set to list. List<String> list = new ArrayList<String>(set); // If sorting requested, then do so. if (sort) { Collections.sort(list); } // Get first "max" elements if max is > 0 and smaller than list size if (max > 0 && max < list.size()) { list = list.subList(0, max); list.add("..."); } // Finally, join the result by separator. return StringUtils.join(list, separator); }
From source file:org.jasig.portlet.proxy.mvc.portlet.gateway.GatewayPortletController.java
@PostConstruct private void validateGatewayEntries() { HashSet<GatewayEntry> set = new HashSet<GatewayEntry>(); for (GatewayEntry entry : gatewayEntries) { if (!set.add(entry)) { throw new InvalidPropertyException(GatewayEntry.class, "name", "Error initializing Gateway Entries, multiple entries with name " + entry.getName()); }/*from w w w .jav a 2s.co m*/ } }
From source file:functionaltests.execremote.TestExecRemote.java
private void scriptOnNodeSource(String nsName, HashSet<String> nodesUrls) throws Exception { RMTHelper.log("Test 6 - Execute script on a specified nodesource name"); SimpleScript script = new SimpleScript(TestExecRemote.simpleScriptContent, "javascript"); HashSet<String> targets = new HashSet<>(1); targets.add(nsName); List<ScriptResult<Object>> results = rmHelper.getResourceManager().executeScript(script, TargetType.NODESOURCE_NAME.toString(), targets); assertEquals("The size of result list must equal to size of nodesource", nodesUrls.size(), results.size()); for (ScriptResult<Object> res : results) { Throwable exception = res.getException(); if (exception != null) { RMTHelper.log("An exception occured while executing the script remotely:"); exception.printStackTrace(System.out); }//from www .java 2s . c o m assertNull("No exception must occur", exception); } }
From source file:functionaltests.execremote.TestExecRemote.java
private void scriptOnHost(String hostname) throws Exception { RMTHelper.log("Test 7 - Execute script with hostname as target"); SimpleScript script = new SimpleScript(TestExecRemote.simpleScriptContent, "javascript"); HashSet<String> targets = new HashSet<>(1); targets.add(hostname); List<ScriptResult<Object>> results = rmHelper.getResourceManager().executeScript(script, TargetType.HOSTNAME.toString(), targets); assertEquals("The size of result list must equal to 1, if a hostname is specified a single node must be " + "selected", results.size(), 1); for (ScriptResult<Object> res : results) { Throwable exception = res.getException(); if (exception != null) { RMTHelper.log("An exception occured while executing the script remotely:"); exception.printStackTrace(System.out); }// w w w . ja v a2 s.c o m assertNull("No exception must occur", exception); } }
From source file:com.brightcove.test.upload.MThreeIntegrationTest.java
private Set<Options> optionsToTest() { HashSet<Options> opts = new HashSet<Options>(); Options uploadOpts = new Options(); uploadOpts.setMBR(true);/*from w ww . jav a 2s .c o m*/ opts.add(uploadOpts); uploadOpts = new Options(); uploadOpts.setMBR(true); uploadOpts.setPreserveSource(true); opts.add(uploadOpts); uploadOpts = new Options(); uploadOpts.setMBR(false); opts.add(uploadOpts); uploadOpts = new Options(); uploadOpts.setMBR(true); uploadOpts.setTargetCodec("FLV"); opts.add(uploadOpts); uploadOpts = new Options(); uploadOpts.setTargetCodec("FLV"); uploadOpts.setMBR(false); opts.add(uploadOpts); return opts; }
From source file:com.liveramp.hank.storage.curly.AbstractCurlyPartitionUpdater.java
private Set<DomainVersion> detectCachedVersions(SortedSet<CueballFilePath> cueballCachedFiles, SortedSet<CurlyFilePath> curlyCachedFiles) throws IOException { // Record in a set all cached Cueball versions HashSet<Integer> cachedCueballVersions = new HashSet<Integer>(); for (CueballFilePath cueballCachedFile : cueballCachedFiles) { cachedCueballVersions.add(cueballCachedFile.getVersion()); }//from www. j a va2s . co m // Compute cached Curly versions Set<DomainVersion> cachedVersions = new HashSet<DomainVersion>(); for (CurlyFilePath curlyCachedFile : curlyCachedFiles) { // Check that the corresponding Cueball version is also cached if (cachedCueballVersions.contains(curlyCachedFile.getVersion())) { DomainVersion version = domain.getVersion(curlyCachedFile.getVersion()); if (version != null) { cachedVersions.add(version); } } } return cachedVersions; }
From source file:edu.mayo.cts2.framework.plugin.service.bioportal.profile.resolvedvalueset.BioportalRestResolvedValueSetResolutionService.java
@Override public Set<? extends PropertyReference> getSupportedSearchReferences() { HashSet<PropertyReference> returnSet = new HashSet<PropertyReference>(); returnSet.add(StandardModelAttributeReference.RESOURCE_SYNOPSIS.getPropertyReference()); return returnSet; }