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:Main.java

public static List<Element> elementsQName(final Element element, final Set<QName> allowedTagNames) {
    List<Element> elements = null;
    final NodeList nodeList = element.getChildNodes();
    if (nodeList != null) {
        for (int i = 0; i < nodeList.getLength(); i++) {
            final Node child = nodeList.item(i);
            if (Element.class.isAssignableFrom(child.getClass())) {
                final Element childElement = (Element) child;
                final QName childElementQName = new QName(childElement.getNamespaceURI(),
                        childElement.getLocalName());
                if (allowedTagNames.contains(childElementQName)) {
                    if (elements == null) {
                        elements = new ArrayList<Element>();
                    }//  ww w.  j a  va2 s.c  om
                    elements.add(childElement);
                }
            }
        }
    }
    return elements;
}

From source file:acromusashi.stream.ml.anomaly.lof.LofCalculator.java

/**
 * ??<br>//  w ww  .j  a v  a  2  s .  c  om
 * ?????????????{@link #initDataSet(int, LofDataSet)}???
 * 
 * @param baseDataSet ?
 * @param targetDataSet ?
 * @param max ??
 * @return ?
 */
public static LofDataSet mergeDataSet(LofDataSet baseDataSet, LofDataSet targetDataSet, int max) {
    Collection<LofPoint> basePointList = baseDataSet.getDataMap().values();
    Collection<LofPoint> targetPointList = targetDataSet.getDataMap().values();

    // LOF??????
    List<LofPoint> mergedList = new ArrayList<>();
    mergedList.addAll(basePointList);
    mergedList.addAll(targetPointList);
    Collections.sort(mergedList, new LofPointComparator());

    // ?????????
    Collections.reverse(mergedList);

    // ?????????
    // ??????????????ID??????
    // ??????ID?????????????????
    Set<String> registeredId = new HashSet<>();
    int addedCount = 0;
    LofDataSet resultDataSet = new LofDataSet();

    for (LofPoint targetPoint : mergedList) {
        if (registeredId.contains(targetPoint.getDataId()) == true) {
            continue;
        }

        registeredId.add(targetPoint.getDataId());
        resultDataSet.addData(targetPoint);
        addedCount++;

        if (addedCount >= max) {
            break;
        }
    }

    return resultDataSet;
}

From source file:com.palantir.ptoss.cinch.core.BindingContext.java

private static Map<String, ObjectFieldMethod> indexMethods(List<ObjectFieldMethod> methods)
        throws IllegalArgumentException {
    Map<String, ObjectFieldMethod> map = Maps.newHashMap();
    Set<String> ambiguousNames = Sets.newHashSet();
    for (ObjectFieldMethod ofm : methods) {
        Method method = ofm.getMethod();
        String blindKey = method.getName();
        if (!ambiguousNames.contains(blindKey)) {
            if (map.containsKey(blindKey)) {
                map.remove(blindKey);/*from   ww w .  ja  v a 2 s  .c o m*/
                ambiguousNames.add(blindKey);
            } else {
                map.put(blindKey, ofm);
            }
        }
        String fieldName = ofm.getField() == null ? "this" : ofm.getField().getName();
        String qualifiedKey = fieldName + "." + blindKey;
        map.put(qualifiedKey, ofm);
    }
    return map;
}

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  ww  .ja  v 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:CollectionsX.java

/** Tests whether two sets has any intersection.
 *///from   w ww.  jav  a2s.com
public static final boolean isIntersected(Set a, Set b) {
    final int sza = a != null ? a.size() : 0;
    final int szb = b != null ? b.size() : 0;
    if (sza == 0 || szb == 0)
        return false;

    final Set large, small;
    if (sza > szb) {
        large = a;
        small = b;
    } else {
        large = b;
        small = a;
    }
    for (final Iterator it = small.iterator(); it.hasNext();)
        if (large.contains(it.next()))
            return true;
    return false;
}

From source file:com.google.gwt.dev.javac.CompilationStateBuilder.java

private static void invalidateUnitsWithInvalidRefs(TreeLogger logger, Map<String, CompilationUnit> resultUnits,
        Set<ContentId> set) {
    Set<CompilationUnit> validResultUnits = new HashSet<CompilationUnit>(resultUnits.values());
    CompilationUnitInvalidator.retainValidUnits(logger, validResultUnits, set);
    for (Entry<String, CompilationUnit> entry : resultUnits.entrySet()) {
        CompilationUnit unit = entry.getValue();
        if (unit.isCompiled() && !validResultUnits.contains(unit)) {
            entry.setValue(new InvalidCompilationUnit(unit));
        }/*  w  w w .  j a  v a 2 s.co  m*/
    }
}

From source file:hr.fer.spocc.regex.DefaultRegularExpression.java

private static List<RegularExpressionElement> toElements(String escapedString, CharacterEscaper escaper) {

    List<RegularExpressionElement> elements = new ArrayList<RegularExpressionElement>();

    Set<Integer> unescapedIndexes = new HashSet<Integer>();
    String unescapedString = escaper.unescape(escapedString, unescapedIndexes);

    for (int i = 0; i < unescapedString.length(); ++i) {
        RegularExpressionElement lastElement = (!elements.isEmpty() ? elements.get(elements.size() - 1) : null);
        char c = unescapedString.charAt(i);
        RegularExpressionElement e = null;
        if (!unescapedIndexes.contains(i)) {
            switch (c) {
            case STAR_OPERATOR:
                e = RegularExpressionOperator.STAR;
                break;
            case UNION_OPERATOR:
                e = RegularExpressionOperator.UNION;
                break;
            case LEFT_PARENTHESIS:
                e = RegularExpressionElements.LEFT_PARENTHESIS;
                break;
            case RIGHT_PARENTHESIS:
                e = RegularExpressionElements.RIGHT_PARENTHESIS;
                break;
            case EPSILON_SYMBOL:
                e = new RegularExpressionSymbol<Character>(null);
                break;
            default:
                e = new RegularExpressionSymbol<Character>(c);
                break;
            }/*  w ww. j ava 2 s. co  m*/
        } else { // escaped character is always a symbol
            e = new RegularExpressionSymbol<Character>(c);
        }

        // insert the concatenation operator if needed
        if (requiresConcatenation(lastElement, e)) {
            elements.add(RegularExpressionOperator.CONCATENATION);
        }
        elements.add(e);
    }

    return Collections.unmodifiableList(elements);
}

