Example usage for java.util Set contains

List of usage examples for java.util Set contains

Introduction

In this page you can find the example usage for java.util Set contains.

Prototype

boolean contains(Object o);

Source Link

Document

Returns true if this set contains the specified element.

Usage

From source file:backup.namenode.NameNodeBackupBlockCheckProcessor.java

public static boolean shouldIgnore(Set<Path> pathSetToIgnore, Path path) {
    do {/*from   w  ww  .  j  a  v  a2s.com*/
        if (pathSetToIgnore.contains(path)) {
            return true;
        }
        path = path.getParent();
    } while (path != null);
    return false;
}

From source file:flex2.compiler.mxml.gen.DescriptorGenerator.java

/**
 *
 *///w w  w. j  a va 2s .  c  o m
private static void addDescriptorProperties(CodeFragmentList list, Model model,
        final Set<String> includePropNames, boolean includeDesignLayer, String indent) {
    //  ordinary properties
    Iterator propIter = includePropNames == null ? model.getPropertyInitializerIterator(false)
            : new FilterIterator(model.getPropertyInitializerIterator(false), new Predicate() {
                public boolean evaluate(Object obj) {
                    return includePropNames.contains(((NamedInitializer) obj).getName());
                }
            });

    //  visual children
    Iterator vcIter = (model instanceof MovieClip && ((MovieClip) model).hasChildren())
            ? ((MovieClip) model).children().iterator()
            : Collections.EMPTY_LIST.iterator();

    // designLayer ?
    Boolean hasDesignLayer = (includeDesignLayer && (model.layerParent != null)
            && model.getType().isAssignableTo(model.getStandardDefs().INTERFACE_IVISUALELEMENT));

    if (propIter.hasNext() || vcIter.hasNext() || hasDesignLayer) {
        if (!list.isEmpty()) {
            list.add(indent, ",", 0);
        }

        list.add(indent, "propertiesFactory: function():Object { return {", 0);
        indent += DescriptorGenerator.INDENT;

        while (propIter.hasNext()) {
            NamedInitializer init = (NamedInitializer) propIter.next();
            if (!init.isStateSpecific()) {
                list.add(indent, init.getName(), ": ", init.getValueExpr(),
                        (propIter.hasNext() || vcIter.hasNext() || hasDesignLayer ? "," : ""),
                        init.getLineRef());
            }
        }

        if (hasDesignLayer) {
            list.add(indent, "designLayer", ": ", model.layerParent.getId(), (vcIter.hasNext() ? "," : ""),
                    model.getXmlLineNumber());
        }

        if (vcIter.hasNext()) {
            list.add(indent, "childDescriptors: [", 0);

            // Generate each child descriptor unless the child as explicitly filtered out.
            boolean isFirst = true;
            while (vcIter.hasNext()) {
                VisualChildInitializer init = (VisualChildInitializer) vcIter.next();
                Model child = (MovieClip) init.getValue();
                if (child.isDescriptorInit()) {
                    if (!isFirst) {
                        list.add(indent, ",", 0);
                    }

                    addDescriptorInitializerFragments(list, child, indent + DescriptorGenerator.INDENT);
                    isFirst = false;
                }

            }

            list.add(indent, "]", 0);
        }

        indent = indent.substring(0, indent.length() - INDENT.length());
        list.add(indent, "}}", 0);
    }
}

From source file:podd.util.PoddWebappTestUtil.java

