Example usage for java.util HashSet clear

List of usage examples for java.util HashSet clear

Introduction

In this page you can find the example usage for java.util HashSet clear.

Prototype

public void clear() 

Source Link

Document

Removes all of the elements from this set.

Usage

From source file:org.keycloak.testsuite.authorization.ResourcePermissionManagementTest.java

@Test
public void testCreateForTypeWithMultiplePolicies() throws Exception {
    createAlbumResourceTypePermission();

    HashSet<String> roles = new HashSet<>();

    roles.add("admin");

    Map<String, DefaultEvaluation> evaluationsAdminRole = performEvaluation(
            Arrays.asList(new ResourcePermission(albumResource, Collections.emptyList(), resourceServer)),
            createAccessToken(roles), createClientConnection("127.0.0.1"));

    assertEquals(2, evaluationsAdminRole.size());
    assertTrue(evaluationsAdminRole.containsKey(this.administrationPolicy.getId()));
    assertTrue(evaluationsAdminRole.containsKey(this.anyUserPolicy.getId()));
    assertEquals(Effect.DENY, evaluationsAdminRole.get(this.anyUserPolicy.getId()).getEffect());
    assertEquals(Effect.PERMIT, evaluationsAdminRole.get(this.administrationPolicy.getId()).getEffect());

    evaluationsAdminRole = performEvaluation(
            Arrays.asList(new ResourcePermission(albumResource, Collections.emptyList(), resourceServer)),
            createAccessToken(roles), createClientConnection("127.0.0.10"));

    assertEquals(2, evaluationsAdminRole.size());
    assertTrue(evaluationsAdminRole.containsKey(this.administrationPolicy.getId()));
    assertTrue(evaluationsAdminRole.containsKey(this.anyUserPolicy.getId()));
    assertEquals(Effect.DENY, evaluationsAdminRole.get(this.anyUserPolicy.getId()).getEffect());
    assertEquals(Effect.DENY, evaluationsAdminRole.get(this.administrationPolicy.getId()).getEffect());

    roles.clear();
    roles.add("user");

    Map<String, DefaultEvaluation> evaluationsUserRole = performEvaluation(
            Arrays.asList(new ResourcePermission(albumResource, Collections.emptyList(), resourceServer)),
            createAccessToken(roles), createClientConnection("127.0.0.1"));

    assertEquals(2, evaluationsUserRole.size());
    assertTrue(evaluationsUserRole.containsKey(this.administrationPolicy.getId()));
    assertTrue(evaluationsUserRole.containsKey(this.anyUserPolicy.getId()));
    assertEquals(Effect.PERMIT, evaluationsUserRole.get(this.anyUserPolicy.getId()).getEffect());
    assertEquals(Effect.DENY, evaluationsUserRole.get(this.administrationPolicy.getId()).getEffect());
}

From source file:com.datatorrent.stram.engine.StreamingContainer.java

public void teardown() {
    operateListeners(containerContext, false);

    deactivate();/*ww  w.  j  a va  2 s  .c o m*/

    assert (streams.isEmpty());

    eventBus.shutdown();

    nodes.clear();

    HashSet<WindowGenerator> gens = new HashSet<WindowGenerator>();
    gens.addAll(generators.values());
    generators.clear();
    for (WindowGenerator wg : gens) {
        wg.teardown();
    }

    if (bufferServer != null) {
        eventloop.stop(bufferServer);
        eventloop.stop();
    }

    gens.clear();
}

From source file:org.tinymediamanager.core.movie.tasks.MovieUpdateDatasourceTask2.java

/**
 * for SingleMovie or DiscFolders//from   www. jav a2s. c  o m
 *
 * @param dataSource
 *          the data source
 * @param movieDir
 *          the movie folder
 * @param isDiscFolder
 *          is the movie in a disc folder?
 */
