Example usage for java.util Set toArray

List of usage examples for java.util Set toArray

Introduction

In this page you can find the example usage for java.util Set toArray.

Prototype

<T> T[] toArray(T[] a);

Source Link

Document

Returns an array containing all of the elements in this set; the runtime type of the returned array is that of the specified array.

Usage

From source file:dk.netarkivet.archive.arcrepositoryadmin.ArcRepositoryEntry.java

/**
 * Get the ArchiveStoreState for the entry in general.
 * This is computed from the ArchiveStoreStates for the bitarchives.
 * <br>1. If no information about the bitarchives are available,
 *      the state UPLOAD_FAILED with timestamp=NOW is returned
 * <br>2. If there are information about one bitarchive,
 *      the state of this bitarchive is returned.
 * <br>3. If there are information from more than one bitarchive,
 *  A. if the state of one of the bitarchives equals UPLOAD_FAILED,
 *      the state UPLOAD_FAILED with the latest timestamp is returned
 *  B. else, find the lowest state of the N bitarchives:
 *      return this state together with the the latest timestamp
 * <p>//from w  w w . j  a  va2  s. c o  m
 * Note that the storestate and the timestamp might not come from the same
 * bitarchive.
 *
 * @return the current ArchiveStoreState for the entry in general
 */
public ArchiveStoreState getGeneralStoreState() {
    Set<String> bitarchives = storeStates.keySet();
    // Check whether scenario 1.
    if (bitarchives.size() == 0) {
        return new ArchiveStoreState(ReplicaStoreState.UPLOAD_FAILED);
    }

    String[] bitarchiveNames = bitarchives.toArray(new String[bitarchives.size()]);
    // Check whether scenario 2.
    if (bitarchives.size() == 1) {
        ArchiveStoreState ass = storeStates.get(bitarchiveNames[0]);
        return new ArchiveStoreState(ass.getState(), ass.getLastChanged());
    }

    // Scenario 3: If there are information from more than one bitarchive
    ArchiveStoreState ass = storeStates.get(bitarchiveNames[0]);
    Date lastChanged = ass.getLastChanged();
    boolean failState = false;
    ReplicaStoreState lowestStoreState = ass.getState();
    if (ass.getState().equals(ReplicaStoreState.UPLOAD_FAILED)) {
        failState = true;
    }
    for (int i = 1; i < bitarchiveNames.length; i++) {
        ArchiveStoreState tmpAss = storeStates.get(bitarchiveNames[i]);
        if (tmpAss.getState().ordinal() < lowestStoreState.ordinal()) {
            lowestStoreState = tmpAss.getState();
        }
        if (tmpAss.getState().equals(ReplicaStoreState.UPLOAD_FAILED)) {
            failState = true;
        }
        if (tmpAss.getLastChanged().after(lastChanged)) {
            lastChanged = tmpAss.getLastChanged();
        }
    }

    // Scenario 3A: if the state of one of the bitarchives equals
    // UPLOAD_FAILED.
    if (failState) {
        return new ArchiveStoreState(ReplicaStoreState.UPLOAD_FAILED, lastChanged);
    }

    // Scenario 3B:
    //   B. else, find the lowest state of the N bitarchives:
    //     return this state together with the the latest timestamp
    return new ArchiveStoreState(lowestStoreState, lastChanged);
}

From source file:us.swcraft.springframework.store.persistence.AerospikeTemplate.java

@Override
public void persist(final String key, final Set<Bin> bins) {
    Assert.notNull(key, "key can't be null");
    final Key recordKey = new Key(namespace, setname, key);
    Assert.notNull(bins, "bins can't be null");
    Assert.notEmpty(bins, "bins should have data to store");
    getAerospikeClient().put(writePolicyUpdate, recordKey, bins.toArray(BIN_ARRAY_TYPE));
}

From source file:com.appeligo.captions.DeleteOldProgramsThread.java

@Override
public void run() {

    while (true) {
        LuceneIndexer liveIndex = LuceneIndexer.getInstance(liveIndexLocation);
        Calendar wayback = Calendar.getInstance();
        wayback.add(Calendar.MONTH, -3);
        Calendar tenminutesago = Calendar.getInstance();
        tenminutesago.add(Calendar.MINUTE, -10);
        log.info("Deleting old programs from live index, between " + wayback.getTime() + " and "
                + tenminutesago.getTime());
        String dateField = "lineup-" + liveLineup + "-endTime";
        ConstantScoreRangeQuery dateQuery = new ConstantScoreRangeQuery(dateField,
                DateTools.dateToString(wayback.getTime(), DateTools.Resolution.MINUTE),
                DateTools.dateToString(tenminutesago.getTime(), DateTools.Resolution.MINUTE), true, true);
        IndexSearcher searcher = null;//from   w  w w. j  a  v a 2  s  . c  o  m
        try {
            searcher = new IndexSearcher(liveIndexLocation);
            Hits hits = searcher.search(dateQuery);
            Set<Term> terms = new HashSet<Term>();
            if (hits.length() > 0) {
                for (int index = 0; index < hits.length(); index++) {
                    Document doc = hits.doc(index);
                    Term term = new Term(dateField, doc.get(dateField));
                    terms.add(term);
                }
            }
            liveIndex.deleteDocuments(terms.toArray(new Term[terms.size()]));
        } catch (IOException e) {
            log.error("Error deleting old programs from live index", e);
        } finally {
            if (searcher != null) {
                try {
                    searcher.close();
                } catch (IOException e) {
                    log.error("Error closing searcher when deleting old programs from live index", e);

                }
            }
        }

        Calendar cal = Calendar.getInstance();
        int minute = cal.get(Calendar.MINUTE);
        if (minute < 15) {
            cal.set(Calendar.MINUTE, 15);
        } else if (minute >= 45) {
            cal.set(Calendar.MINUTE, 15);
            cal.add(Calendar.HOUR, 1);
        } else {
            cal.set(Calendar.MINUTE, 45);
        }
        log.info("queued up that delete, now we're waiting until " + cal.getTime());
        Utils.sleepUntil(cal.getTimeInMillis());
    }
}

