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:com.asakusafw.testdriver.compiler.util.DeploymentUtil.java

private static void putEntry(ZipOutputStream zip, File source, String path, Set<String> saw)
        throws IOException {
    assert zip != null;
    assert source != null;
    assert !(source.isFile() && path == null);
    if (source.isDirectory()) {
        for (File child : list(source)) {
            String next = (path == null) ? child.getName() : path + '/' + child.getName();
            putEntry(zip, child, next, saw);
        }//from w  w w .  j av a 2 s . co m
    } else {
        if (saw.contains(path)) {
            return;
        }
        saw.add(path);
        zip.putNextEntry(new ZipEntry(path));
        try (InputStream in = new BufferedInputStream(new FileInputStream(source))) {
            LOG.trace("Copy into archive: {} -> {}", source, path);
            copyStream(in, zip);
        }
        zip.closeEntry();
    }
}

From source file:net.geoprism.ontology.Classifier.java

/**
 * Returns the JSONObject representation of the node and all of its children nodes
 * //from  w  ww.ja  va  2 s  .  co m
 * @param _classifier
 *          Entity to serialize into a JSONObject
 * @param _ids
 *          List of classifier ids in which to include the children in the serialization
 * @param _isRoot
 *          Flag indicating if the classifier represents a root node of the tree
 * @return
 */
private static JSONObject getJSONObject(Classifier _classifier, Set<String> _ids, boolean _isRoot) {
    try {
        JSONArray children = new JSONArray();

        if (_ids.contains(_classifier.getId())) {
            OIterator<? extends ClassifierIsARelationship> iterator = null;

            try {
                // Get the relationships where this object is the parent

                ClassifierIsARelationshipQuery query = new ClassifierIsARelationshipQuery(new QueryFactory());
                query.WHERE(query.getParent().EQ(_classifier));
                query.ORDER_BY_ASC(((AttributeReference) query.getChild())
                        .aLocalCharacter(Classifier.DISPLAYLABEL).localize());
                iterator = query.getIterator();

                List<? extends ClassifierIsARelationship> relationships = iterator.getAll();

                for (ClassifierIsARelationship relationship : relationships) {
                    Classifier child = relationship.getChild();

                    JSONObject parentRecord = new JSONObject();
                    parentRecord.put("parentId", relationship.getParentId());
                    parentRecord.put("relId", relationship.getId());
                    parentRecord.put("relType", ClassifierIsARelationship.CLASS);

                    JSONObject object = Classifier.getJSONObject(child, _ids, false);
                    object.put("parentRecord", parentRecord);

                    children.put(object);
                }

            } finally {
                if (iterator != null) {
                    iterator.close();
                }
            }
        }

        String label = _classifier.getDisplayLabel().getValue();

        JSONObject object = new JSONObject();
        object.put("label", label);
        object.put("id", _classifier.getId());
        object.put("type", _classifier.getType());
        object.put("children", children);
        object.put("fetched", (children.length() > 0));

        return object;
    } catch (JSONException e) {
        throw new ProgrammingErrorException(e);
    }
}

From source file:net.sf.jabref.collab.ChangeScanner.java

private static Optional<BibtexString> findString(BibDatabase base, String name, Set<Object> used) {
    if (!base.hasStringLabel(name)) {
        return Optional.empty();
    }/* www  .  j a  va2  s.  c  om*/
    for (String key : base.getStringKeySet()) {
        BibtexString bs = base.getString(key);
        if (bs.getName().equals(name) && !used.contains(key)) {
            used.add(key);
            return Optional.of(bs);
        }
    }
    return Optional.empty();
}

From source file:net.solarnetwork.node.util.ClassUtils.java

/**
 * Get a Map of non-null bean properties for an object.
 * //from   w ww  .j  a v a2  s . com
 * @param o
 *        the object to inspect
 * @param ignore
 *        a set of property names to ignore (optional)
 * @return Map (never null)
 */
public static Map<String, Object> getBeanProperties(Object o, Set<String> ignore) {
    if (ignore == null) {
        ignore = DEFAULT_BEAN_PROP_NAME_IGNORE;
    }
    Map<String, Object> result = new LinkedHashMap<String, Object>();
    BeanWrapper bean = new BeanWrapperImpl(o);
    PropertyDescriptor[] props = bean.getPropertyDescriptors();
    for (PropertyDescriptor prop : props) {
        if (prop.getReadMethod() == null) {
            continue;
        }
        String propName = prop.getName();
        if (ignore != null && ignore.contains(propName)) {
            continue;
        }
        Object propValue = bean.getPropertyValue(propName);
        if (propValue == null) {
            continue;
        }
        result.put(propName, propValue);
    }
    return result;
}

