List of usage examples for java.util Set contains
boolean contains(Object o);
From source file:edu.umich.flowfence.service.NamespaceSharedPrefs.java
public static NamespaceSharedPrefs get(SharedPreferences basePrefs, String taintSetNamespace, String... taintNamespaces) { Objects.requireNonNull(taintSetNamespace); taintNamespaces = ArrayUtils.nullToEmpty(taintNamespaces); if (taintNamespaces.length == 0) { throw new IllegalArgumentException("Need at least one taint namespace!"); }//from w w w . j a va 2 s .co m Set<String> taintNamespaceSet = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(taintNamespaces))); if (taintNamespaceSet.contains(taintSetNamespace)) { throw new IllegalArgumentException("Taint set namespace also a taint namespace"); } synchronized (g_mPrefsLookup) { NamespaceSharedPrefs prefsStrong = null; WeakReference<NamespaceSharedPrefs> prefsWeak = g_mPrefsLookup.get(basePrefs); if (prefsWeak != null) { prefsStrong = prefsWeak.get(); } if (prefsStrong != null) { if (!taintSetNamespace.equals(prefsStrong.mTaintSetNamespace) || !taintNamespaceSet.equals(prefsStrong.mTaintNamespaces)) { Log.w(TAG, String.format( "Inconsistent initialization: " + "initialized with TS=%s T=%s, retrieved with TS=%s T=%s", prefsStrong.mTaintSetNamespace, prefsStrong.mTaintNamespaces, taintSetNamespace, taintNamespaceSet)); } } else { prefsStrong = new NamespaceSharedPrefs(basePrefs, taintSetNamespace, taintNamespaceSet); prefsWeak = new WeakReference<>(prefsStrong); g_mPrefsLookup.put(basePrefs, prefsWeak); } return prefsStrong; } }
From source file:edu.cmu.tetrad.cli.util.Args.java
public static String[] removeFlags(String[] args, String... flags) { String[] arguments = new String[args.length - 2]; Set<String> options = new HashSet<>(); Collections.addAll(options, flags); int index = 0; for (String arg : args) { if (arg.startsWith("--")) { arg = arg.substring(2, arg.length()); if (options.contains(arg)) { continue; }/* w w w .jav a2 s . c o m*/ } else if (arg.startsWith("-")) { arg = arg.substring(1, arg.length()); if (options.contains(arg)) { continue; } } arguments[index++] = arg; } return arguments; }
From source file:com.github.javarch.jsf.tags.security.SpringSecurityELLibrary.java
/** * Method that checks if the user holds <b>all</b> of the given roles. * Returns <code>true</code>, iff the user holds all roles, <code>false</code> if no roles are given or * the first non-matching role is found// w w w . j a va 2 s.c o m * * @param requiredRoles a comma seperated list of roles * @return true if all of the given roles are granted to the current user, false otherwise or if no * roles are specified at all. */ public static boolean ifAllGranted(final String requiredRoles) { // parse required roles into list Set<String> requiredAuthorities = parseAuthorities(requiredRoles); if (requiredAuthorities.isEmpty()) return false; // get granted roles GrantedAuthority[] authoritiesArray = getUserAuthorities(); Set<String> grantedAuthorities = new TreeSet<String>(); for (GrantedAuthority authority : authoritiesArray) { grantedAuthorities.add(authority.getAuthority()); } // iterate over required roles, for (String requiredAuthority : requiredAuthorities) { // check if required role is inside granted roles // if not, return false if (!grantedAuthorities.contains(requiredAuthority)) { return false; } } return true; }
From source file:com.metadave.stow.Stow.java
public static void generateObjects(String groupFile, String classPackage, String classPrefix, String dest) { if (classPrefix == null) { classPrefix = ""; }//from w ww .ja va2s .c o m Set<String> templateNames = new HashSet<String>(); StowSTGroupFile stg = new StowSTGroupFile(groupFile); STGroup outputGroup = new STGroupFile("Stow.stg"); Map<String, CompiledST> ts = stg.getTemplates(); int i = 1; for (String s : ts.keySet()) { CompiledST t = ts.get(s); if (t.isAnonSubtemplate) { continue; } String templateId; if (!templateNames.contains(t.name.toUpperCase())) { templateNames.add(t.name.toUpperCase()); templateId = t.name; } else { System.out.println("Adding a unique id to " + t.name); templateId = t.name + i; } STOWSTBean bean = new STOWSTBean(outputGroup); bean.addPackage(classPackage); bean.addTemplateName(t.name); String className = classPrefix + templateId; bean.addBeanClass(className); if (t.hasFormalArgs) { Map<String, FormalArgument> fas = t.formalArguments; if (fas != null) { for (String fa : fas.keySet()) { FormalArgument f = fas.get(fa); STOWSTAccessor acc = new STOWSTAccessor(outputGroup); acc.addBeanClass(className); acc.addMethodName(getNiceName(f.name)); acc.addParamName(f.name); bean.addAccessor(acc); } } } String outputFileName = dest + File.separator + className + ".java"; System.out.println("Generating " + outputFileName); File f = new File(outputFileName); try { FileUtils.writeStringToFile(f, bean.getST().render()); } catch (Exception e) { e.printStackTrace(); } } System.out.println("Finished!"); }
From source file:ml.shifu.core.util.ValidationUtils.java
/** * validate fields in FieldMeta are valid. * * @throws RuntimeException if invalid.//from w w w . j av a2 s . co m */ public static void validateFields(FieldMeta fieldMeta) { // validate num fields // num_fields < MIN_NUM_FIELDS String errMessage = null; List<Field> fields = fieldMeta.getFields(); if (fields == null || fields.size() < Constants.MIN_NUM_FIELDS) { errMessage = "Invalid number of fields in FieldMeta (< " + " " + Constants.MIN_NUM_FIELDS + " ). Check header file/configuration."; LOG.error(errMessage); throw new RuntimeException(errMessage); } // detect duplicate fields Set set = new HashSet(); for (Field field : fields) { String name = field.getFieldBasics().getName(); if (set.contains(name)) { errMessage = "Duplicate field name [" + name + "] found. Check header file/configuration."; LOG.error(errMessage); throw new RuntimeException(errMessage); } set.add(name); } // TODO any character not allowed in field name? }
From source file:biomine.bmvis2.subgraph.Extractor.java
public static void hideAllExceptNodes(VisualGraph g, Set<VisualNode> keepers) { Set<VisualNode> parents = new HashSet<VisualNode>(); for (VisualNode node : keepers) { VisualNode parent = node.getParent(); while (parent != null) { parents.add(parent);/*from w w w .j ava 2 s .c o m*/ parent = parent.getParent(); } } Set<VisualNode> newHidden = new HashSet<VisualNode>(); for (VisualNode node : g.getAllNodes()) if (!keepers.contains(node) && !parents.contains(node)) newHidden.add(node); g.setHiddenNodes(newHidden); }
From source file:de.micromata.genome.jpa.metainf.MetaInfoUtils.java
private static void dumpReferencePath(StringBuilder sb, EntityMetadata em, Set<EntityMetadata> visited, String ident) {//from www . j a va 2 s . com sb.append(ident).append(em); if (visited.contains(em) == true) { sb.append(" < CYCLIC ").append("\n"); return; } visited.add(em); sb.append("\n"); for (EntityMetadata re : em.getReferencedBy()) { dumpReferencePath(sb, re, visited, ident + " "); } }
From source file:Main.java
public static List<Element> elementsQName(Element element, Set<QName> allowedTagNames) { if (element == null || !element.hasChildNodes()) { return Collections.emptyList(); }/*ww w .jav a2 s .c o m*/ List<Element> elements = new ArrayList<Element>(); for (Node child = element.getFirstChild(); child != null; child = child.getNextSibling()) { if (child.getNodeType() == Node.ELEMENT_NODE) { Element childElement = (Element) child; QName childQName = new QName(childElement.getNamespaceURI(), childElement.getLocalName()); if (allowedTagNames.contains(childQName)) { elements.add(childElement); } } } return elements; }
From source file:biomine.bmvis2.subgraph.Extractor.java
public static void removeAllExceptNodes(VisualGraph g, Set<VisualNode> keepers) { Set<VisualNode> parents = new HashSet<VisualNode>(); for (VisualNode node : keepers) { VisualNode parent = node.getParent(); while (parent != null) { parents.add(parent);//from www . j av a 2s .com parent = parent.getParent(); } } Set<VisualNode> newHidden = new HashSet<VisualNode>(); for (VisualNode node : g.getAllNodes()) if (!keepers.contains(node) && !parents.contains(node)) newHidden.add(node); for (VisualNode node : newHidden) { g.deleteNode(node); } }
From source file:com.adobe.acs.commons.analysis.jcrchecksum.impl.JSONGenerator.java
@SuppressWarnings("squid:S3776") private static void outputProperty(Property property, ChecksumGeneratorOptions opts, JsonWriter out) throws RepositoryException, IOException { Set<String> sortValues = opts.getSortedProperties(); if (property.isMultiple()) { out.name(property.getName());// www . j a va2 s.c om // create an array for multi value output out.beginArray(); boolean isSortedValues = sortValues.contains(property.getName()); Value[] values = property.getValues(); TreeMap<String, Value> sortedValueMap = new TreeMap<String, Value>(); for (Value v : values) { int type = v.getType(); if (type == PropertyType.BINARY) { if (isSortedValues) { try { java.io.InputStream stream = v.getBinary().getStream(); String ckSum = DigestUtils.shaHex(stream); stream.close(); sortedValueMap.put(ckSum, v); } catch (IOException e) { sortedValueMap.put("ERROR: generating hash for binary of " + property.getPath() + " : " + e.getMessage(), v); } } else { outputPropertyValue(property, v, out); } } else { String val = v.getString(); if (isSortedValues) { sortedValueMap.put(val, v); } else { outputPropertyValue(property, v, out); } } } if (isSortedValues) { for (Value v : sortedValueMap.values()) { outputPropertyValue(property, v, out); } } out.endArray(); // end multi value property output } else { out.name(property.getName()); outputPropertyValue(property, property.getValue(), out); } }