private void createSingleMovieFromDir(Path dataSource, Path movieDir, boolean isDiscFolder) {
    LOGGER.info(
            "Parsing single movie directory: " + movieDir + " (are we a disc folder? " + isDiscFolder + ")");

    Path relative = dataSource.relativize(movieDir);
    // STACKED FOLDERS - go up ONE level (only when the stacked folder ==
    // stacking marker)
    // movie/CD1/ & /movie/CD2 -> go up
    // movie CD1/ & /movie CD2 -> NO - there could be other files/folders there

    // if (!Utils.getFolderStackingMarker(relative.toString()).isEmpty() &&
    // level > 1) {
    if (!Utils.getFolderStackingMarker(relative.toString()).isEmpty()
            && Utils.getFolderStackingMarker(relative.toString()).equals(movieDir.getFileName().toString())) {
        movieDir = movieDir.getParent();
    }

    Movie movie = movieList.getMovieByPath(movieDir);
    HashSet<Path> allFiles = getAllFilesRecursive(movieDir, 3); // need 3 (was
                                                                // 2) because
                                                                // extracted BD
    filesFound.add(movieDir.toAbsolutePath()); // our global cache
    filesFound.addAll(allFiles); // our global cache

    // convert to MFs (we need it anyways at the end)
    ArrayList<MediaFile> mfs = new ArrayList<>();
    for (Path file : allFiles) {
        mfs.add(new MediaFile(file));
    }
    allFiles.clear();

    if (movie == null) {
        LOGGER.debug("| movie not found; looking for NFOs");
        movie = new Movie();
        String bdinfoTitle = ""; // title parsed out of BDInfo
        String videoName = ""; // title from file

        // ***************************************************************
        // first round - try to parse NFO(s) first
        // ***************************************************************
        // TODO: add movie.addMissingMetaData(otherMovie) to get merged movie from
        // multiple NFOs ;)
        for (MediaFile mf : mfs) {

            if (mf.getType().equals(MediaFileType.NFO)) {
                // PathMatcher matcher =
                // FileSystems.getDefault().getPathMatcher("glob:*.[nN][fF][oO]");
                LOGGER.info("| parsing NFO " + mf.getFileAsPath());
                Movie nfo = null;
                switch (MovieModuleManager.MOVIE_SETTINGS.getMovieConnector()) {
                case XBMC:
                    nfo = MovieToXbmcNfoConnector.getData(mf.getFileAsPath());
                    if (nfo == null) {
                        // try the other
                        nfo = MovieToKodiNfoConnector.getData(mf.getFileAsPath());
                    }
                    if (nfo == null) {
                        // try the other
                        nfo = MovieToMpNfoConnector.getData(mf.getFileAsPath());
                    }
                    break;

                case KODI:
                    nfo = MovieToKodiNfoConnector.getData(mf.getFileAsPath());
                    // not needed at the moment since kodi is downwards compatible
                    // if (nfo == null) {
                    // // try the other
                    // nfo = MovieToXbmcNfoConnector.getData(mf.getFileAsPath());
                    // }
                    if (nfo == null) {
                        // try the other
                        nfo = MovieToMpNfoConnector.getData(mf.getFileAsPath());
                    }
                    break;

                case MP:
                    nfo = MovieToMpNfoConnector.getData(mf.getFileAsPath());
                    if (nfo == null) {
                        // try the other
                        nfo = MovieToKodiNfoConnector.getData(mf.getFileAsPath());
                    }
                    // not needed at the moment since kodi is downwards compatible
                    // if (nfo == null) {
                    // // try the other
                    // nfo = MovieToXbmcNfoConnector.getData(mf.getFileAsPath());
                    // }
                    break;
                }
                if (nfo != null) {
                    movie = nfo;
                }
                // was NFO, but parsing exception. try to find at least imdb id within
                if (movie.getImdbId().isEmpty()) {
                    try {
                        String imdb = Utils.readFileToString(mf.getFileAsPath());
                        imdb = ParserUtils.detectImdbId(imdb);
                        if (!imdb.isEmpty()) {
                            LOGGER.debug("| Found IMDB id: " + imdb);
                            movie.setImdbId(imdb);
                        }
                    } catch (IOException e) {
                        LOGGER.warn("| couldn't read NFO " + mf);
                    }
                }

            } // end NFO
            else if (mf.getType().equals(MediaFileType.TEXT)) {
                try {
                    String txtFile = Utils.readFileToString(mf.getFileAsPath());

                    String bdinfo = StrgUtils.substr(txtFile, ".*Disc Title:\\s+(.*?)[\\n\\r]");
                    if (!bdinfo.isEmpty()) {
                        LOGGER.debug("| Found Disc Title in BDInfo.txt: " + bdinfo);
                        bdinfoTitle = WordUtils.capitalizeFully(bdinfo);
                    }

                    String imdb = ParserUtils.detectImdbId(txtFile);
                    if (!imdb.isEmpty()) {
                        LOGGER.debug("| Found IMDB id: " + imdb);
                        movie.setImdbId(imdb);
                    }
                } catch (Exception e) {
                    LOGGER.warn("| couldn't read TXT " + mf.getFilename());
                }
            } else if (mf.getType().equals(MediaFileType.VIDEO)) {
                videoName = mf.getBasename();
            }
        } // end NFO MF loop
        movie.setNewlyAdded(true);
        movie.setDateAdded(new Date());
    } // end first round - we might have a filled movie

    if (movie.getTitle().isEmpty()) {
        // get the "cleaner" name/year combo
        // ParserUtils.ParserInfo video = ParserUtils.getCleanerString(new
        // String[] { videoName, movieDir.getName(), bdinfoTitle });
        // does not work reliable yet - user folder name
        String[] video = ParserUtils.detectCleanMovienameAndYear(movieDir.getFileName().toString());
        movie.setTitle(video[0]);
        if (!video[1].isEmpty()) {
            movie.setYear(video[1]);
        }
    }

    // if the String 3D is in the movie dir, assume it is a 3D movie
    Matcher matcher = video3DPattern.matcher(movieDir.getFileName().toString());
    if (matcher.find()) {
        movie.setVideoIn3D(true);
    }
    // get edition from name
    movie.setEdition(MovieEdition.getMovieEditionFromString(movieDir.getFileName().toString()));

    movie.setPath(movieDir.toAbsolutePath().toString());
    movie.setDataSource(dataSource.toString());

    // movie.findActorImages(); // TODO: find as MediaFiles
    LOGGER.debug("| store movie into DB as: " + movie.getTitle());

    movieList.addMovie(movie);

    if (movie.getMovieSet() != null) {
        LOGGER.debug("| movie is part of a movieset");
        // movie.getMovieSet().addMovie(movie);
        movie.getMovieSet().insertMovie(movie);
        movieList.sortMoviesInMovieSet(movie.getMovieSet());
        movie.getMovieSet().saveToDb();
    }

    // ***************************************************************
    // second round - now add all the other known files
    // ***************************************************************
    addMediafilesToMovie(movie, mfs);

    // ***************************************************************
    // third round - try to match unknown graphics like title.ext or
    // filename.ext as poster
    // ***************************************************************
    if (movie.getArtworkFilename(MediaFileType.POSTER).isEmpty()) {
        for (MediaFile mf : mfs) {
            if (mf.getType().equals(MediaFileType.GRAPHIC)) {
                LOGGER.debug("| parsing unknown graphic " + mf.getFilename());
                List<MediaFile> vid = movie.getMediaFiles(MediaFileType.VIDEO);
                if (vid != null && !vid.isEmpty()) {
                    String vfilename = vid.get(0).getFilename();
                    if (FilenameUtils.getBaseName(vfilename).equals(FilenameUtils.getBaseName(mf.getFilename())) // basename
                            // match
                            || FilenameUtils.getBaseName(Utils.cleanStackingMarkers(vfilename)).trim()
                                    .equals(FilenameUtils.getBaseName(mf.getFilename())) // basename
                                                                                                                                                                   // w/o
                                                                                                                                                                   // stacking
                            || movie.getTitle().equals(FilenameUtils.getBaseName(mf.getFilename()))) { // title
                                                                                                       // match
                        mf.setType(MediaFileType.POSTER);
                        movie.addToMediaFiles(mf);
                    }
                }
            }
        }
    }

    // ***************************************************************
    // check if that movie is an offline movie
    // ***************************************************************
    boolean isOffline = false;
    for (MediaFile mf : movie.getMediaFiles(MediaFileType.VIDEO)) {
        if ("disc".equalsIgnoreCase(mf.getExtension())) {
            isOffline = true;
        }
    }
    movie.setOffline(isOffline);

    movie.reEvaluateStacking();
    movie.saveToDb();
}

