List of usage examples for java.util Set clear
void clear();
From source file:com.arcbees.gwtp.upgrader.AbstractReWriter.java
protected Set<String> getFullyQualifiedName(String name) { Set<String> result = new HashSet<>(); if (imports != null) { for (ImportDeclaration id : imports) { String iName = id.getName().toString(); if (id.isAsterisk()) { result.add(iName.replace("*", name)); } else { if (name.contains(".")) { String[] names = name.split("\\."); if (iName.endsWith("." + names[0]) || iName.equals(names[0])) { for (int i = 1; i < names.length; i++) { iName = iName + "." + names[i]; }/* www .j a v a2s. c o m*/ result.clear(); result.add(iName); return result; } } else if (iName.endsWith("." + name) || iName.equals(name)) { result.clear(); result.add(iName); return result; } } } } if (result.isEmpty()) { result.add(name); } return result; }
From source file:org.apache.tika.eval.ComparerBatchTest.java
@Test public void testSimpleDBWriteAndRead() throws Exception { Set<String> set = new HashSet<>(); //filenames/* ww w . j a v a 2s . c om*/ List<String> list = getColStrings(Cols.FILE_NAME.name(), ExtractComparer.PROFILES_A.getName(), ""); assertEquals(7, list.size()); assertTrue(list.contains("file1.pdf")); //container ids in comparisons table list = getColStrings(Cols.CONTAINER_ID.name(), ExtractComparer.COMPARISON_CONTAINERS.getName(), ""); assertEquals(10, list.size()); set.clear(); set.addAll(list); assertEquals(10, set.size()); /* //ids in comparisons table list = getColStrings(AbstractProfiler.HEADERS.ID.name(), compTable,""); assertEquals(9, list.size()); set.clear(); set.addAll(list); assertEquals(9, set.size());*/ }
From source file:com.projity.server.data.linker.Linker.java
public void addOutline(Node root) { final Set endVoids = new HashSet(); //lastIndex=0; getHierarchy().visitAll(root, true, new Closure() { //int tmpIndex=0; public void execute(Object arg) { Node node = (Node) arg; Object nodeImpl = node.getImpl(); if (!(nodeImpl instanceof Assignment)) { // if (!node.isVoid()) lastIndex=tmpIndex; // tmpIndex++; if (node.isVoid()) endVoids.add(node);/*from w w w .j a v a2 s .co m*/ else endVoids.clear(); } } }); getHierarchy().visitAllLevelOrder(root, true, new Closure() { Node thisParent = null; long position = 0; //int index=0; public void execute(Object arg) { //if (index++>lastIndex) return; Node node = (Node) arg; if (endVoids.contains(node)) return; Object nodeImpl = node.getImpl(); if (!(nodeImpl instanceof Assignment)) { Node currentParent = getHierarchy().getParent(node); if (currentParent != null && currentParent.isRoot()) currentParent = null; //for compatibility if (thisParent != currentParent) { thisParent = currentParent; position = 0; } if (node.isVoid() || addOutlineElement(nodeImpl, (thisParent == null) ? null : thisParent.getImpl(), position)) position++; //skip voids but increment position } } }); }
From source file:hydrograph.ui.propertywindow.widgets.dialog.hiveInput.HiveFieldDialogHelper.java
/** * /*from w w w .j a v a 2s . co m*/ * @param keyValues * @param keyList * @param incomingList2 */ private void checkAndAdjustRowsColumns(List<HivePartitionFields> keyValues, List<String> keyList, List<InputHivePartitionColumn> incomingList) { Set<String> colNames = new HashSet<>(); for (int i = 0; i < incomingList.size(); i++) { colNames = extractColumnNamesFromObject(incomingList.get(i), colNames); List<String> notAvailableFields = ListUtils.subtract(keyList, new ArrayList<>(colNames)); if (null != notAvailableFields && notAvailableFields.size() > 0) { for (String fieldName : notAvailableFields) { keyValues.get(i).getRowFields().add(keyList.indexOf(fieldName), ""); } } colNames.clear(); } }
From source file:com.pryzach.suggestions.service.impl.SuggestionServiceImplTest.java
private void performanceTest(long amount) { SuggestionService suggestionService = SuggestionFactory.getSuggestionService(); String[] suggestedWordsArray; String[] suggestedNextLettersArray; List<String> selectors = new ArrayList<>(); String wordString;/*from w w w. ja va 2 s . co m*/ long startTime = new Date().getTime(); Set<Word> words = new HashSet<>(); for (int i = 0; i < amount; i++) { wordString = RandomStringUtils.randomAlphabetic(randomInt(3, 10)); words.add(new Word(wordString, randomInt(1, 100))); if (randomInt(0, 5) == 2 && wordString.length() > 3) { selectors.add(wordString.substring(0, wordString.length() - 3)); } } suggestionService.addWords(words); words.clear(); System.out.println( "Added to service [" + amount + "] and took [" + (new Date().getTime() - startTime) + " ms]"); int i = 0; startTime = new Date().getTime(); for (String selector : selectors) { suggestedWordsArray = suggestionService.suggest(selector, 10); // uncomment below to visually confirm matches // if (i % 1000 == 0) System.out.println("Matched [" + selector + "] to [" + result.get("suggestions") + "]"); Assert.assertTrue(suggestedWordsArray.length >= 1); i++; } System.out.println( "Matched: [" + selectors.size() + "] and took [" + (new Date().getTime() - startTime) + " ms] [" + new BigDecimal(((double) new Date().getTime() - startTime) / selectors.size()) .setScale(5, BigDecimal.ROUND_HALF_UP).toString() + " ms] per match and [" + Math.round(1000 / (((double) new Date().getTime() - startTime) / selectors.size())) + " words] per second"); }
From source file:org.apache.hadoop.hdfs.server.namenode.TestReplicationPolicy.java
/** * Test NetworkTopology.chooseRack(Set<String>) *///w ww .j a v a 2 s .c om public void testChooseRack() throws Exception { // for this test create 100 datanodes Random r = new Random(); Collection<String> locations = new HashSet<String>(); for (int i = 0; i < NUM_OF_DATANODES; i++) { // remove original datanodes cluster.remove(dataNodes[i]); } dataNodes = new DatanodeDescriptor[100]; for (int i = 0; i < 100; i++) { String did = "h" + i + ":5020"; String loc = "/d" + r.nextInt(5) + "/r" + r.nextInt(5); locations.add(loc); dataNodes[i] = new DatanodeDescriptor(new DatanodeID(did), loc); // add new datanodes cluster.add(dataNodes[i]); } LOG.info("Locations : " + locations.size() + " racks in total"); int numOfDatanodes = dataNodes.length; Set<String> excludedRacks = new HashSet<String>(); // randomly exclude racks for (int i = 0; i < 20; i++) { excludedRacks.clear(); int numToExclude = r.nextInt(locations.size() - 1) + 1; LOG.info("Iteration : " + i + " will exclude: " + numToExclude); // exclude a random number of racks while (excludedRacks.size() < numToExclude) { excludedRacks.add(dataNodes[r.nextInt(numOfDatanodes)].getNetworkLocation()); } LOG.info("Excluded racks: " + excludedRacks); String chosenNode = cluster.chooseRack(excludedRacks); LOG.info("Chosen node: " + chosenNode + " should not be null"); // chosen node cannot be in the excluded list for (String exluded : excludedRacks) { assertFalse(exluded.equals(chosenNode)); } // if the number of locations in the excluded list was less that the // total number of location, then we should not get null if (locations.size() > excludedRacks.size()) { assertNotNull(chosenNode); } } // exclude all nodes, and we should get null LOG.info("Excluding all nodes"); excludedRacks.clear(); for (int n = 0; n < numOfDatanodes; n++) { excludedRacks.add(dataNodes[n].getNetworkLocation()); } String chosenNode = cluster.chooseRack(excludedRacks); LOG.info("Chosen node: " + chosenNode + " should be null"); assertNull(chosenNode); }
From source file:org.apache.mahout.freqtermsets.convertors.integer.IntegerStringOutputConverter.java
@Override public void collect(Integer key, List<Pair<List<Integer>, Long>> value) throws IOException { String stringKey = featureReverseMap.get(key); // YA: Detect langauge for attribute by voting from different patterns // String langSure = null; int patternWords; // int totalSupport = 0; Set<String> hashtags = Sets.<String>newHashSet(); HashMap<String, MutableLong> langVotes = Maps.<String, MutableLong>newHashMap(); StringBuilder patStr = new StringBuilder(); // END langDetect List<Pair<List<String>, Long>> stringValues = Lists.newArrayList(); for (Pair<List<Integer>, Long> e : value) { List<String> pattern = Lists.newArrayList(); if (DO_LANG_DETECTION) { // YA langDetect // totalSupport += itemSet.support(); patStr.setLength(0);//from w w w.java 2s. c o m hashtags.clear(); patternWords = 0; char k0 = stringKey.charAt(0); if (k0 == '#') { if (repeatHashTag) hashtags.add(stringKey.substring(1)); } else if (!(k0 == '@' || stringKey.equals(TokenIterator.URL_PLACEHOLDER))) { patStr.append(stringKey); ++patternWords; } // END langDetect } for (Integer i : e.getFirst()) { String token = featureReverseMap.get(i); pattern.add(token); if (DO_LANG_DETECTION) { // YA langDetect char ch0 = token.toString().charAt(0); if (ch0 == '#') { if (repeatHashTag) hashtags.add(token.substring(1)); } else if (!(ch0 == '@' || stringKey.equals(token) || token.equals(TokenIterator.URL_PLACEHOLDER))) { if (hashtags.contains(token)) { hashtags.remove(token); // This is the extra token that is returned after the hashtag // Hashtags are no good for language detection // if (DIGITS_PATTERN.matcher(token).matches()) { // contains digits so it is not a proper word // TODO: any other heuristics continue; } patStr.append(' ').append(token); ++patternWords; } if (patternWords >= minWordsForLangDetect) { String lang = langCat.categorize(patStr.toString()); if (!langVotes.containsKey(lang)) { langVotes.put(lang, new MutableLong(0)); } MutableLong voteCnt = langVotes.get(lang); voteCnt.add(e.getSecond()); log.info("Detected language for attribute '{}' to be '{}'", stringKey, lang); } // END langDetect } } stringValues.add(new Pair<List<String>, Long>(pattern, e.getSecond())); } // YA langDetect // Vote for one language // double maxVote = 1e-9; // List<String> langCandidates = Lists.newLinkedList(); // // for (Entry<String, MutableLong> voteEntry : langVotes.entrySet()) { // double ratio = voteEntry.getValue().doubleValue() / maxVote; // if (ratio >= superiorityRatio) { // langCandidates.clear(); // } // // if (ratio > superiorityRatioRecip) { // langCandidates.add(voteEntry.getKey()); // } // // if (ratio > 1.0) { // maxVote = voteEntry.getValue().intValue(); // } // } // // if (langCandidates.size() > 0) { // langSure = langCandidates.get(rand.nextInt(langCandidates.size())); // } else { // log.warn("Language Candidates is empty! Using 'unknown'. freqPatterns: {}, langVotes: {}", // frequentPatterns.getHeap(), // langVotes); // langSure = "unknown"; // } // langvotes will be empty anyway: if(DO_LANG_DETECTION) for (Entry<String, MutableLong> voteEntry : langVotes.entrySet()) { stringValues.add(new Pair<List<String>, Long>( Arrays.asList(stringKey, AggregatorReducer.METADATA_PREFIX + LANGUAGE_ITEMSET_TOKEN, AggregatorReducer.METADATA_PREFIX + voteEntry.getKey()), voteEntry.getValue().longValue())); } // END YA langDetect collector.collect(new Text(stringKey), new TopKStringPatterns(stringValues)); }
From source file:it.polimi.modaclouds.monitoring.monitoring_manager.CSPARQLEngineManager.java
private void removeObservers(MonitoringRule rule) throws ServerErrorException, ObserverErrorException { for (Action action : rule.getActions().getActions()) { if (action.getName().equals(OutputMetric.class.getSimpleName())) { String metric = Util.getParameterValue(OutputMetric.metric, action).toLowerCase(); Set<Observer> observers = observersByMetric.get(metric); if (observers != null) { for (Observer observer : observers) { csparqlAPI.deleteObserver(observer.getUri()); }//from w w w . j av a 2s .com observers.clear(); } } } }
From source file:com.alibaba.jstorm.task.master.GrayUpgradeHandler.java
private void pickWorkersToUpgrade(GrayUpgradeConfig grayUpgradeConf, Set<String> upgradedWorkers) throws Exception { Set<String> remainingSlots = new HashSet<>(); remainingSlots.addAll(this.totalWorkers); remainingSlots.removeAll(upgradedWorkers); int workerNum = grayUpgradeConf.getWorkerNum(); String component = grayUpgradeConf.getComponent(); Set<String> workers = grayUpgradeConf.getWorkers(); TopologyContext topologyContext = tmContext.getContext(); if (workers.size() > 0) { LOG.info("Upgrading specified workers:{}", workers); for (String worker : workers) { if (remainingSlots.contains(worker)) { addUpgradingSlot(worker); } else { LOG.warn("Worker {} is not in topology worker list or has been upgraded already, skip.", worker);/*from ww w. j a va2 s . co m*/ } } // reset workers workers.clear(); } else if (!StringUtils.isBlank(component)) { LOG.info("Upgrading workers of component:{}", component); List<Integer> tasks = topologyContext.getComponentTasks(component); if (tasks == null) { LOG.error("Failed to get tasks for component {}, maybe it's a wrong component name.", component); return; } Set<String> slots = new HashSet<>(); for (Integer task : tasks) { String worker = this.taskToHostPort.get(task); if (worker != null && remainingSlots.contains(worker)) { slots.add(worker); } } LOG.info("Available workers of component {}: {}", component, slots); pickUpgradingSlots(slots, workerNum > 0 ? workerNum : slots.size()); // reset component if (workerNum == 0 || workerNum >= slots.size()) { grayUpgradeConf.setComponent(null); } } else if (workerNum > 0) { LOG.info("Upgrading workers at random"); pickUpgradingSlots(remainingSlots, workerNum); } }
From source file:com.kalessil.phpStorm.phpInspectionsEA.inspectors.apiUsage.strings.CascadeStringReplacementInspector.java
@Override @NotNull// w ww. j a v a2s . c o m public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) { return new BasePhpElementVisitor() { @Override public void visitPhpReturn(@NotNull PhpReturn returnStatement) { final FunctionReference functionCall = this.getFunctionReference(returnStatement); if (functionCall != null) { this.analyze(functionCall, returnStatement); } } @Override public void visitPhpAssignmentExpression(@NotNull AssignmentExpression assignmentExpression) { final FunctionReference functionCall = this.getFunctionReference(assignmentExpression); if (functionCall != null) { this.analyze(functionCall, assignmentExpression); } } private void analyze(@NotNull FunctionReference functionCall, @NotNull PsiElement expression) { final PsiElement[] arguments = functionCall.getParameters(); if (arguments.length == 3) { /* case: cascading replacements */ final AssignmentExpression previous = this.getPreviousAssignment(expression); final FunctionReference previousCall = previous == null ? null : this.getFunctionReference(previous); if (previousCall != null) { final PsiElement transitionVariable = previous.getVariable(); if (transitionVariable instanceof Variable && arguments[2] instanceof Variable) { final Variable callSubject = (Variable) arguments[2]; final Variable previousVariable = (Variable) transitionVariable; final PsiElement callResultStorage = expression instanceof AssignmentExpression ? ((AssignmentExpression) expression).getVariable() : callSubject; if (callResultStorage != null && callSubject.getName().equals(previousVariable.getName()) && OpenapiEquivalenceUtil.areEqual(transitionVariable, callResultStorage)) { holder.registerProblem(functionCall, messageCascading, new MergeStringReplaceCallsFix(functionCall, previousCall, USE_SHORT_ARRAYS_SYNTAX)); } } } /* case: nested replacements */ this.checkNestedCalls(arguments[2], functionCall); /* case: search/replace simplification */ final PsiElement replace = arguments[1]; if (replace instanceof ArrayCreationExpression) { this.checkForSimplification((ArrayCreationExpression) replace); } else if (replace instanceof StringLiteralExpression) { final PsiElement search = arguments[0]; if (search instanceof ArrayCreationExpression) { this.checkForSimplification((ArrayCreationExpression) search); } } } } private void checkForSimplification(@NotNull ArrayCreationExpression candidate) { final Set<String> replacements = new HashSet<>(); for (final PsiElement oneReplacement : candidate.getChildren()) { if (oneReplacement instanceof PhpPsiElement) { final PhpPsiElement item = ((PhpPsiElement) oneReplacement).getFirstPsiChild(); if (!(item instanceof StringLiteralExpression)) { replacements.clear(); return; } replacements.add(item.getText()); } } if (replacements.size() == 1) { holder.registerProblem(candidate, messageReplacements, ProblemHighlightType.WEAK_WARNING, new SimplifyReplacementFix(replacements.iterator().next())); } replacements.clear(); } private void checkNestedCalls(@NotNull PsiElement callCandidate, @NotNull FunctionReference parentCall) { if (OpenapiTypesUtil.isFunctionReference(callCandidate)) { final FunctionReference call = (FunctionReference) callCandidate; final String functionName = call.getName(); if (functionName != null && functionName.equals("str_replace")) { holder.registerProblem(callCandidate, messageNesting, new MergeStringReplaceCallsFix(parentCall, call, USE_SHORT_ARRAYS_SYNTAX)); } } } @Nullable private FunctionReference getFunctionReference(@NotNull AssignmentExpression assignment) { FunctionReference result = null; final PsiElement value = ExpressionSemanticUtil .getExpressionTroughParenthesis(assignment.getValue()); if (OpenapiTypesUtil.isFunctionReference(value)) { final String functionName = ((FunctionReference) value).getName(); if (functionName != null && functionName.equals("str_replace")) { result = (FunctionReference) value; } } return result; } @Nullable private FunctionReference getFunctionReference(@NotNull PhpReturn phpReturn) { FunctionReference result = null; final PsiElement value = ExpressionSemanticUtil .getExpressionTroughParenthesis(ExpressionSemanticUtil.getReturnValue(phpReturn)); if (OpenapiTypesUtil.isFunctionReference(value)) { final String functionName = ((FunctionReference) value).getName(); if (functionName != null && functionName.equals("str_replace")) { result = (FunctionReference) value; } } return result; } @Nullable private AssignmentExpression getPreviousAssignment(@NotNull PsiElement returnOrAssignment) { /* get previous non-comment, non-php-doc expression */ PsiElement previous = null; if (returnOrAssignment instanceof PhpReturn) { previous = ((PhpReturn) returnOrAssignment).getPrevPsiSibling(); } else if (returnOrAssignment instanceof AssignmentExpression) { previous = returnOrAssignment.getParent().getPrevSibling(); } while (previous != null && !(previous instanceof PhpPsiElement)) { previous = previous.getPrevSibling(); } while (previous instanceof PhpDocComment) { previous = ((PhpDocComment) previous).getPrevPsiSibling(); } /* grab the target assignment */ final AssignmentExpression result; if (previous != null && previous.getFirstChild() instanceof AssignmentExpression) { result = (AssignmentExpression) previous.getFirstChild(); } else { result = null; } return result; } }; }