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:collection.PhysicalWebCollection.java

/**
 * If a site URL appears multiple times in the pairs list, keep only the first example.
 * @param allPwPairs input PwPairs list.
 * @return filtered PwPairs list with all duplicated site URLs removed.
 *///from   w  w  w . j ava  2  s. c o  m
private static List<PwPair> removeDuplicateSiteUrls(List<PwPair> allPwPairs) {
    List<PwPair> filteredPwPairs = new ArrayList<>();
    Set<String> siteUrls = new HashSet<>();
    for (PwPair pwPair : allPwPairs) {
        String siteUrl = pwPair.getPwsResult().getSiteUrl();
        if (!siteUrls.contains(siteUrl)) {
            siteUrls.add(siteUrl);
            filteredPwPairs.add(pwPair);
        }
    }
    return filteredPwPairs;
}

From source file:Main.java

protected static String nodeToString(Node node, Set<String> parentPrefixes, String namespaceURI)
        throws Exception {
    StringBuilder b = new StringBuilder();

    if (node == null) {
        return "";
    }/* www  .j av a2s. co  m*/

    if (node instanceof Element) {
        Element element = (Element) node;
        b.append("<");
        b.append(element.getNodeName());

        Map<String, String> thisLevelPrefixes = new HashMap();
        if (element.getPrefix() != null && !parentPrefixes.contains(element.getPrefix())) {
            thisLevelPrefixes.put(element.getPrefix(), element.getNamespaceURI());
        }

        if (element.hasAttributes()) {
            NamedNodeMap map = element.getAttributes();
            for (int i = 0; i < map.getLength(); i++) {
                Node attr = map.item(i);
                if (attr.getNodeName().startsWith("xmlns"))
                    continue;
                if (attr.getPrefix() != null && !parentPrefixes.contains(attr.getPrefix())) {
                    thisLevelPrefixes.put(attr.getPrefix(), element.getNamespaceURI());
                }
                b.append(" ");
                b.append(attr.getNodeName());
                b.append("=\"");
                b.append(attr.getNodeValue());
                b.append("\"");
            }
        }

        if (namespaceURI != null && !thisLevelPrefixes.containsValue(namespaceURI)
                && !namespaceURI.equals(element.getParentNode().getNamespaceURI())) {
            b.append(" xmlns=\"").append(namespaceURI).append("\"");
        }

        for (Map.Entry<String, String> entry : thisLevelPrefixes.entrySet()) {
            b.append(" xmlns:").append(entry.getKey()).append("=\"").append(entry.getValue()).append("\"");
            parentPrefixes.add(entry.getKey());
        }

        NodeList children = element.getChildNodes();
        boolean hasOnlyAttributes = true;
        for (int i = 0; i < children.getLength(); i++) {
            Node child = children.item(i);
            if (child.getNodeType() != Node.ATTRIBUTE_NODE) {
                hasOnlyAttributes = false;
                break;
            }
        }
        if (!hasOnlyAttributes) {
            b.append(">");
            for (int i = 0; i < children.getLength(); i++) {
                b.append(nodeToString(children.item(i), parentPrefixes, children.item(i).getNamespaceURI()));
            }
            b.append("</");
            b.append(element.getNodeName());
            b.append(">");
        } else {
            b.append("/>");
        }

        for (String thisLevelPrefix : thisLevelPrefixes.keySet()) {
            parentPrefixes.remove(thisLevelPrefix);
        }

    } else if (node.getNodeValue() != null) {
        b.append(encodeText(node.getNodeValue()));
    }

    return b.toString();
}

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

private static void addImports(CompilationUnit unit, List<String> imports) {
    List<ImportDeclaration> unitImports = unit.getImports();
    unitImports = (unitImports == null) ? new ArrayList<ImportDeclaration>() : unitImports;
    Set<String> oldImports = new HashSet<String>();
    for (ImportDeclaration decalaration : unitImports) {
        oldImports.add(decalaration.getName().toString());
    }//  w  w  w . ja va 2  s  . c om
    for (String imp : new LinkedHashSet<String>(imports)) {
        if (!oldImports.contains(imp)) {
            unitImports.add(new ImportDeclaration(makeNameExpr(imp), false, false));
        }
    }
    unit.setImports(unitImports);
}

