List of usage examples for java.util Set contains
boolean contains(Object o);
From source file:it.cilea.osd.jdyna.web.tag.JDynATagLibraryFunctions.java
public static boolean isContained(Object object, Set list) { return list == null ? false : list.contains(object); }
From source file:com.google.enterprise.connector.importexport.ImportExport.java
/** * Imports a list of connectors. Replaces the existing connectors with the * connectors in {@code connectors}. For each connector in {@code connectors}, * update an existing connector if the connector names match or create a new * connector if it doesn't already exist. * Unless instructed otherwise, remove any existing connectors which are not * included in {@code connectors}./*w w w. j av a 2 s . c o m*/ * * @param connectors a {@link ImportExportConnectorList} * @param noRemove {@code setConnectors} removes previous connectors * which are not included in {@code connectors} if and only if * {@code noremove} is {@code false}. */ static final void setConnectors(ImportExportConnectorList connectors, boolean noRemove) { Instantiator instantiator = Context.getInstance().getInstantiator(); Set<String> previousConnectorNames = new HashSet<String>(instantiator.getConnectorNames()); for (ImportExportConnector connector : connectors) { String name = connector.getName(); try { // Store the Configuration. boolean update = previousConnectorNames.contains(name); Configuration configuration = connector.getConfiguration(); ConfigureResponse configureResponse = instantiator.setConnectorConfiguration(name, configuration, Locale.ENGLISH, update); if (configureResponse != null) { LOGGER.warning( "setConnectorConfiguration(name=" + name + "\"): " + configureResponse.getMessage()); continue; } // Store the Schedule. instantiator.setConnectorSchedule(name, connector.getSchedule()); previousConnectorNames.remove(name); } catch (ConnectorNotFoundException e) { // This shouldn't happen. LOGGER.warning("Connector " + name + " not found!"); } catch (ConnectorExistsException e) { // This shouldn't happen. LOGGER.warning("Connector " + name + " already exists!"); } catch (ConnectorTypeNotFoundException e) { LOGGER.warning("Connector Type " + connector.getTypeName() + " not found!"); } catch (InstantiatorException e) { LOGGER.log(Level.WARNING, "Failed to create connector " + name + ": ", e); } } // Remove previous connectors which no longer exist. if (!noRemove) { for (String name : previousConnectorNames) { try { instantiator.removeConnector(name); } catch (InstantiatorException e) { LOGGER.log(Level.WARNING, "Failed to remove connector " + name + ": ", e); } } } }
From source file:com.espertech.esper.epl.parse.ASTUtil.java
public static boolean isRecursiveParentRule(ParserRuleContext ctx, Set<Integer> rulesIds) { ParserRuleContext parent = ctx.getParent(); if (parent == null) { return false; }//from www.j ava2 s. c o m return rulesIds.contains(parent.getRuleIndex()) || isRecursiveParentRule(parent, rulesIds); }
From source file:com.github.stagirs.lingvo.syntax.disambiguity.MyStemTest.java
public static String getType(Morph morpho, String word, String form) throws IOException { Set<Attr> set = getAttrs(form); int maxCount = -1; Form maxForm = null;/*www . j av a 2s . c o m*/ for (int i = 0; i < morpho.getNormCount(); i++) { for (Form rawForm : morpho.getRawForms(i)) { int count = 0; for (Attr attr : rawForm.getAttrs()) { if (set.contains(attr)) { count++; } } if (count > maxCount) { maxForm = rawForm; maxCount = count; } } } if (maxCount == 0) { maxForm.toString(); } return WordSyntaxItem.getType(morpho.getRaw(), maxForm); }
From source file:com.bruce.intellijplugin.generatesetter.utils.PsiToolUtils.java
public static void addImportToFile(PsiDocumentManager psiDocumentManager, PsiJavaFile containingFile, Document document, Set<String> newImportList) { if (newImportList.size() > 0) { Iterator<String> iterator = newImportList.iterator(); while (iterator.hasNext()) { String u = iterator.next(); if (u.startsWith("java.lang")) { iterator.remove();// w w w . j a v a 2 s .c o m } } } if (newImportList.size() > 0) { PsiJavaFile javaFile = containingFile; PsiImportStatement[] importStatements = javaFile.getImportList().getImportStatements(); Set<String> containedSet = new HashSet<>(); for (PsiImportStatement s : importStatements) { containedSet.add(s.getQualifiedName()); } StringBuilder newImportText = new StringBuilder(); for (String newImport : newImportList) { if (!containedSet.contains(newImport)) { newImportText.append("\nimport " + newImport + ";"); } } PsiPackageStatement packageStatement = javaFile.getPackageStatement(); int start = 0; if (packageStatement != null) { start = packageStatement.getTextLength() + packageStatement.getTextOffset(); } String insertText = newImportText.toString(); if (StringUtils.isNotBlank(insertText)) { document.insertString(start, insertText); PsiDocumentUtils.commitAndSaveDocument(psiDocumentManager, document); } } }
From source file:org.jasig.portlet.maps.tools.MapDataTransformer.java
/** * Update the provided MapData abbreviations, ensuring each location * has a unique and non-null ID.//w w w .j ava 2 s . co m * * @param data */ protected static void setAbbreviations(MapData data) { // initialize a set for tracking in-use IDs so that we can ensure each // abbreviation is unique Set<String> usedIds = new HashSet<String>(); for (Location location : data.getLocations()) { // if the location already has an abbreviation set and it is not // a duplicate, just go ahead and use it if (StringUtils.isNotBlank(location.getAbbreviation()) && !usedIds.contains(location.getAbbreviation())) { usedIds.add(location.getAbbreviation()); } // otherwise create an automated ID for the location else { // create a default ID from the location name String defaultId = location.getName().replaceAll("[^a-zA-Z0-9]", ""); // if this ID hasn't been used yet, go ahead and use it if (!usedIds.contains(defaultId)) { location.setAbbreviation(defaultId); usedIds.add(defaultId); } // otherwise, add a progressively bigger index to the name until // we have a unique ID else { int idx = 1; String id = defaultId.concat(String.valueOf(idx)); while (usedIds.contains(id)) { idx++; id = defaultId.concat(String.valueOf(idx)); } location.setAbbreviation(id); usedIds.add(id); } } } }
From source file:de.micromata.genome.util.runtime.ClassUtils.java
/** * Collect class annotations./* www . j ava 2 s .c o m*/ * * @param <T> the generic type * @param clazz the clazz * @param annotClass the annot class * @param annots the annots * @param visitedClasses the visited classes */ public static <T extends Annotation> void collectClassAnnotations(Class<?> clazz, Class<T> annotClass, List<T> annots, Set<Class<?>> visitedClasses) { if (visitedClasses.contains(clazz) == true) { return; } visitedClasses.add(clazz); T[] ana = clazz.getAnnotationsByType(annotClass); if (ana != null) { for (T an : ana) { annots.add(an); } } Class<?> superclz = clazz.getSuperclass(); if (superclz == null || superclz == Object.class) { return; } collectClassAnnotations(superclz, annotClass, annots, visitedClasses); Class<?>[] ifaces = clazz.getInterfaces(); if (ifaces == null || ifaces.length == 0) { return; } for (Class<?> iclazz : ifaces) { collectClassAnnotations(iclazz, annotClass, annots, visitedClasses); } }
From source file:com.vmware.photon.controller.api.frontend.utils.SecurityGroupUtils.java
/** * Merge the security inherited from parent to the current security groups. * * @param existingSecurityGroups Existing security groups including both inherited and self ones. * @param parentSecurityGroups Security groups inherited from parent. * @return The merged security groups and the ones removed from 'self' ones due to duplication with parent. *///from ww w.j a v a2 s . c om public static Pair<List<SecurityGroup>, List<String>> mergeParentSecurityGroups( List<SecurityGroup> existingSecurityGroups, List<String> parentSecurityGroups) { checkNotNull(existingSecurityGroups, "Provided value for existingSecurityGroups is unacceptably null"); checkNotNull(parentSecurityGroups, "Provided value for parentSecurityGroups is unacceptably null"); List<SecurityGroup> mergedSecurityGroups = new ArrayList<>(); List<String> selfSecurityGroupsRemoved = new ArrayList<>(); Set<String> inheritedSecurityGroupsNames = new HashSet<>(); parentSecurityGroups.forEach(g -> { mergedSecurityGroups.add(new SecurityGroup(g, true)); inheritedSecurityGroupsNames.add(g); }); existingSecurityGroups.stream().filter(g -> !g.isInherited()).forEach(g -> { if (inheritedSecurityGroupsNames.contains(g.getName())) { selfSecurityGroupsRemoved.add(g.getName()); } else { mergedSecurityGroups.add(g); } }); return Pair.of(mergedSecurityGroups, selfSecurityGroupsRemoved); }
From source file:com.github.stagirs.lingvo.build.MorphStateMachineBuilder.java
private static int[] getCommon(Set<String> suffixes, String raw, List<WordForm[]> wordForms) { int[] index = new int[] { 0, raw.length() }; for (WordForm[] record : wordForms) { int[] com = getCommon(record[1].getWord(), raw); index[0] = Math.max(com[0], index[0]); index[1] = Math.min(com[1], index[1]); }/*from w ww . j a v a 2 s . c o m*/ for (int i = 0; i < index[1]; i++) { if (suffixes.contains(raw.substring(i))) { index[1] = i; break; } } return index; }
From source file:com.espertech.esper.epl.parse.ExceptionConvertor.java
/** * Converts from a syntax error to a nice exception. * @param e is the syntax error/*from w w w. j ava 2s . c o m*/ * @param expression is the expression text * @param parser the parser that parsed the expression * @param addPleaseCheck indicates to add "please check" paraphrases * @return syntax exception */ public static UniformPair<String> convert(RecognitionException e, String expression, boolean addPleaseCheck, EsperEPL2GrammarParser parser) { if (expression.trim().length() == 0) { String message = "Unexpected " + END_OF_INPUT_TEXT; return new UniformPair<String>(message, expression); } Token t; Token tBeforeBefore = null; Token tBefore = null; Token tAfter = null; int tIndex = e.getOffendingToken() != null ? e.getOffendingToken().getTokenIndex() : Integer.MAX_VALUE; if (tIndex < parser.getTokenStream().size()) { t = parser.getTokenStream().get(tIndex); if ((tIndex + 1) < parser.getTokenStream().size()) { tAfter = parser.getTokenStream().get(tIndex + 1); } if (tIndex - 1 >= 0) { tBefore = parser.getTokenStream().get(tIndex - 1); } if (tIndex - 2 >= 0) { tBeforeBefore = parser.getTokenStream().get(tIndex - 2); } } else { if (parser.getTokenStream().size() >= 1) { tBeforeBefore = parser.getTokenStream().get(parser.getTokenStream().size() - 1); } if (parser.getTokenStream().size() >= 2) { tBefore = parser.getTokenStream().get(parser.getTokenStream().size() - 2); } t = parser.getTokenStream().get(parser.getTokenStream().size() - 1); } Token tEnd = null; if (parser.getTokenStream().size() > 0) { tEnd = parser.getTokenStream().get(parser.getTokenStream().size() - 1); } String positionInfo = getPositionInfo(t); String token = t.getType() == EsperEPL2GrammarParser.EOF ? "end-of-input" : "'" + t.getText() + "'"; Stack stack = parser.getParaphrases(); String check = ""; boolean isSelect = stack.size() == 1 && stack.get(0).equals("select clause"); if ((stack.size() > 0) && addPleaseCheck) { String delimiter = ""; StringBuilder checkList = new StringBuilder(); checkList.append(", please check the "); while (stack.size() != 0) { checkList.append(delimiter); checkList.append(stack.pop()); delimiter = " within the "; } check = checkList.toString(); } // check if token is a reserved keyword Set<String> keywords = parser.getKeywords(); boolean reservedKeyword = false; if (keywords.contains(token.toLowerCase())) { token += " (a reserved keyword)"; reservedKeyword = true; } else if (tAfter != null && keywords.contains("'" + tAfter.getText().toLowerCase() + "'")) { token += " ('" + tAfter.getText() + "' is a reserved keyword)"; reservedKeyword = true; } else { if ((tBefore != null) && (tAfter != null) && (keywords.contains("'" + tBefore.getText().toLowerCase() + "'")) && (keywords.contains("'" + tAfter.getText().toLowerCase() + "'"))) { token += " ('" + tBefore.getText() + "' and '" + tAfter.getText() + "' are a reserved keyword)"; reservedKeyword = true; } else if ((tBefore != null) && (keywords.contains("'" + tBefore.getText().toLowerCase() + "'"))) { token += " ('" + tBefore.getText() + "' is a reserved keyword)"; reservedKeyword = true; } else if (tEnd != null && keywords.contains("'" + tEnd.getText().toLowerCase() + "'")) { token += " ('" + tEnd.getText() + "' is a reserved keyword)"; reservedKeyword = true; } } // special handling for the select-clause "as" keyword, which is required if (isSelect && !reservedKeyword) { check += getSelectClauseAsText(tBeforeBefore, t); } String message = "Incorrect syntax near " + token + positionInfo + check; if (e instanceof NoViableAltException || e instanceof LexerNoViableAltException || checkForInputMismatchWithNoExpected(e)) { Token nvaeToken = e.getOffendingToken(); int nvaeTokenType = nvaeToken != null ? nvaeToken.getType() : EsperEPL2GrammarLexer.EOF; if (nvaeTokenType == EsperEPL2GrammarLexer.EOF) { if (token.equals(END_OF_INPUT_TEXT)) { message = "Unexpected " + END_OF_INPUT_TEXT + positionInfo + check; } else { if (ParseHelper.hasControlCharacters(expression)) { message = "Unrecognized control characters found in text" + positionInfo; } else { message = "Unexpected " + END_OF_INPUT_TEXT + " near " + token + positionInfo + check; } } } else { if (parser.getParserTokenParaphrases().get(nvaeTokenType) != null) { message = "Incorrect syntax near " + token + positionInfo + check; } else { // find next keyword in the next 3 tokens int currentIndex = tIndex + 1; while ((currentIndex > 0) && (currentIndex < parser.getTokenStream().size() - 1) && (currentIndex < tIndex + 3)) { Token next = parser.getTokenStream().get(currentIndex); currentIndex++; String quotedToken = "'" + next.getText() + "'"; if (parser.getKeywords().contains(quotedToken)) { check += " near reserved keyword '" + next.getText() + "'"; break; } } message = "Incorrect syntax near " + token + positionInfo + check; } } } else if (e instanceof InputMismatchException) { InputMismatchException mismatched = (InputMismatchException) e; String expected; if (mismatched.getExpectedTokens().size() > 1) { StringWriter writer = new StringWriter(); writer.append("any of the following tokens {"); String delimiter = ""; for (int i = 0; i < mismatched.getExpectedTokens().size(); i++) { writer.append(delimiter); if (i > 5) { writer.append("..."); writer.append(Integer.toString(mismatched.getExpectedTokens().size() - 5)); writer.append(" more"); break; } delimiter = ", "; writer.append(getTokenText(parser, mismatched.getExpectedTokens().get(i))); } writer.append("}"); expected = writer.toString(); } else { expected = getTokenText(parser, mismatched.getExpectedTokens().get(0)); } int offendingTokenType = mismatched.getOffendingToken().getType(); String unexpected = getTokenText(parser, offendingTokenType); String expecting = " expecting " + expected.trim() + " but found " + unexpected.trim(); message = "Incorrect syntax near " + token + expecting + positionInfo + check; } return new UniformPair<String>(message, expression); }