From source file:com.kylinolap.job.tools.DeployCoprocessorCLI.java

public static Path uploadCoprocessorJar(String localCoprocessorJar, FileSystem fileSystem,
        Set<String> oldJarPaths) throws IOException {
    Path uploadPath = null;/*from   w  w w  .j  a va  2  s  .c o  m*/
    File localCoprocessorFile = new File(localCoprocessorJar);

    // check existing jars
    if (oldJarPaths == null) {
        oldJarPaths = new HashSet<String>();
    }
    Path coprocessorDir = getCoprocessorHDFSDir(fileSystem, KylinConfig.getInstanceFromEnv());
    for (FileStatus fileStatus : fileSystem.listStatus(coprocessorDir)) {
        if (fileStatus.getLen() == localCoprocessorJar.length()
                && fileStatus.getModificationTime() == localCoprocessorFile.lastModified()) {
            uploadPath = fileStatus.getPath();
            break;
        }
        String filename = fileStatus.getPath().toString();
        if (filename.endsWith(".jar")) {
            oldJarPaths.add(filename);
        }
    }

    // upload if not existing
    if (uploadPath == null) {
        // figure out a unique new jar file name
        Set<String> oldJarNames = new HashSet<String>();
        for (String path : oldJarPaths) {
            oldJarNames.add(new Path(path).getName());
        }
        String baseName = getBaseFileName(localCoprocessorJar);
        String newName = null;
        int i = 0;
        while (newName == null) {
            newName = baseName + "-" + (i++) + ".jar";
            if (oldJarNames.contains(newName))
                newName = null;
        }

        // upload
        uploadPath = new Path(coprocessorDir, newName);
        FileInputStream in = null;
        FSDataOutputStream out = null;
        try {
            in = new FileInputStream(localCoprocessorFile);
            out = fileSystem.create(uploadPath);
            IOUtils.copy(in, out);
        } finally {
            IOUtils.closeQuietly(in);
            IOUtils.closeQuietly(out);
        }

        fileSystem.setTimes(uploadPath, localCoprocessorFile.lastModified(), System.currentTimeMillis());
    }

    uploadPath = uploadPath.makeQualified(fileSystem.getUri(), null);
    return uploadPath;
}

From source file:org.artifactory.webapp.servlet.RequestUtils.java

public static boolean isRepoRequest(HttpServletRequest request, boolean warnIfRepoDoesNotExist) {
    String servletPath = getServletPathFromRequest(request);
    String pathPrefix = PathUtils.getFirstPathElement(servletPath);
    if (pathPrefix == null || pathPrefix.length() == 0) {
        return false;
    }//from  w w w  . ja v a2 s.c om
    if (ArtifactoryRequest.LIST_BROWSING_PATH.equals(pathPrefix)) {
        pathPrefix = PathUtils.getFirstPathElement(servletPath.substring("list/".length()));
    }
    if (ArtifactoryRequest.SIMPLE_BROWSING_PATH.equals(pathPrefix)) {
        pathPrefix = PathUtils.getFirstPathElement(servletPath.substring("simple/".length()));
    }
    if (UI_PATH_PREFIXES.contains(pathPrefix)) {
        return false;
    }
    if (NON_UI_PATH_PREFIXES.contains(pathPrefix)) {
        return false;
    }
    String repoKey = pathPrefix;
    //Support repository-level metadata requests
    repoKey = NamingUtils.stripMetadataFromPath(repoKey);
    //Strip any matrix params
    int paramsIdx = repoKey.indexOf(Properties.MATRIX_PARAMS_SEP);
    if (paramsIdx > 0) {
        repoKey = repoKey.substring(0, paramsIdx);
    }
    RepositoryService repositoryService = ContextHelper.get().getRepositoryService();
    Set<String> allRepos = repositoryService.getAllRepoKeys();
    try {
        repoKey = URLDecoder.decode(repoKey, "utf-8");
    } catch (UnsupportedEncodingException e) {
        log.warn("Could not decode repo key '" + repoKey + "' in utf-8");
        return false;
    }
    if (!allRepos.contains(repoKey)) {
        if (warnIfRepoDoesNotExist) {
            log.warn("Request " + servletPath + " should be a repo request and does not match any repo key");
        }
        return false;
    }
    return true;
}

From source file:eu.annocultor.tools.GeneratorOfXmlSchemaForConvertersDoclet.java

public static Set<String> getSuperClasses(ClassDoc cd) {
    Set<String> superClasses = new HashSet<String>();
    ClassDoc cls = cd;//from   w  w  w  .ja  v  a2s. co m
    while (cls != null && cls.isClass()) {
        ClassDoc superClass = cls.superclass();
        if (superClass != null) {
            if (superClasses.contains(superClass.qualifiedName())) {
                throw new RuntimeException("Cycle in superclass relation: " + Utils.show(superClasses, ", "));
            }
            superClasses.add(superClass.qualifiedName());
        }
        cls = superClass;
    }
    return superClasses;
}