From source file:com.microfocus.application.automation.tools.octane.executor.UFTTestDetectionService.java

private static void removeTestDuplicatedForUpdateTests(UftTestDiscoveryResult result) {
    Set<String> keys = new HashSet<>();
    List<AutomatedTest> testsToRemove = new ArrayList<>();
    for (AutomatedTest test : result.getUpdatedTests()) {
        String key = test.getPackage() + "_" + test.getName();
        if (keys.contains(key)) {
            testsToRemove.add(test);//  ww  w .jav a2 s  .co  m
        }
        keys.add(key);

    }
    result.getAllTests().removeAll(testsToRemove);
}

From source file:Main.java

protected static String nodeToString(Node node, Set<String> parentPrefixes, String namespaceURI)
        throws Exception {
    StringBuilder b = new StringBuilder();

    if (node == null) {
        return "";
    }/*w  w w .  jav a 2  s  . c o  m*/

    if (node instanceof Element) {
        Element element = (Element) node;
        b.append("<");
        b.append(element.getNodeName());

        Map<String, String> thisLevelPrefixes = new HashMap();
        if (element.getPrefix() != null && !parentPrefixes.contains(element.getPrefix())) {
            thisLevelPrefixes.put(element.getPrefix(), element.getNamespaceURI());
        }

        if (element.hasAttributes()) {
            NamedNodeMap map = element.getAttributes();
            for (int i = 0; i < map.getLength(); i++) {
                Node attr = map.item(i);
                if (attr.getNodeName().startsWith("xmlns"))
                    continue;
                if (attr.getPrefix() != null && !parentPrefixes.contains(attr.getPrefix())) {
                    thisLevelPrefixes.put(attr.getPrefix(), element.getNamespaceURI());
                }
                b.append(" ");
                b.append(attr.getNodeName());
                b.append("=\"");
                b.append(attr.getNodeValue());
                b.append("\"");
            }
        }

        if (namespaceURI != null && !thisLevelPrefixes.containsValue(namespaceURI)
                && !namespaceURI.equals(element.getParentNode().getNamespaceURI())) {
            b.append(" xmlns=\"").append(namespaceURI).append("\"");
        }

        for (Map.Entry<String, String> entry : thisLevelPrefixes.entrySet()) {
            b.append(" xmlns:").append(entry.getKey()).append("=\"").append(entry.getValue()).append("\"");
            parentPrefixes.add(entry.getKey());
        }

        NodeList children = element.getChildNodes();
        boolean hasOnlyAttributes = true;
        for (int i = 0; i < children.getLength(); i++) {
            Node child = children.item(i);
            if (child.getNodeType() != Node.ATTRIBUTE_NODE) {
                hasOnlyAttributes = false;
                break;
            }
        }
        if (!hasOnlyAttributes) {
            b.append(">");
            for (int i = 0; i < children.getLength(); i++) {
                b.append(nodeToString(children.item(i), parentPrefixes, children.item(i).getNamespaceURI()));
            }
            b.append("</");
            b.append(element.getNodeName());
            b.append(">");
        } else {
            b.append("/>");
        }

        for (String thisLevelPrefix : thisLevelPrefixes.keySet()) {
            parentPrefixes.remove(thisLevelPrefix);
        }

    } else if (node.getNodeValue() != null) {
        b.append(encodeText(node.getNodeValue(), node instanceof Attr));
    }

    return b.toString();
}

From source file:Main.java