@SuppressWarnings({ "unchecked" })
public static <T> void checkGetterMethods(T obj1, T obj2, Set<String> skipList) {
    try {//from w ww . j  a  v  a  2s. c  o m
        final Method[] methods = obj1.getClass().getMethods();
        for (Method m : methods) {
            if (m.getName().startsWith("get") && !skipList.contains(m.getName())) {
                final Object value1 = m.invoke(obj1);
                final Object value2 = m.invoke(obj2);
                if (value1 instanceof Collection && value2 instanceof Collection) {
                    checkMembers((Collection) value1, ((Collection) value2).toArray());
                } else if (!(value1 instanceof Collection || value2 instanceof Collection)) {
                    assertEquals("Method: " + m.getName(), value1, value2);
                } else {
                    throw new IllegalArgumentException("One is collection while the other is not.");
                }
            }
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.opengamma.engine.view.compilation.CompiledViewCalculationConfigurationImpl.java

private static Map<ValueSpecification, Collection<ValueSpecification>> processMarketDataRequirements(
        final DependencyGraph dependencyGraph) {
    ArgumentChecker.notNull(dependencyGraph, "dependencyGraph");
    final Collection<ValueSpecification> marketDataEntries = dependencyGraph.getAllRequiredMarketData();
    final Map<ValueSpecification, Collection<ValueSpecification>> result = Maps
            .newHashMapWithExpectedSize(marketDataEntries.size());
    final Set<ValueSpecification> terminalOutputs = dependencyGraph.getTerminalOutputSpecifications();
    for (ValueSpecification marketData : marketDataEntries) {
        final DependencyNode marketDataNode = dependencyGraph.getNodeProducing(marketData);
        Collection<ValueSpecification> aliases = null;
        Collection<DependencyNode> aliasNodes = marketDataNode.getDependentNodes();
        boolean usedDirectly = terminalOutputs.contains(marketData);
        for (DependencyNode aliasNode : aliasNodes) {
            if (aliasNode.getFunction().getFunction() instanceof MarketDataAliasingFunction) {
                if (aliases == null) {
                    aliases = new ArrayList<>(aliasNodes.size());
                    result.put(marketData, Collections.unmodifiableCollection(aliases));
                }/*from   w w w.jav a  2  s. c om*/
                aliases.addAll(aliasNode.getOutputValues());
            } else {
                usedDirectly = true;
            }
        }
        if (usedDirectly) {
            if (aliases != null) {
                aliases.add(marketData);
            } else {
                result.put(marketData, Collections.singleton(marketData));
            }
        }
    }
    return Collections.unmodifiableMap(result);
}

From source file:hsyndicate.utils.IPUtils.java

public static boolean isLocalIPAddress(String address) {
    Collection<String> localhostAddress = IPUtils.getHostAddress();
    Set<String> localhostAddrSet = new HashSet<String>();
    localhostAddrSet.addAll(localhostAddress);

    String hostname = address;//from  w  w w  . j  a v  a 2 s .com
    int pos = hostname.indexOf(":");
    if (pos > 0) {
        hostname = hostname.substring(0, pos);
    }

    if (hostname.equalsIgnoreCase("localhost") || hostname.equals("127.0.0.1")) {
        // localloop
        return true;
    }

    if (localhostAddrSet.contains(hostname)) {
        return true;
    }

    return false;
}

From source file:com.perl5.lang.perl.util.PerlSubUtil.java

@NotNull
public static List<PerlSubBase> collectOverridingSubs(@NotNull PerlSubBase subBase,
        @NotNull Set<String> recursionSet) {
    List<PerlSubBase> result = new ArrayList<PerlSubBase>();
    for (PerlSubBase directDescendant : getDirectOverridingSubs(subBase)) {
        String packageName = directDescendant.getPackageName();
        if (StringUtil.isNotEmpty(packageName) && !recursionSet.contains(packageName)) {
            recursionSet.add(packageName);
            result.add(directDescendant);
            result.addAll(collectOverridingSubs(directDescendant, recursionSet));
        }// ww w . ja  v a 2  s  .c o  m
    }

    return result;
}

From source file:com.ms.commons.test.tool.GenerateTestCase.java

private static List<MethodDeclaration> filterMethodForTest(List<MethodDeclaration> methodList,
        List<FieldDeclaration> fieldList) {
    Set<String> fieldSet = getAllFieldHashSet(fieldList);
    List<MethodDeclaration> filteredMethodList = new ArrayList<MethodDeclaration>();
    for (MethodDeclaration method : methodList) {
        String name = method.getName();

        if (name.startsWith("get") || name.startsWith("set")) {
            if (fieldSet.contains(name.substring(3).toLowerCase())) {
                continue;
            }// w  w w  .j a v  a 2s .  c  om
        }
        filteredMethodList.add(method);
    }
    return filteredMethodList;
}

From source file:de.bund.bfr.knime.gis.views.canvas.CanvasUtils.java

public static <T extends Element> Set<T> getElementsById(Collection<T> elements, Set<String> ids) {
    return elements.stream().filter(e -> ids.contains(e.getId()))
            .collect(Collectors.toCollection(LinkedHashSet::new));
}

From source file:I18NUtil.java

/**
 * Searches for the nearest locale from the available options.  To match any locale, pass in
 * <tt>null</tt>.//from   w  w w.j ava 2s. c  o m
 * 
 * @param templateLocale the template to search for or <tt>null</tt> to match any locale
 * @param options the available locales to search from
 * @return Returns the best match from the available options, or the <tt>null</tt> if
 *      all matches fail
 */
public static Locale getNearestLocale(Locale templateLocale, Set<Locale> options) {
    if (options.isEmpty()) // No point if there are no options
    {
        return null;
    } else if (templateLocale == null) {
        for (Locale locale : options) {
            return locale;
        }
    } else if (options.contains(templateLocale)) // First see if there is an exact match
    {
        return templateLocale;
    }
    // make a copy of the set
    Set<Locale> remaining = new HashSet<Locale>(options);

    // eliminate those without matching languages
    Locale lastMatchingOption = null;
    String templateLanguage = templateLocale.getLanguage();
    if (templateLanguage != null && !templateLanguage.equals("")) {
        Iterator<Locale> iterator = remaining.iterator();
        while (iterator.hasNext()) {
            Locale option = iterator.next();
            if (option != null && !templateLanguage.equals(option.getLanguage())) {
                iterator.remove(); // It doesn't match, so remove
            } else {
                lastMatchingOption = option; // Keep a record of the last match
            }
        }
    }
    if (remaining.isEmpty()) {
        return null;
    } else if (remaining.size() == 1 && lastMatchingOption != null) {
        return lastMatchingOption;
    }

    // eliminate those without matching country codes
    lastMatchingOption = null;
    String templateCountry = templateLocale.getCountry();
    if (templateCountry != null && !templateCountry.equals("")) {
        Iterator<Locale> iterator = remaining.iterator();
        while (iterator.hasNext()) {
            Locale option = iterator.next();
            if (option != null && !templateCountry.equals(option.getCountry())) {
                // It doesn't match language - remove
                // Don't remove the iterator. If it matchs a langage but not the country, returns any matched language                     
                // iterator.remove();
            } else {
                lastMatchingOption = option; // Keep a record of the last match
            }
        }
    }
    /*if (remaining.isEmpty())
    {
    return null;
    }
    else */
    if (remaining.size() == 1 && lastMatchingOption != null) {
        return lastMatchingOption;
    } else {
        // We have done an earlier equality check, so there isn't a matching variant
        // Also, we know that there are multiple options at this point, either of which will do.

        // This gets any country match (there will be worse matches so we take the last the country match)
        if (lastMatchingOption != null) {
            return lastMatchingOption;
        } else {
            for (Locale locale : remaining) {
                return locale;
            }
        }
    }
    // The logic guarantees that this code can't be called
    throw new RuntimeException("Logic should not allow code to get here.");
}

From source file:com.netflix.spinnaker.halyard.cli.services.v1.ResponseUnwrapper.java

private static void logTasks(List<DaemonTask> tasks, Set<String> loggedEvents) {
    // This is expensive, so don't check all tasks to log unless it's necessary.
    if (GlobalOptions.getGlobalOptions().getLog() == Level.OFF) {
        return;/*  w  w  w  .j  a va2  s .  c om*/
    }

    for (DaemonTask task : tasks) {
        for (Object oEvent : task.getEvents()) {
            DaemonEvent event = (DaemonEvent) oEvent;
            String loggedEvent = formatLoggedDaemonTask(task, event);
            if (!loggedEvents.contains(loggedEvent)) {
                loggedEvents.add(loggedEvent);
                log.info(loggedEvent);
            }
        }
    }
}