From source file:com.tech.utils.CustomCollectionUtil.java

/**
 * Method to calculate standard set difference operation. Example : Consider
 * set1 = {1,2,3,4,5} set2 = {1,2,3} then, the output of this method will be
 * setDifference = {4,5}/*  w w w. j  av  a 2s. c om*/
 * 
 * @param set1
 * @param set2
 * @return setDifference
 */
public static Set<Long> setDifference(Set<Long> itemSet1, Set<Long> itemSet2) {
    Set<Long> setDifference = new HashSet<Long>();
    /*
     * Perform set difference operation only if the set1 are not empty.
     */
    if (itemSet1 != null && !itemSet1.isEmpty()) {
        if (itemSet2 != null && !itemSet2.isEmpty()) {
            for (Long item : itemSet1) {
                if (!itemSet2.contains(item)) {
                    setDifference.add(item);
                }
            }
        } else {
            for (Long item : itemSet1) {
                setDifference.add(item);
            }
        }
    }
    return setDifference;
}

From source file:de.unisb.cs.st.javaslicer.slicing.DirectSlicer.java

private static <T> Set<T> intersect(Set<T> set1, Set<T> set2) {
    if (set1.isEmpty() || set2.isEmpty())
        return Collections.emptySet();

    Set<T> smallerSet;//from ww w .  ja  v a2  s  . c  o  m
    Set<T> biggerSet;
    if (set1.size() < set2.size()) {
        smallerSet = set1;
        biggerSet = set2;
    } else {
        smallerSet = set2;
        biggerSet = set1;
    }

    Set<T> intersection = null;
    for (T obj : smallerSet) {
        if (biggerSet.contains(obj)) {
            if (intersection == null)
                intersection = new HashSet<T>();
            intersection.add(obj);
        }
    }

    if (intersection == null)
        return Collections.emptySet();
    return intersection;
}

From source file:com.bibisco.manager.SceneTagsManager.java

/**
**
 * @return a Map as//from w w  w.j  a  va2  s .c  o  m
 * 
 *                 Chapter.1 Chapter.2 Chapter.3
 * - location.1 -     X         X
 * - location.2 -               X
 * - location.3 -     X         X          
 * 
 */
public static Map<String, List<Boolean>> getLocationsChaptersPresence() {

    Map<String, List<Boolean>> lMapLocationChapterPresence = new HashMap<String, List<Boolean>>();

    mLog.debug("Start getLocationsChaptersDistribution()");

    List<com.bibisco.bean.LocationDTO> lListLocationDTO = LocationManager.loadAll();
    List<ChapterDTO> lListChapters = ChapterManager.loadAll();

    if (CollectionUtils.isEmpty(lListLocationDTO) || CollectionUtils.isEmpty(lListChapters)) {
        mLog.debug("End getStrandsChaptersDistribution()");
        return lMapLocationChapterPresence;
    }

    SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance().getSqlSessionFactoryProject();
    SqlSession lSqlSession = lSqlSessionFactory.openSession();
    try {

        VSceneTagsMapper lVSceneTagsMapper = lSqlSession.getMapper(VSceneTagsMapper.class);
        VSceneTagsExample lVSceneTagsExample = new VSceneTagsExample();
        lVSceneTagsExample.setOrderByClause("chapter_position, id_location");
        List<VSceneTags> lListVSceneTags = lVSceneTagsMapper.selectByExample(lVSceneTagsExample);

        if (lListVSceneTags != null && lListVSceneTags.size() > 0) {

            Map<Integer, Set<Integer>> lMapLocationsChaptersDistribution = new HashMap<Integer, Set<Integer>>();
            int lIntLastChapter = -1;
            Set<Integer> lSetChapterLocations = null;

            // filter duplicate items using a set
            for (VSceneTags lVSceneTags : lListVSceneTags) {
                if (lVSceneTags.getChapterPosition().intValue() != lIntLastChapter) {
                    lSetChapterLocations = new HashSet<Integer>();
                    lMapLocationsChaptersDistribution.put(lVSceneTags.getChapterPosition(),
                            lSetChapterLocations);
                    lIntLastChapter = lVSceneTags.getChapterPosition();
                }
                if (lVSceneTags.getIdLocation() != null) {
                    lSetChapterLocations.add(lVSceneTags.getIdLocation().intValue());
                }

            }

            // populate result map
            for (LocationDTO lLocationDTO : lListLocationDTO) {
                List<Boolean> lListLocationChapterPresence = new ArrayList<Boolean>();
                lMapLocationChapterPresence.put(lLocationDTO.getIdLocation().toString(),
                        lListLocationChapterPresence);
                for (ChapterDTO lChapterDTO : lListChapters) {
                    Set<Integer> lSetLocations = lMapLocationsChaptersDistribution
                            .get(lChapterDTO.getPosition());
                    if (lSetLocations != null && !lSetLocations.isEmpty()
                            && lSetLocations.contains(lLocationDTO.getIdLocation())) {
                        lListLocationChapterPresence.add(Boolean.TRUE);
                    } else {
                        lListLocationChapterPresence.add(Boolean.FALSE);
                    }
                }
            }
        }

    } catch (Throwable t) {
        mLog.error(t);
        throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION);
    } finally {
        lSqlSession.close();
    }

    mLog.debug("End getLocationsChaptersDistribution()");

    return lMapLocationChapterPresence;
}