protected static String nodeToString(Node node, Set<String> parentPrefixes, String namespaceURI)
        throws Exception {
    StringBuilder b = new StringBuilder();

    if (node == null) {
        return "";
    }/*w w  w .j a v a  2  s.co m*/

    if (node instanceof Element) {
        Element element = (Element) node;
        b.append("<");
        b.append(element.getNodeName());

        Map<String, String> thisLevelPrefixes = new HashMap();
        if (element.getPrefix() != null && !parentPrefixes.contains(element.getPrefix())) {
            thisLevelPrefixes.put(element.getPrefix(), element.getNamespaceURI());
        }

        if (element.hasAttributes()) {
            NamedNodeMap map = element.getAttributes();
            for (int i = 0; i < map.getLength(); i++) {
                Node attr = map.item(i);
                if (attr.getNodeName().startsWith("xmlns"))
                    continue;
                if (attr.getPrefix() != null && !parentPrefixes.contains(attr.getPrefix())) {
                    thisLevelPrefixes.put(attr.getPrefix(), element.getNamespaceURI());
                }
                b.append(" ");
                b.append(attr.getNodeName());
                b.append("=\"");
                b.append(attr.getNodeValue());
                b.append("\"");
            }
        }

        if (namespaceURI != null && !thisLevelPrefixes.containsValue(namespaceURI)
                && !namespaceURI.equals(element.getParentNode().getNamespaceURI())) {
            b.append(" xmlns=\"").append(namespaceURI).append("\"");
        }

        for (Map.Entry<String, String> entry : thisLevelPrefixes.entrySet()) {
            b.append(" xmlns:").append(entry.getKey()).append("=\"").append(entry.getValue()).append("\"");
            parentPrefixes.add(entry.getKey());
        }

        NodeList children = element.getChildNodes();
        boolean hasOnlyAttributes = true;
        for (int i = 0; i < children.getLength(); i++) {
            Node child = children.item(i);
            if (child.getNodeType() != Node.ATTRIBUTE_NODE) {
                hasOnlyAttributes = false;
                break;
            }
        }
        if (!hasOnlyAttributes) {
            b.append(">");
            for (int i = 0; i < children.getLength(); i++) {
                b.append(nodeToString(children.item(i), parentPrefixes, children.item(i).getNamespaceURI()));
            }
            b.append("</");
            b.append(element.getNodeName());
            b.append(">");
        } else {
            b.append("/>");
        }

        for (String thisLevelPrefix : thisLevelPrefixes.keySet()) {
            parentPrefixes.remove(thisLevelPrefix);
        }

    } else if (node.getNodeValue() != null) {

        b.append(encodeText(node.getNodeValue()));
    }

    return b.toString();
}

From source file:com.offbynull.coroutines.instrumenter.asm.SearchUtils.java

/**
 * Find instructions in a certain class that are of a certain set of opcodes.
 * @param insnList instruction list to search through
 * @param opcodes opcodes to search for//  ww  w. j a v  a 2 s  .c  o  m
 * @return list of instructions that contain the opcodes being searched for
 * @throws NullPointerException if any argument is {@code null}
 * @throws IllegalArgumentException if {@code opcodes} is empty
 */
public static List<AbstractInsnNode> searchForOpcodes(InsnList insnList, int... opcodes) {
    Validate.notNull(insnList);
    Validate.notNull(opcodes);
    Validate.isTrue(opcodes.length > 0);

    List<AbstractInsnNode> ret = new LinkedList<>();

    Set<Integer> opcodeSet = new HashSet<>();
    Arrays.stream(opcodes).forEach((x) -> opcodeSet.add(x));

    Iterator<AbstractInsnNode> it = insnList.iterator();
    while (it.hasNext()) {
        AbstractInsnNode insnNode = it.next();
        if (opcodeSet.contains(insnNode.getOpcode())) {
            ret.add(insnNode);
        }
    }

    return ret;
}

From source file:com.github.gfx.android.orma.migration.SchemaDiffMigration.java

public static Map<String, SQLiteMaster> loadMetadata(Database db, List<? extends MigrationSchema> schemas) {
    Map<String, SQLiteMaster> metadata = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);

    Set<String> tableNames = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
    for (MigrationSchema schema : schemas) {
        tableNames.add(schema.getTableName());
    }/*from  w  ww .j  a  v  a 2s.com*/

    for (Map.Entry<String, SQLiteMaster> entry : SQLiteMaster.loadTables(db).entrySet()) {
        if (tableNames.contains(entry.getKey())) {
            metadata.put(entry.getKey(), entry.getValue());
        }
    }
    return metadata;
}