From source file:org.apache.hadoop.yarn.server.resourcemanager.recovery.RMStateStoreTestBase.java

public void testRMDTSecretManagerStateStore(RMStateStoreHelper stateStoreHelper) throws Exception {
    RMStateStore store = stateStoreHelper.getRMStateStore();
    TestDispatcher dispatcher = new TestDispatcher();
    store.setRMDispatcher(dispatcher);/* w w w .  j ava 2  s  . co  m*/

    // store RM delegation token;
    RMDelegationTokenIdentifier dtId1 = new RMDelegationTokenIdentifier(new Text("owner1"),
            new Text("renewer1"), new Text("realuser1"));
    int sequenceNumber = 1111;
    dtId1.setSequenceNumber(sequenceNumber);
    byte[] tokenBeforeStore = dtId1.getBytes();
    Long renewDate1 = new Long(System.currentTimeMillis());
    store.storeRMDelegationToken(dtId1, renewDate1);
    modifyRMDelegationTokenState();
    Map<RMDelegationTokenIdentifier, Long> token1 = new HashMap<RMDelegationTokenIdentifier, Long>();
    token1.put(dtId1, renewDate1);
    // store delegation key;
    DelegationKey key = new DelegationKey(1234, 4321, "keyBytes".getBytes());
    HashSet<DelegationKey> keySet = new HashSet<DelegationKey>();
    keySet.add(key);
    store.storeRMDTMasterKey(key);

    RMDTSecretManagerState secretManagerState = store.loadState().getRMDTSecretManagerState();
    Assert.assertEquals(token1, secretManagerState.getTokenState());
    Assert.assertEquals(keySet, secretManagerState.getMasterKeyState());
    Assert.assertEquals(sequenceNumber, secretManagerState.getDTSequenceNumber());
    RMDelegationTokenIdentifier tokenAfterStore = secretManagerState.getTokenState().keySet().iterator().next();
    Assert.assertTrue(Arrays.equals(tokenBeforeStore, tokenAfterStore.getBytes()));

    // update RM delegation token;
    renewDate1 = new Long(System.currentTimeMillis());
    store.updateRMDelegationToken(dtId1, renewDate1);
    token1.put(dtId1, renewDate1);

    RMDTSecretManagerState updateSecretManagerState = store.loadState().getRMDTSecretManagerState();
    Assert.assertEquals(token1, updateSecretManagerState.getTokenState());
    Assert.assertEquals(keySet, updateSecretManagerState.getMasterKeyState());
    Assert.assertEquals(sequenceNumber, updateSecretManagerState.getDTSequenceNumber());

    // check to delete delegationKey
    store.removeRMDTMasterKey(key);
    keySet.clear();
    RMDTSecretManagerState noKeySecretManagerState = store.loadState().getRMDTSecretManagerState();
    Assert.assertEquals(token1, noKeySecretManagerState.getTokenState());
    Assert.assertEquals(keySet, noKeySecretManagerState.getMasterKeyState());
    Assert.assertEquals(sequenceNumber, noKeySecretManagerState.getDTSequenceNumber());

    // check to delete delegationToken
    store.removeRMDelegationToken(dtId1);
    RMDTSecretManagerState noKeyAndTokenSecretManagerState = store.loadState().getRMDTSecretManagerState();
    token1.clear();
    Assert.assertEquals(token1, noKeyAndTokenSecretManagerState.getTokenState());
    Assert.assertEquals(keySet, noKeyAndTokenSecretManagerState.getMasterKeyState());
    Assert.assertEquals(sequenceNumber, noKeySecretManagerState.getDTSequenceNumber());
    store.close();

}

