List of usage examples for java.util Set clear
void clear();
From source file:org.jenkinsci.plugins.todos.TodosChartBuilder.java
/** * Get all valid actions and all patterns defined through all builds. * //from w w w .jav a 2s.c om * @param lastAction * the last action * @param outAllValidActions * all valid actions with statistics defined, output parameter * @param outAllPatterns * all patterns defined through all builds */ private static void getActionsAndPatterns(TodosBuildAction lastAction, List<TodosBuildAction> outAllValidActions, Set<String> outAllPatterns) { outAllValidActions.clear(); outAllPatterns.clear(); TodosBuildAction action = lastAction; while (action != null) { if (action.getStatistics() != null) { for (TodosPatternStatistics statistics : action.getStatistics().getPatternStatistics()) { outAllPatterns.add(statistics.getPattern()); } outAllValidActions.add(action); } action = action.getPreviousAction(); } }
From source file:org.jboss.capedwarf.connect.server.HttpHeaders.java
/** * Cleanup.//from w w w .j a v a 2 s . c o m */ public static void clear() { Set<Header> set = tlh.get(); if (set != null) { tlh.remove(); set.clear(); } }
From source file:net.landora.video.utils.UIUtils.java
public static MultiValueMap createCompleteContextByClass(Collection<?> context) { Collection<Object> fullContext = UIUtils.createCompleteContext(context); MultiValueMap valuesByClass = new MultiValueMap(); Set<Class<?>> allClasses = new HashSet<Class<?>>(); for (Object obj : fullContext) { Class<?> clazz = obj.getClass(); allClasses.clear(); while (clazz != null) { allClasses.add(clazz);// w ww .j a v a 2s . c om allClasses.addAll(Arrays.asList(clazz.getInterfaces())); clazz = clazz.getSuperclass(); } for (Class<?> c : allClasses) { valuesByClass.put(c, obj); } } return valuesByClass; }
From source file:it.jnrpe.client.JNRPEClient.java
/** * Prints usage instrunctions and, eventually, an error message about the * latest execution./* ww w .ja v a2s.com*/ * * @param e * The exception error */ @SuppressWarnings("unchecked") private static void printUsage(final Exception e) { printVersion(); StringBuilder sbDivider = new StringBuilder("="); if (e != null) { System.out.println(e.getMessage() + "\n"); } HelpFormatter hf = new HelpFormatter(); while (sbDivider.length() < hf.getPageWidth()) { sbDivider.append('='); } // DISPLAY SETTING Set displaySettings = hf.getDisplaySettings(); displaySettings.clear(); displaySettings.add(DisplaySetting.DISPLAY_GROUP_EXPANDED); displaySettings.add(DisplaySetting.DISPLAY_PARENT_CHILDREN); // USAGE SETTING Set usageSettings = hf.getFullUsageSettings(); usageSettings.clear(); usageSettings.add(DisplaySetting.DISPLAY_PARENT_ARGUMENT); usageSettings.add(DisplaySetting.DISPLAY_ARGUMENT_BRACKETED); usageSettings.add(DisplaySetting.DISPLAY_PARENT_CHILDREN); usageSettings.add(DisplaySetting.DISPLAY_GROUP_EXPANDED); hf.setDivider(sbDivider.toString()); hf.setGroup(configureCommandLine()); hf.print(); }
From source file:com.textocat.textokit.postagger.DictionaryComplianceChecker.java
private static Set<BitSet> selectClosest(final BitSet targetBits, Iterable<BitSet> srcBitSets) { Set<BitSet> result = Sets.newHashSet(); int minDistance = Integer.MAX_VALUE; for (final BitSet srcBits : srcBitSets) { int curDistance = calcDistance(targetBits, srcBits); if (curDistance < minDistance) { result.clear(); result.add(srcBits);//from w ww . j a v a2 s. c o m minDistance = curDistance; } else if (curDistance == minDistance) { result.add(srcBits); } // else curDistance > minDistance => do nothing } return result; }
From source file:org.aksw.simba.cetus.tools.ClassModelCreator.java
public static boolean inferSubClassRelations(Model classModel) { Set<Resource> subClasses = new HashSet<Resource>(); ResIterator resIterator = classModel.listSubjectsWithProperty(RDFS.subClassOf); while (resIterator.hasNext()) { subClasses.add(resIterator.next()); }/*from w w w. ja va 2s. com*/ LOGGER.info("Found " + subClasses.size() + " sub classes."); Queue<Resource> queue = new LinkedList<Resource>(); int count = 0, count2 = 0; Resource resource, next; NodeIterator nodeIterator; Set<Resource> equalClasses = new HashSet<Resource>(); Set<Resource> alreadySeen = new HashSet<Resource>(); for (Resource subClass : subClasses) { equalClasses.clear(); equalClasses.add(subClass); nodeIterator = classModel.listObjectsOfProperty(subClass, OWL.equivalentClass); while (nodeIterator.hasNext()) { equalClasses.add(nodeIterator.next().asResource()); } resIterator = classModel.listSubjectsWithProperty(OWL.equivalentClass, subClass); while (resIterator.hasNext()) { equalClasses.add(resIterator.next()); } for (Resource equalClass : equalClasses) { nodeIterator = classModel.listObjectsOfProperty(equalClass, RDFS.subClassOf); while (nodeIterator.hasNext()) { queue.add(nodeIterator.next().asResource()); } } alreadySeen.clear(); while (!queue.isEmpty()) { resource = queue.poll(); // mark this resource as super class of the sub class classModel.add(subClass, RDFS.subClassOf, resource); ++count2; if (!classModel.contains(resource, RDF.type, RDFS.Class)) { classModel.add(resource, RDF.type, RDFS.Class); } nodeIterator = classModel.listObjectsOfProperty(resource, RDFS.subClassOf); while (nodeIterator.hasNext()) { next = nodeIterator.next().asResource(); if (!alreadySeen.contains(next)) { queue.add(next); alreadySeen.add(next); } } } ++count; if ((count % 100000) == 0) { LOGGER.info("processed " + count + " sub classes."); } } LOGGER.info("Added " + count2 + " properties."); return true; }
From source file:edu.umd.cs.marmoset.utilities.MarmosetUtilities.java
public static <T> Map<T, Boolean> setAsMap(final Set<T> set) { return new Map<T, Boolean>() { @Override//from w w w.j av a 2 s. c o m public void clear() { set.clear(); } @Override public boolean containsKey(Object arg0) { return set.contains(arg0); } @Override public boolean containsValue(Object arg0) { throw new UnsupportedOperationException(); } @Override public Set<java.util.Map.Entry<T, Boolean>> entrySet() { throw new UnsupportedOperationException(); } @Override public Boolean get(Object arg0) { return set.contains(arg0); } @Override public boolean isEmpty() { return set.isEmpty(); } @Override public Set<T> keySet() { return set; } @Override public Boolean put(T arg0, Boolean arg1) { Boolean result = set.contains(arg0); if (arg1) set.add(arg0); else set.remove(arg0); return result; } @Override public void putAll(Map<? extends T, ? extends Boolean> arg0) { throw new UnsupportedOperationException(); } @Override public Boolean remove(Object arg0) { Boolean result = set.contains(arg0); set.remove(arg0); return result; } @Override public int size() { return set.size(); } @Override public Collection<Boolean> values() { throw new UnsupportedOperationException(); } }; }
From source file:org.apache.pulsar.broker.loadbalance.impl.LoadManagerShared.java
public static void applyNamespacePolicies(final ServiceUnitId serviceUnit, final SimpleResourceAllocationPolicies policies, final Set<String> brokerCandidateCache, final Set<String> availableBrokers) { Set<String> primariesCache = localPrimariesCache.get(); primariesCache.clear(); Set<String> secondaryCache = localSecondaryCache.get(); secondaryCache.clear();/* ww w . ja v a2s . co m*/ NamespaceName namespace = serviceUnit.getNamespaceObject(); boolean isIsolationPoliciesPresent = policies.areIsolationPoliciesPresent(namespace); boolean isNonPersistentTopic = (serviceUnit instanceof NamespaceBundle) ? ((NamespaceBundle) serviceUnit).hasNonPersistentTopic() : false; if (isIsolationPoliciesPresent) { log.debug("Isolation Policies Present for namespace - [{}]", namespace.toString()); } for (final String broker : availableBrokers) { final String brokerUrlString = String.format("http://%s", broker); URL brokerUrl; try { brokerUrl = new URL(brokerUrlString); } catch (MalformedURLException e) { log.error("Unable to parse brokerUrl from ResourceUnitId - [{}]", e); continue; } // todo: in future check if the resource unit has resources to take // the namespace if (isIsolationPoliciesPresent) { // note: serviceUnitID is namespace name and ResourceID is // brokerName if (policies.isPrimaryBroker(namespace, brokerUrl.getHost())) { primariesCache.add(broker); if (log.isDebugEnabled()) { log.debug( "Added Primary Broker - [{}] as possible Candidates for" + " namespace - [{}] with policies", brokerUrl.getHost(), namespace.toString()); } } else if (policies.isSecondaryBroker(namespace, brokerUrl.getHost())) { secondaryCache.add(broker); if (log.isDebugEnabled()) { log.debug( "Added Shared Broker - [{}] as possible " + "Candidates for namespace - [{}] with policies", brokerUrl.getHost(), namespace.toString()); } } else { if (log.isDebugEnabled()) { log.debug("Skipping Broker - [{}] not primary broker and not shared" + " for namespace - [{}] ", brokerUrl.getHost(), namespace.toString()); } } } else if (policies.isSharedBroker(brokerUrl.getHost())) { secondaryCache.add(broker); if (log.isDebugEnabled()) { log.debug("Added Shared Broker - [{}] as possible Candidates for namespace - [{}]", brokerUrl.getHost(), namespace.toString()); } } } if (isIsolationPoliciesPresent) { brokerCandidateCache.addAll(primariesCache); if (policies.shouldFailoverToSecondaries(namespace, primariesCache.size())) { log.debug( "Not enough of primaries [{}] available for namespace - [{}], " + "adding shared [{}] as possible candidate owners", primariesCache.size(), namespace.toString(), secondaryCache.size()); brokerCandidateCache.addAll(secondaryCache); } } else { log.debug( "Policies not present for namespace - [{}] so only " + "considering shared [{}] brokers for possible owner", namespace.toString(), secondaryCache.size()); brokerCandidateCache.addAll(secondaryCache); } }
From source file:org.apache.hadoop.raid.StripeReader.java
/** * Build the InputStream arrays from the StripeInfo. * //from w w w .ja v a2 s .c o m * @return * @throws IOException */ public static InputStream[] buildInputsFromStripeInfo(DistributedFileSystem srcFs, FileStatus srcStat, Codec codec, StripeInfo si, long offsetInBlock, long limit, List<Integer> erasedLocations, Set<Integer> locationsToNotRead, ErasureCode code) throws IOException { InputStream[] inputs = new InputStream[codec.stripeLength + codec.parityLength]; boolean redo = false; do { redo = false; locationsToNotRead.clear(); List<Integer> locationsToRead = code.locationsToReadForDecode(erasedLocations); for (int i = 0; i < inputs.length; i++) { boolean isErased = (erasedLocations.indexOf(i) != -1); boolean shouldRead = (locationsToRead.indexOf(i) != -1); try { InputStream stm = null; if (isErased || !shouldRead) { if (isErased) { LOG.info("Location " + i + " is erased, using zeros"); } else { LOG.info("Location " + i + " need not be read, using zeros"); } locationsToNotRead.add(i); stm = new RaidUtils.ZeroInputStream(limit); } else { long blockId; if (i < codec.parityLength) { blockId = si.parityBlocks.get(i).getBlockId(); } else if ((i - codec.parityLength) < si.srcBlocks.size()) { blockId = si.srcBlocks.get(i - codec.parityLength).getBlockId(); } else { LOG.info("Using zeros for location " + i); inputs[i] = new RaidUtils.ZeroInputStream(limit); continue; } LocatedBlockWithFileName lb = srcFs.getClient().getBlockInfo(blockId); if (lb == null) { throw new BlockMissingException(String.valueOf(blockId), "Location " + i + " can not be found. Block id: " + blockId, 0); } else { Path filePath = new Path(lb.getFileName()); FileStatus stat = srcFs.getFileStatus(filePath); long blockSize = stat.getBlockSize(); if (offsetInBlock > blockSize) { stm = new RaidUtils.ZeroInputStream(limit); } else { if (srcFs.exists(filePath)) { long startOffset = getBlockIdInFile(srcFs, filePath, blockId) * blockSize; long offset = startOffset + offsetInBlock; LOG.info("Opening " + lb.getFileName() + ":" + offset + " for location " + i); FSDataInputStream is = srcFs.open(filePath); is.seek(offset); stm = is; } else { LOG.info("Location " + i + ", File " + lb.getFileName() + " does not exist, using zeros"); locationsToNotRead.add(i); stm = new RaidUtils.ZeroInputStream(limit); } } } } inputs[i] = stm; } catch (IOException e) { if (e instanceof BlockMissingException || e instanceof ChecksumException) { erasedLocations.add(i); redo = true; RaidUtils.closeStreams(inputs); break; } else { throw e; } } } } while (redo); assert (locationsToNotRead.size() == codec.parityLength); return inputs; }
From source file:com.mischivous.wormysharpyloggy.wsl.model.Tile.java
/** * Return the specified amount of Tiles using the specified amount of random Tiles * <p>/* w w w . j a v a 2 s.c o m*/ * Create a Set board with the requested amount of Tiles using the * requested amount of random Tiles. The difference will be made up * for by manual selection. * * @param boardSize The size of the board to return * @param randomStarters The number of random Tiles to use when creating the board * @return A Tile array conforming to the given inputs */ @NonNull public static Tile[] GetTilesForBoard(int boardSize, int randomStarters) { if (boardSize != 9) { throw new IllegalArgumentException("Boards must have nine Tiles."); } else if (randomStarters > boardSize) { throw new IllegalArgumentException(String.format("Cannot use %d random starters for Board of size %d.", randomStarters, boardSize)); } else if (randomStarters == 0) { return GetRandomTiles(boardSize); } Set<Tile> maybeBoard = new HashSet<>(boardSize); Set<Tile> starters; do { // Starting with six random Tiles and building the Board // to nine yields a more optimal distribution for normal // and time attack games, which is why I do it here. maybeBoard.clear(); starters = new HashSet<>(Arrays.asList(Tile.GetRandomTiles(randomStarters))); maybeBoard.addAll(starters); // Check for Powerset games so they don't have to go // through the loop. if (maybeBoard.size() == boardSize) { break; } ICombinatoricsVector<Tile> tileVector = Factory.createVector(maybeBoard); Generator<Tile> gen = Factory.createSimpleCombinationGenerator(tileVector, 2); for (ICombinatoricsVector<Tile> v : gen) { Tile t1 = v.getValue(0); Tile t2 = v.getValue(1); Tile t = SetHelper.GetLastTile(t1, t2); if (!maybeBoard.contains(t)) { maybeBoard.add(t); } if (maybeBoard.size() == boardSize) { break; } } // It's possible there is no way to create a Board of // size nine with the selected starters, hence the // redundant checks. } while (maybeBoard.size() != boardSize); return maybeBoard.toArray(new Tile[boardSize]); }