From source file:com.espertech.esper.core.deploy.EPLModuleUtil.java

public static List<EPLModuleParseItem> parse(String module) {

    CharStream input;//ww w  .  j  a v  a  2  s  .  com
    try {
        input = new NoCaseSensitiveStream(new StringReader(module));
    } catch (IOException ex) {
        log.error("Exception reading model expression: " + ex.getMessage(), ex);
        return null;
    }

    EsperEPL2GrammarLexer lex = new EsperEPL2GrammarLexer(input);
    CommonTokenStream tokens = new CommonTokenStream(lex);

    List<EPLModuleParseItem> statements = new ArrayList<EPLModuleParseItem>();
    StringWriter current = new StringWriter();
    Integer lineNum = null;
    int charPosStart = 0;
    int charPos = 0;
    List<Token> tokenList = tokens.getTokens();
    Set<Integer> skippedSemicolonIndexes = getSkippedSemicolons(tokenList);
    int index = -1;
    for (Object token : tokenList) // Call getTokens first before invoking tokens.size! ANTLR problem
    {
        index++;
        Token t = (Token) token;
        boolean semi = t.getType() == EsperEPL2GrammarParser.SEMI && !skippedSemicolonIndexes.contains(index);
        if (semi) {
            if (current.toString().trim().length() > 0) {
                statements.add(new EPLModuleParseItem(current.toString().trim(), lineNum == null ? 0 : lineNum,
                        charPosStart, charPos));
                lineNum = null;
            }
            current = new StringWriter();
        } else {
            if ((lineNum == null) && (t.getType() != EsperEPL2GrammarParser.WS)) {
                lineNum = t.getLine();
                charPosStart = charPos;
            }
            current.append(t.getText());
            charPos += t.getText().length();
        }
    }

    if (current.toString().trim().length() > 0) {
        statements.add(new EPLModuleParseItem(current.toString().trim(), lineNum == null ? 0 : lineNum, 0, 0));
    }
    return statements;
}

From source file:org.eclipse.swt.examples.launcher.LauncherPlugin.java

/**
 * Constructs a list of available programs from registered extensions.
 * // w w w  . j a v  a2s.co  m
 * @return an ItemTreeNode representing the root of a tree of items (the root is not to be displayed)
 */