From source file:it.iit.genomics.cru.structures.bridges.uniprot.UniprotkbUtils.java

/**
 *
 * @param xrefs//from www .j a  v a 2  s.co  m
 * @param filterTaxid
 * @return
 * @throws BridgesRemoteAccessException
 */
public HashMap<String, MoleculeEntry> getUniprotEntriesFromUniprotAccessions(Collection<String> xrefs,
        boolean filterTaxid) throws BridgesRemoteAccessException {
    String tool = UNIPROT_TOOL;

    // remove xrefs that are not uniprotAcs
    Collection<String> uniprotAcs = getUniprotAcs(xrefs);

    HashMap<String, MoleculeEntry> results = new HashMap<>();

    HashSet<String> ref2get = new HashSet<>();

    try {
        for (String ref : uniprotAcs) {
            if (cache.containsKey(ref.toUpperCase())) {
                results.put(ref, cache.get(ref.toUpperCase()).iterator().next());
            } else {
                ref2get.add(ref);

                // if size == limit, do query
                if (ref2get.size() == maxQueries) {
                    String location = UNIPROT_SERVER + tool + "/?" + "query=(accession:"
                            + URLEncoder.encode(StringUtils.join(ref2get, " OR accession:") + "", "UTF-8")
                            + ")";
                    if (filterTaxid) {
                        location += "+AND+keyword:181+AND+organism:"
                                + URLEncoder.encode("\"" + taxid + "\"", "UTF-8");
                    }

                    Collection<MoleculeEntry> uniprotEntries = getUniprotEntriesXML(location);

                    for (MoleculeEntry entry : uniprotEntries) {
                        results.put(entry.getUniprotAc(), entry);
                    }
                    ref2get.clear();
                }
            }
        }

        if (ref2get.isEmpty()) {
            return results;
        }

        String location = UNIPROT_SERVER + tool + "/?" + "query=(accession:"
                + URLEncoder.encode(StringUtils.join(ref2get, " OR accession:") + "", "UTF-8") + ")";
        if (filterTaxid) {
            location += "+AND+keyword:181+AND+organism:" + URLEncoder.encode("\"" + taxid + "\"", "UTF-8");
        }
        Collection<MoleculeEntry> uniprotEntries = getUniprotEntriesXML(location);

        for (MoleculeEntry entry : uniprotEntries) {
            results.put(entry.getUniprotAc(), entry);
        }

    } catch (UnsupportedEncodingException e) {
        logger.error("cannot get proteins for " + StringUtils.join(xrefs, ", "), e);
    }

    return results;
}

