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.bibisco.manager.SceneTagsManager.java

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

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

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

    List<com.bibisco.bean.CharacterDTO> lListCharacterDTO = CharacterManager.loadAll();
    List<ChapterDTO> lListChapters = ChapterManager.loadAll();

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

    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_character");
        List<VSceneTags> lListVSceneTags = lVSceneTagsMapper.selectByExample(lVSceneTagsExample);

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

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

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

            // populate result map
            for (CharacterDTO lCharacterDTO : lListCharacterDTO) {
                List<Boolean> lListCharacterChapterPresence = new ArrayList<Boolean>();
                lMapCharacterChapterPresence.put(lCharacterDTO.getIdCharacter().toString(),
                        lListCharacterChapterPresence);
                for (ChapterDTO lChapterDTO : lListChapters) {
                    Set<Integer> lSetCharacters = lMapCharactersChaptersDistribution
                            .get(lChapterDTO.getPosition());
                    if (lSetCharacters != null && !lSetCharacters.isEmpty()
                            && lSetCharacters.contains(lCharacterDTO.getIdCharacter())) {
                        lListCharacterChapterPresence.add(Boolean.TRUE);
                    } else {
                        lListCharacterChapterPresence.add(Boolean.FALSE);
                    }
                }
            }
        }

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

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

    return lMapCharacterChapterPresence;
}

From source file:net.i2p.util.I2PSSLSocketFactory.java

/**
 * Adapted from Jetty SslContextFactory.java
 *
 * @param toEnable Add all these to what is enabled, if supported
 * @param toExclude Remove all these from what is enabled
 * @since 0.9.16//from  w  ww .j  a  v  a2  s.co  m
 */
private static String[] select(String[] enabledArr, String[] supportedArr, List<String> toEnable,
        List<String> toExclude) {
    Log log = I2PAppContext.getGlobalContext().logManager().getLog(I2PSSLSocketFactory.class);
    Set<String> selected = new HashSet<String>(enabledArr.length);
    selected.addAll(Arrays.asList(enabledArr));
    selected.removeAll(toExclude);
    Set<String> supported = new HashSet<String>(supportedArr.length);
    supported.addAll(Arrays.asList(supportedArr));
    for (String s : toEnable) {
        if (supported.contains(s)) {
            if (selected.add(s)) {
                if (log.shouldLog(Log.INFO))
                    log.info("Added, previously disabled: " + s);
            }
        } else if (log.shouldLog(Log.INFO)) {
            log.info("Not supported in this JVM: " + s);
        }
    }
    if (selected.isEmpty()) {
        // shouldn't happen, Java 6 supports TLSv1
        log.logAlways(Log.WARN, "No TLS support for SSLEepGet, falling back");
        return enabledArr;
    }
    if (log.shouldLog(Log.DEBUG)) {
        List<String> foo = new ArrayList<String>(selected);
        Collections.sort(foo);
        log.debug("Selected: " + foo);
    }
    return selected.toArray(new String[selected.size()]);
}

From source file:com.healthmarketscience.jackcess.impl.office.EncryptionHeader.java

public static EncryptionHeader read(ByteBuffer encProvBuf, Set<CryptoAlgorithm> validCryptoAlgos,
        Set<HashAlgorithm> validHashAlgos) {
    // read length of header
    int headerLen = encProvBuf.getInt();

    // read header (temporarily narrowing buf to header)
    int curLimit = encProvBuf.limit();
    int curPos = encProvBuf.position();
    encProvBuf.limit(curPos + headerLen);
    EncryptionHeader header = new EncryptionHeader(encProvBuf);

    // verify parameters
    if (!validCryptoAlgos.contains(header.getCryptoAlgorithm())) {
        throw new IllegalStateException(header + " crypto algorithm must be one of " + validCryptoAlgos);
    }//from  ww w.  j  a va  2s. c o  m

    if (!validHashAlgos.contains(header.getHashAlgorithm())) {
        throw new IllegalStateException(header + " hash algorithm must be one of " + validHashAlgos);
    }

    int keySize = header.getKeySize();
    if (!header.getCryptoAlgorithm().isValidKeySize(keySize)) {
        throw new IllegalStateException(header + " key size is outside allowable range");
    }
    if ((keySize % 8) != 0) {
        throw new IllegalStateException(header + " key size must be multiple of 8");
    }

    // move to after header
    encProvBuf.limit(curLimit);
    encProvBuf.position(curPos + headerLen);

    return header;
}

From source file:edu.du.penrose.systems.fedoraApp.util.FedoraAppUtil.java

/**
 * @param batchSetName accepts a batchSetName of type institution_batchSet_TASK.
 * NOTE: the task may or may not be enabled in the taskEnable.properties. This method does
 * not check the taskEnable.properties file.
 * //from  www. ja va  2s  .  c o  m
 * @return true if there is a file containing backgroud task ingest options
 */