From source file:jetbrains.buildServer.buildTriggers.vcs.git.PluginConfigImpl.java

public String getFetchClasspath() {
    Set<Class> classes = fetchProcessClasses();
    return ClasspathUtil.composeClasspath(classes.toArray(new Class[classes.size()]), null, null);
}

From source file:com.googlecode.flyway.core.util.scanner.ClassPathScanner.java

/**
 * Scans the classpath for resources under the specified location, starting with the specified prefix and ending with
 * the specified suffix./*from  www . j  a  v a2 s .c o m*/
 *
 * @param location The location (directory) in the classpath to start searching. Subdirectories are also searched.
 * @param prefix   The prefix of the resource names to match.
 * @param suffix   The suffix of the resource names to match.
 * @return The resources that were found.
 * @throws IOException when the location could not be scanned.
 */
public ClassPathResource[] scanForResources(String location, String prefix, String suffix) throws IOException {
    Set<ClassPathResource> classPathResources = new TreeSet<ClassPathResource>();

    Set<String> resourceNames = findResourceNames(location, prefix, suffix);
    for (String resourceName : resourceNames) {
        classPathResources.add(new ClassPathResource(resourceName));
        LOG.debug("Found resource: " + resourceName);
    }

    return classPathResources.toArray(new ClassPathResource[classPathResources.size()]);
}

From source file:jp.co.nemuzuka.dao.ProjectMemberDao.java

/**
 * List?./* ww w .  ja  v  a 2s .co m*/
 * @param projectKeyString Key
 * @param memberKeyString ?Key
 * @return 
 */
public List<ProjectMemberModel> getList(String projectKeyString, String memberKeyString) {
    ProjectMemberModelMeta e = (ProjectMemberModelMeta) getModelMeta();
    Set<FilterCriterion> filterSet = new HashSet<FilterCriterion>();
    if (StringUtils.isNotEmpty(projectKeyString)) {
        Key key = Datastore.stringToKey(projectKeyString);
        filterSet.add(e.projectKey.equal(key));
    }
    if (StringUtils.isNotEmpty(memberKeyString)) {
        Key key = Datastore.stringToKey(memberKeyString);
        filterSet.add(e.memberKey.equal(key));
    }
    return Datastore.query(e).filter(filterSet.toArray(new FilterCriterion[0]))
            .sortInMemory(e.projectKey.asc, e.projectAuthority.asc, e.memberKey.asc).asList();
}

From source file:net.paoding.analysis.knife.FileDictionaries.java

protected Word[] getDictionaryWords(String dicNameRelativeDicHome) {
    Map dics;//from  w  ww  . java2  s.c  o m
    try {
        dics = FileWordsReader.readWords(dicHome + "/" + dicNameRelativeDicHome + ".dic", charsetName,
                maxWordLen);
    } catch (IOException e) {
        throw toRuntimeException(e);
    }
    Set/* <Word> */ set = (Set/* <Word> */) dics.get(dicNameRelativeDicHome);
    Word[] words = (Word[]) set.toArray(new Word[set.size()]);
    Arrays.sort(words);
    return words;
}

From source file:us.swcraft.springframework.store.persistence.AerospikeTemplate.java

@Override
public void persistIfAbsent(final String key, final Set<Bin> bins) {
    Assert.notNull(key, "key can't be null");
    final Key recordKey = new Key(namespace, setname, key);
    Assert.notNull(bins, "bins can't be null");
    Assert.notEmpty(bins, "bins should have data to store");
    getAerospikeClient().put(writePolicyCreateOnly, recordKey, bins.toArray(BIN_ARRAY_TYPE));
}

From source file:com.minyisoft.webapp.core.utils.spring.cache.redis.RedisCache.java

public final void clear() {
    // need to del each key individually
    template.execute(new JedisActionNoResult() {

        @Override/*  ww  w  .  j av  a 2s .  c  om*/
        public void action(Jedis jedis) throws Exception {
            // another clear is on-going
            if (jedis.exists(cacheLockName)) {
                return;
            }

            try {
                jedis.set(cacheLockName, cacheLockName);

                int offset = 0;
                boolean finished = false;

                do {
                    // need to paginate the keys
                    Set<byte[]> keys = jedis.zrange(setName, (offset) * PAGE_SIZE,
                            (offset + 1) * PAGE_SIZE - 1);
                    finished = keys.size() < PAGE_SIZE;
                    offset++;
                    if (!keys.isEmpty()) {
                        jedis.del(keys.toArray(new byte[keys.size()][]));
                    }
                } while (!finished);

                jedis.del(setName);
                _furtherClear(jedis);
            } finally {
                jedis.del(cacheLockName);
            }
        }
    });
}

From source file:cc.pp.analyzer.paoding.knife.FileDictionaries.java

@SuppressWarnings({ "unchecked", "rawtypes" })
protected Word[] getDictionaryWords(String dicNameRelativeDicHome) {
    Map dics;//from w  w  w  .j  a  v  a 2  s.  c  o  m
    try {
        dics = FileWordsReader.readWords(dicHome + "/" + dicNameRelativeDicHome + ".dic", charsetName);
    } catch (IOException e) {
        throw toRuntimeException(e);
    }
    Set/* <Word> */<Word> set = (Set/* <Word> */<Word>) dics.get(dicNameRelativeDicHome);
    Word[] words = set.toArray(new Word[set.size()]);
    Arrays.sort(words);
    return words;
}