From source file:org.voltdb.TestExecutionSite.java

@SuppressWarnings("deprecation")
public void testMultiPartitionParticipantTxnState_handleSiteFaults() throws Exception {
    start(SITE_COUNT, PARTITION_COUNT, K_FACTOR);
    StoredProcedureInvocation spi = new StoredProcedureInvocation();
    spi.setClientHandle(25);//from   w w w .j  a v a  2 s. c o m
    spi.setProcName("johnisgreat");
    spi.setParams("commit", 57, "gooniestoo");

    long[] nonCoordinatorSites = new long[SITE_COUNT - 1];
    for (int i = 0; i < SITE_COUNT - 1; i++) {
        nonCoordinatorSites[i] = getHSIdForES(i + 1);
    }

    InitiateTaskMessage mn = new InitiateTaskMessage(-1, 0, -1, false, false, spi, Long.MIN_VALUE,
            nonCoordinatorSites);

    final long siteId0 = getHSIdForES(0);
    Mailbox m0 = m_mboxes.get(siteId0);
    ExecutionSite es0 = m_sites.get(siteId0);
    MultiPartitionParticipantTxnState ts = new MultiPartitionParticipantTxnState(m0, es0, mn);

    // fail middle and last site
    HashSet<Long> failedSites = new HashSet<Long>();
    failedSites.add(getHSIdForES(1));
    failedSites.add(getHSIdForES(2));
    failedSites.add(getHSIdForES(3));
    failedSites.add(getHSIdForES(5));
    ts.handleSiteFaults(failedSites);

    // peek at some internals
    long[] nonCoordinatingSites = ts.getNonCoordinatingSites();
    assertEquals(4, nonCoordinatingSites.length);
    assertEquals(getHSIdForES(8), nonCoordinatingSites[3]);
    assertEquals(getHSIdForES(7), nonCoordinatingSites[2]);
    assertEquals(getHSIdForES(6), nonCoordinatingSites[1]);
    assertEquals(getHSIdForES(4), nonCoordinatingSites[0]);

    // fail first site
    ts = new MultiPartitionParticipantTxnState(m0, es0, mn);
    failedSites.clear();
    failedSites.add(getHSIdForES(1));
    ts.handleSiteFaults(failedSites);

    nonCoordinatingSites = ts.getNonCoordinatingSites();
    assertEquals(7, nonCoordinatingSites.length);
    assertEquals(getHSIdForES(8), nonCoordinatingSites[6]);
    assertEquals(getHSIdForES(7), nonCoordinatingSites[5]);
    assertEquals(getHSIdForES(6), nonCoordinatingSites[4]);
    assertEquals(getHSIdForES(4), nonCoordinatingSites[2]);
    assertEquals(getHSIdForES(3), nonCoordinatingSites[1]);
    assertEquals(getHSIdForES(2), nonCoordinatingSites[0]);

    // fail site that isn't a non-coordinator site
    ts = new MultiPartitionParticipantTxnState(m0, es0, mn);
    failedSites.clear();
    failedSites.add(getHSIdForES(9));
    failedSites.add(getHSIdForES(10));
    ts.handleSiteFaults(failedSites);

    nonCoordinatingSites = ts.getNonCoordinatingSites();
    assertEquals(8, nonCoordinatingSites.length);
    assertEquals(getHSIdForES(8), nonCoordinatingSites[7]);
    assertEquals(getHSIdForES(7), nonCoordinatingSites[6]);
    assertEquals(getHSIdForES(6), nonCoordinatingSites[5]);
    assertEquals(getHSIdForES(5), nonCoordinatingSites[4]);
    assertEquals(getHSIdForES(3), nonCoordinatingSites[2]);
    assertEquals(getHSIdForES(2), nonCoordinatingSites[1]);
    assertEquals(getHSIdForES(1), nonCoordinatingSites[0]);
}