public static boolean isHasTaskIngestPropertiesFile(String batchSetName) {
    if (batchSetName == null)
        return false;

    boolean result = false;

    try {
        Set tempSet = getTaskConfiguredInstitutions();

        if (tempSet.contains(batchSetName))
            result = true;

    } catch (Exception e) {
        // TBD
    }

    return result;
}

From source file:edu.du.penrose.systems.fedoraApp.util.FedoraAppUtil.java

/**
 * @param batchSetName accepts a batchSetName of type institution_batchSet_REMOTE.
 * To be remote enabled a batchSet must have a batchSet_REMOTE.properites file.
 * NOTE: the task may or may not be enabled in the taskEnable.properties. This method does
 * not check the taskEnable.properties file.
 * //from  w  ww.ja  v a2s.com
 * @return true if there is a file containing remote ingest options
 */
public static boolean isHasRemoteIngestPropertiesFile(String batchSetName) {
    if (batchSetName == null)
        return false;

    boolean result = false;

    try {
        Set tempSet = getRemoteConfiguredInstitutions();

        if (tempSet.contains(batchSetName))
            result = true;

    } catch (Exception e) {
        // TBD
    }

    return result;
}

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

/**
 * Get a Map of non-null <em>simple</em> bean properties for an object.
 * /*from  w w  w  . j  a  va2s.co  m*/
 * @param o
 *        the object to inspect
 * @param ignore
 *        a set of property names to ignore (optional)
 * @return Map (never <em>null</em>)
 * @since 1.1
 */
public static Map<String, Object> getSimpleBeanProperties(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;
        }
        Class<?> propType = bean.getPropertyType(propName);
        if (!(propType.isPrimitive() || propType.isEnum() || String.class.isAssignableFrom(propType)
                || Number.class.isAssignableFrom(propType) || Character.class.isAssignableFrom(propType)
                || Byte.class.isAssignableFrom(propType) || Date.class.isAssignableFrom(propType))) {
            continue;
        }
        Object propValue = bean.getPropertyValue(propName);
        if (propValue == null) {
            continue;
        }
        if (propType.isEnum()) {
            propValue = propValue.toString();
        } else if (Date.class.isAssignableFrom(propType)) {
            propValue = ((Date) propValue).getTime();
        }
        result.put(propName, propValue);
    }
    return result;
}

From source file:com.aurel.track.item.consInf.ConsInfBL.java

/**
 * Deletes those elements from list//from  www.j  av a  2  s.co  m
 * which correspond to elements of values array
 * @param personBeans
 * @param values
 * @return
 */
public static void deleteSelected(List<TPersonBean> personBeans, Integer[] values) {
    if (personBeans == null || values == null || values.length == 0) {
        return;
    }
    Set<Integer> valuesSet = new HashSet<Integer>();
    for (int i = 0; i < values.length; i++) {
        valuesSet.add(values[i]);
    }
    Iterator<TPersonBean> iterator = personBeans.iterator();
    while (iterator.hasNext()) {
        TPersonBean personBean = iterator.next();
        if (valuesSet.contains(personBean.getObjectID())) {
            iterator.remove();
        }
    }
}

From source file:edu.umass.cs.utils.Util.java

public static Set<Object> diff(Set<?> s1, Set<?> s2) {
    Set<Object> diff = new HashSet<Object>();
    for (Object node : s1)
        if (!s2.contains(node))
            diff.add(node);//  w w  w.  j a v a2 s .  co m
    return diff;
}

From source file:hsyndicate.utils.IPUtils.java

public static String selectLocalIPAddress(String[] addresses) {
    Collection<String> localhostAddress = IPUtils.getHostAddress();
    Set<String> localhostAddrSet = new HashSet<String>();
    localhostAddrSet.addAll(localhostAddress);

    for (String addr : addresses) {
        String hostname = addr;/*from ww w .jav  a  2 s  . c om*/
        int pos = hostname.indexOf(":");
        if (pos > 0) {
            hostname = hostname.substring(0, pos);
        }

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

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

    return null;
}

From source file:gov.nih.nci.cabig.caaers.web.utils.WebUtils.java

public static List<Study> filterStudiesByCoordinatorOrSponsor(List<Study> studies,
        Set<Organization> organizations, Organization subjectOrganization) {

    List<Study> _s = new ArrayList<Study>();

    for (Study s : studies) {
        boolean isGood = false;

        Organization scc = s.getStudyCoordinatingCenter().getOrganization();
        Organization sfs = s.getPrimaryFundingSponsorOrganization();

        // select studies coordinated by RS
        if (organizations.contains(scc) || organizations.contains(sfs)) {
            isGood = true;/* w  w w  .j ava2  s. co  m*/
        }

        // add studies where RS's organizaton is just a StudySite if it's the same as Subject's Site
        if (organizations.contains(subjectOrganization)) {
            for (StudySite ss : s.getStudySites()) {
                if (ss.getOrganization().equals(subjectOrganization))
                    isGood = true;
            }
        }

        if (isGood)
            _s.add(s);

    }

    return _s;
}