public static ItemTreeNode getLaunchItemTree() {
    ItemTreeNode categoryTree = new ItemTreeNode(
            new ItemDescriptor("<<Root>>", "<<Root>>", null, null, null, null, null, null));

    // get the platform's public plugin registry
    IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry();
    // retrieve all configuration elements registered at our launchItems extension-point
    IConfigurationElement[] configurationElements = extensionRegistry
            .getConfigurationElementsFor(LAUNCH_ITEMS_POINT_ID);

    if (configurationElements == null || configurationElements.length == 0) {
        logError(getResourceString("error.CouldNotFindRegisteredExtensions"), null);
        return categoryTree;
    }

    /* Collect all launch categories -- coalesce those with same ID */
    HashMap<String, ItemTreeNode> idMap = new HashMap<>();
    for (IConfigurationElement ce : configurationElements) {
        final String ceName = ce.getName();
        final String attribId = getItemAttribute(ce, LAUNCH_ITEMS_XML_ATTRIB_ID, null);

        if (idMap.containsKey(attribId))
            continue;
        if (ceName.equalsIgnoreCase(LAUNCH_ITEMS_XML_CATEGORY)) {
            final String attribName = getItemName(ce);
            ItemDescriptor theDescriptor = new ItemDescriptor(attribId, attribName, getItemDescription(ce),
                    null, null, null, null, ce);
            idMap.put(attribId, new ItemTreeNode(theDescriptor));
        }
    }

    /* Generate launch category hierarchy */
    Set<String> tempIdSet = new HashSet<>(); // used to prevent duplicates from being entered into the tree
    for (IConfigurationElement ce : configurationElements) {
        final String ceName = ce.getName();
        final String attribId = getItemAttribute(ce, LAUNCH_ITEMS_XML_ATTRIB_ID, null);

        if (tempIdSet.contains(attribId))
            continue;
        if (ceName.equalsIgnoreCase(LAUNCH_ITEMS_XML_CATEGORY)) {
            final ItemTreeNode theNode = idMap.get(attribId);
            addItemByCategory(ce, categoryTree, theNode, idMap);
            tempIdSet.add(attribId);
        }
    }

    /* Generate program tree */
    for (IConfigurationElement ce : configurationElements) {
        final String ceName = ce.getName();
        final String attribId = getItemAttribute(ce, LAUNCH_ITEMS_XML_ATTRIB_ID, null);

        if (idMap.containsKey(attribId))
            continue;
        if (ceName.equalsIgnoreCase(LAUNCH_ITEMS_XML_CATEGORY)) {
            // ignore
        } else if (ceName.equalsIgnoreCase(LAUNCH_ITEMS_XML_ITEM)) {
            final String enabled = getItemAttribute(ce, LAUNCH_ITEMS_XML_ATTRIB_ENABLED,
                    LAUNCH_ITEMS_XML_VALUE_TRUE);
            if (enabled.equalsIgnoreCase(LAUNCH_ITEMS_XML_VALUE_FALSE))
                continue;
            ItemDescriptor theDescriptor = createItemDescriptor(ce, attribId);

            if (theDescriptor != null) {
                final ItemTreeNode theNode = new ItemTreeNode(theDescriptor);
                addItemByCategory(ce, categoryTree, theNode, idMap);
                idMap.put(attribId, theNode);
            }
        }
    }
    return categoryTree;
}

From source file:au.org.ala.delta.best.Best.java

public static Pair<boolean[], Integer> getStatePresenceForAttribute(Attribute attr, int totalNumStates,
        OrderingType orderingType, DiagType diagType) {
    Character ch = attr.getCharacter();

    // has a boolean value for each character state. A true value
    // designates the presence of the corresponding character state
    // for the attribute.
    boolean[] statePresence = new boolean[totalNumStates];

    int numStatesPresent = 0;

    // determine which character states are present for the
    // attribute.

    if (attr.isUnknown()) {
        // treat attribute as variable
        Arrays.fill(statePresence, true);
        numStatesPresent = totalNumStates;
    } else if (attr.isInapplicable() && (orderingType == OrderingType.SEPARATE
            || (orderingType == OrderingType.DIAGNOSE && diagType == DiagType.SPECIMENS))) {
        // treat attribute as variable
        Arrays.fill(statePresence, true);
        numStatesPresent = totalNumStates;
    } else {/*from  w w w  . j  a  v  a2 s  .c  o  m*/
        Arrays.fill(statePresence, false);

        if (ch.getCharacterType() == CharacterType.OrderedMultiState
                || ch.getCharacterType() == CharacterType.UnorderedMultiState) {
            MultiStateAttribute multiStateAttr = (MultiStateAttribute) attr;
            Set<Integer> attrPresentStates = multiStateAttr.getPresentStates();

            for (int i = 0; i < totalNumStates; i++) {
                if (attrPresentStates.contains(i + 1)) {
                    statePresence[i] = true;
                    numStatesPresent++;
                }
            }

        } else if (ch.getCharacterType() == CharacterType.IntegerNumeric) {
            IntegerCharacter intChar = (IntegerCharacter) ch;
            IntegerAttribute intAttr = (IntegerAttribute) attr;

            // for an integer character, 1 state for each value
            // between
            // the minimum and
            // maximum (inclusive), 1 state for all values below the
            // minimum, and 1 state for
            // all values above the maximum

            Set<Integer> attrPresentStates = intAttr.getPresentValues();

            int offset = intChar.getMinimumValue() - 1;

            for (int i = 0; i < totalNumStates; i++) {
                if (attrPresentStates.contains(i + offset)) {
                    statePresence[i] = true;
                    numStatesPresent++;
                }
            }

        } else if (ch.getCharacterType() == CharacterType.RealNumeric) {
            RealCharacter realChar = (RealCharacter) ch;
            RealAttribute realAttr = (RealAttribute) attr;
            FloatRange presentRange = realAttr.getPresentRange();

            // convert real value into multistate value.
            numStatesPresent = generateKeyStatesForRealCharacter(realChar, presentRange, statePresence);
        } else {
            throw new RuntimeException("Invalid character type " + ch.toString());
        }
    }

    return new Pair<boolean[], Integer>(statePresence, numStatesPresent);
}