From source file:it.iit.genomics.cru.structures.bridges.uniprot.UniprotkbUtils.java

/**
 *
 * @param genes/*from  ww w  .j a  v a2 s.c o  m*/
 * @return
 * @throws BridgesRemoteAccessException
 */
public MapOfMap<String, MoleculeEntry> getUniprotEntriesFromGenes(Collection<String> genes)
        throws BridgesRemoteAccessException {
    String tool = UNIPROT_TOOL;

    MapOfMap<String, MoleculeEntry> gene2uniprots = new MapOfMap<>(genes);

    HashSet<String> genes2get = new HashSet<>();

    try {
        for (String gene : genes) {
            if (cache.containsKey(gene.toUpperCase())) {
                gene2uniprots.addAll(gene, cache.get(gene.toUpperCase()));
            } else {
                genes2get.add(gene);

                // if size == limit, do query
                if (genes2get.size() == maxQueries) {
                    String location = UNIPROT_SERVER + tool + "/?" + "query=keyword:181+AND+organism:"
                            + URLEncoder.encode("\"" + taxid + "\"", "UTF-8") + "+AND+(gene:"
                            + URLEncoder.encode(StringUtils.join(genes2get, " OR gene:"), "UTF-8") + ")";

                    Collection<MoleculeEntry> uniprotEntries = getUniprotEntriesXML(location);

                    for (MoleculeEntry entry : uniprotEntries) {
                        String geneName = entry.getGeneName();

                        // Only use the first one. Using synomyms may cause
                        // ambiguity.
                        if (geneName != null && gene2uniprots.containsKey(geneName)) {
                            gene2uniprots.add(geneName, entry);
                        }
                    }

                    genes2get.clear();
                }

            }
        }

        if (genes2get.isEmpty()) {
            return gene2uniprots;
        }

        String location = UNIPROT_SERVER + tool + "/?" + "query=keyword:181+AND+organism:"
                + URLEncoder.encode("\"" + taxid + "\"", "UTF-8") + "+AND+(gene:"
                + URLEncoder.encode(StringUtils.join(genes2get, " OR gene:"), "UTF-8") + ")";

        Collection<MoleculeEntry> uniprotEntries = getUniprotEntriesXML(location);

        for (MoleculeEntry entry : uniprotEntries) {
            String geneName = entry.getGeneName();

            // Only use the first one. Using synomyms may cause ambiguity.
            if (geneName != null && gene2uniprots.containsKey(geneName)) {
                gene2uniprots.add(geneName, entry);
            }
        }

    } catch (UnsupportedEncodingException e) {
        logger.error("cannot get proteins for " + StringUtils.join(genes, ", "), e);
    }

    return gene2uniprots;
}

From source file:com.joyent.manta.http.MantaHttpHeaders.java

/**
 * Gets the header defining RBAC roles used for this object.
 *
 * @return roles associated with object/*from w  ww  .j av a 2 s .co m*/
 */
public Set<String> getRoles() {
    final Object value = get(HTTP_ROLE_TAG);

    if (value == null) {
        return Collections.emptySet();
    }

    final HashSet<String> roles = new HashSet<>();

    if (value instanceof Iterable<?>) {
        ((Iterable<?>) value).forEach(o -> {
            if (o != null) {
                roles.add(o.toString());
            }
        });
    } else if (value.getClass().isArray()) {
        for (Object o : (Object[]) value) {
            if (o != null) {
                roles.add(o.toString());
            }
        }
    } else {
        String line = value.toString();
        roles.addAll(MantaUtils.fromCsv(line));
    }

    /* The result may come to us as a CSV. In that case we treat each
     * value separated by a comma as a single role.
     */
    if (roles.size() == 1) {
        String line = roles.iterator().next();
        roles.clear();
        roles.addAll(MantaUtils.fromCsv(line));
    }

    return Collections.unmodifiableSet(roles);
}