From source file:com.imaginea.mongodb.controllers.BaseController.java

/**
 * Validates connectionId with the connectionId Array present in session.
 *
 * @param connectionId Mongo Db config information provided to user at time of login.
 * @param logger       Logger to write error message to
 * @param request      Request made by client containing session attributes.
 * @return null if connectionId is valid else error object.
 *///from  w ww  . ja v  a2  s. c o m
protected static String validateConnectionId(String connectionId, Logger logger, HttpServletRequest request) {

    HttpSession session = request.getSession();
    Set<String> existingConnectionIdsInSession = (Set<String>) session
            .getAttribute("existingConnectionIdsInSession");
    if (existingConnectionIdsInSession == null) {
        InvalidHTTPRequestException e = new InvalidHTTPRequestException(ErrorCodes.INVALID_SESSION,
                "Invalid Session");
        return formErrorResponse(logger, e);
    }

    String response = null;
    if (connectionId == null || !existingConnectionIdsInSession.contains(connectionId)) {
        InvalidHTTPRequestException e = new InvalidHTTPRequestException(ErrorCodes.INVALID_CONNECTION,
                "Invalid Connection");
        return formErrorResponse(logger, e);
    }
    return response;
}

From source file:net.intelliant.util.UtilCommon.java

/**
 * 1. Compressed JPEG images./*  w ww  .jav  a  2s. c o  m*/
 * 2. Prefixes (if required) image server URL to image src locations. 
 * 
 * @return a <code>String</code> value
 */
public static String parseHtmlAndGenerateCompressedImages(String html) throws IOException {
    if (UtilValidate.isEmpty(html)) {
        return html;
    }
    org.jsoup.nodes.Document doc = Jsoup.parse(html);
    Elements images = doc.select("img[src~=(?i)\\.(jpg|jpeg|png|gif)]");
    if (images != null && images.size() > 0) {
        Set<String> imageLocations = new HashSet<String>();
        for (Element image : images) {
            String srcAttributeValue = image.attr("src");
            if (!(imageLocations.contains(srcAttributeValue))) {
                if (Debug.infoOn()) {
                    Debug.logInfo(
                            "[parseHtmlAndGenerateCompressedImages] originalSource >> " + srcAttributeValue,
                            module);
                }
                if (!UtilValidate.isUrl(srcAttributeValue)) {
                    int separatorIndex = srcAttributeValue.lastIndexOf("/");
                    if (separatorIndex == -1) {
                        separatorIndex = srcAttributeValue
                                .lastIndexOf("\\"); /** just in case some one plays with html source. */
                    }
                    if (separatorIndex != -1) {
                        String originalFileName = srcAttributeValue.substring(separatorIndex + 1);

                        /* Handling spaces in file-name to make url friendly. */
                        String outputFileName = StringEscapeUtils.escapeHtml(originalFileName);
                        /** Compression works for jpeg's only. 
                        if (originalFileName.endsWith("jpg") || originalFileName.endsWith("jpeg")) {
                           try {
                              outputFileName = generateCompressedImageForInputFile(imageUploadLocation, originalFileName);
                           } catch (NoSuchAlgorithmException e) {
                              Debug.logError(e, module);
                              return html;
                           }
                        }
                        */
                        StringBuilder finalLocation = new StringBuilder(campaignBaseURL);
                        finalLocation.append(imageUploadWebApp).append(outputFileName);
                        html = StringUtil.replaceString(html, srcAttributeValue, finalLocation.toString());
                        imageLocations.add(srcAttributeValue);
                    }
                } else {
                    Debug.logWarning("[parseHtmlAndGenerateCompressedImages] ignoring encountered HTML URL..",
                            module);
                }
            }
        }
    } else {
        if (Debug.infoOn()) {
            Debug.logInfo("[parseHtmlAndGenerateCompressedImages] No jpeg images, doing nothing..", module);
        }
    }
    if (Debug.infoOn()) {
        Debug.logInfo("[parseHtmlAndGenerateCompressedImages] returning html >> " + html, module);
    }
    return html;
}