From source file:org.waarp.openr66.database.data.DbHostConfiguration.java

/**
 * update Business with possible purge and new or added content, and updating in memory information
 * //w  ww  .ja v a2  s. com
 * @param config
 * @param newbusiness
 * @param purged
 * @return True if updated
 */
public boolean updateBusiness(Configuration config, String newbusiness, boolean purged) {
    HashSet<String> set = new HashSet<String>();
    if (!updateSet(newbusiness, XML_BUSINESS + "/" + XML_BUSINESSID, set)) {
        return false;
    }
    if (purged) {
        config.businessWhiteSet.clear();
    } else {
        String business = getBusiness();
        if (!updateSet(business, XML_BUSINESS + "/" + XML_BUSINESSID, set)) {
            return false;
        }
    }
    config.businessWhiteSet.addAll(set);
    if ((newbusiness != null && !newbusiness.isEmpty()) || purged) {
        Document document = DocumentHelper.createDocument(DocumentHelper.createElement(XML_BUSINESS));
        Element root = document.getRootElement();
        for (String sval : set) {
            root.addElement(XML_BUSINESSID).setText(sval);
            logger.info("Business Allow: " + sval);
        }
        setBusiness(root.asXML());
        try {
            update();
        } catch (WaarpDatabaseException e) {
            document.clearContent();
            document = null;
            return false;
        }
        document.clearContent();
        document = null;
    }
    set.clear();
    set = null;
    return true;
}

From source file:europarl.PhraseTranslation.java

private void postProcessData(ArrayList<PhraseTranslation> translations, Bag<String> words_list) {
    //it can remove useless attributes (in a COHERENT way: both from words_list and from translations)
    //it can remove instances (so it can even remove whole classes)
    log.debug("Start preprocessing");
    HashSet<String> to_remove = new HashSet<String>();

    //BEGIN removing too many classes
    Bag<String> classes = new Bag<String>();
    for (PhraseTranslation phraseTranslation : translations) {
        classes.add(phraseTranslation.getTranslatedWord());
    }//from w  ww.  j  a  v a2s  .  c om
    if (log.isDebugEnabled())
        for (String translation : classes)
            if (classes.getCount(translation) > 2)
                System.out.println("Class " + translation + " : " + classes.getCount(translation));

    ArrayList<Integer> class_occurrencies = new ArrayList<Integer>(classes.values());
    java.util.Collections.sort(class_occurrencies);
    System.out.println("CLASS OCC " + class_occurrencies);
    ArrayList<PhraseTranslation> tr_to_remove = new ArrayList<PhraseTranslation>();
    for (String cl : classes) {
        if (classes.getCount(cl) < class_occurrencies
                .get(class_occurrencies.size() - Cfg.cfg.getInt("target_classes", 4))) {
            for (PhraseTranslation phraseTranslation : translations) {
                if (phraseTranslation.getTranslatedWord().equals(cl))
                    tr_to_remove.add(phraseTranslation);
            }
        }
    }
    for (PhraseTranslation phraseTranslation : tr_to_remove) {
        for (String word : phraseTranslation.getPhraseWords()) {
            words_list.countdown(word);
        }
        translations.remove(phraseTranslation);
    }
    System.out.println(translations.size());

    //END removing too many classes

    //BEGIN removing "useless" words, ie words with less than K occurrences
    for (String word : words_list) {
        assert 2 == Cfg.cfg.getInt("minimum_word_occurrencies");
        if (words_list.getCount(word) <= Cfg.cfg.getInt("minimum_word_occurrencies")
                || words_list.getCount(word) >= translations.size() * 50 / 100) {
            log.debug(word + "occurs only" + words_list.getCount(word) + " times");
            to_remove.add(word);
        }
    }
    for (String word : to_remove) {
        words_list.remove(word);
        for (PhraseTranslation trans : translations)
            trans.removeWord(word);
    }
    log.info("Useless words: " + to_remove.size() + ". Now: " + words_list.size());
    to_remove.clear();
    //END removing "useless" words

}