Example usage for java.util SortedSet contains

List of usage examples for java.util SortedSet contains

Introduction

In this page you can find the example usage for java.util SortedSet contains.

Prototype

boolean contains(Object o);

Source Link

Document

Returns true if this set contains the specified element.

Usage

From source file:org.wso2.carbon.ui.Utils.java

/**
 * Process one file from the zip, given its name.
 * Either print the name, or create the file on disk.
 *
 * @param e              zip entry/*from  w w w . j av  a 2s. c o  m*/
 * @param zippy          jarfile
 * @param targetLocation target
 * @param dirsMade       dir
 * @throws java.io.IOException will be thrown
 */
private static void getFile(ZipEntry e, JarFile zippy, File targetLocation, SortedSet<String> dirsMade)
        throws IOException {
    byte[] b = new byte[1024];
    String zipName = e.getName();

    if (zipName.startsWith("/")) {
        zipName = zipName.substring(1);
    }
    //Process only fliles that start with "ui"
    if (!zipName.startsWith("ui")) {
        return;
    }
    // Strip off the ui bit
    zipName = zipName.substring(2);
    // if a directory, just return. We mkdir for every file,
    // since some widely-used Zip creators don't put out
    // any directory entries, or put them in the wrong place.
    if (zipName.endsWith("/")) {
        return;
    }
    // Else must be a file; open the file for output
    // Get the directory part.
    int ix = zipName.lastIndexOf('/');
    if (ix > 0) {
        String dirName = zipName.substring(0, ix);
        if (!dirsMade.contains(dirName)) {
            File d = new File(targetLocation, dirName);
            // If it already exists as a dir, don't do anything
            if (!(d.exists() && d.isDirectory())) {
                // Try to create the directory, warn if it fails
                if (log.isDebugEnabled()) {
                    log.debug("Deploying Directory: " + dirName);
                }
                if (!d.mkdirs()) {
                    log.warn("Warning: unable to mkdir " + dirName);
                }
                dirsMade.add(dirName);
            }
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("Deploying " + zipName);
    }
    File file = new File(targetLocation, zipName);
    FileOutputStream os = new FileOutputStream(file);
    InputStream is = zippy.getInputStream(e);
    int n;
    while ((n = is.read(b)) > 0) {
        os.write(b, 0, n);
    }
    is.close();
    os.close();
}

From source file:org.voltdb.compilereport.ReportMaker.java

static String generateSchemaTable(Database db) {
    StringBuilder sb = new StringBuilder();
    SortedSet<Table> exportTables = CatalogUtil.getExportTables(db);
    for (Table table : db.getTables()) {
        sb.append(generateSchemaRow(table, exportTables.contains(table) ? true : false));
    }// ww  w.  java  2 s.  c  o  m
    return sb.toString();
}

From source file:com.jdom.word.playdough.model.GamePackListModelTest.java

@Test
public void testListGamePacksDelegatesToResolver() {
    SortedSet<String> gamePacks = model.getAvailableGamePackFiles();
    assertEquals(2, gamePacks.size());/*from w  w w .  j  av  a  2s . c o  m*/
    assertTrue("Did not find the default game pack!", gamePacks.contains(UNLOCKED_GAME_PACK_NAME));
    assertTrue("Did not find the unlockable game pack!", gamePacks.contains(UNLOCKABLE_GAME_PACK_NAME));
}

From source file:com.aurel.track.item.link.ItemLinkBL.java

/**
 * Whether a linkSucc is descendant of linkPred for an unidirectional link
 * @param linkPred//w w w  . j  a va2 s.  co  m
 * @param linkSucc
 * @param direction
 * @return
 */
public static boolean isDescendent(Integer linkPred, Integer linkSucc, Integer direction, ILinkType iLinkType) {
    if (EqualUtils.equal(linkPred, linkSucc)) {
        return true;
    }
    List<Integer> linkTypeIDs = LinkTypeBL.getLinkTypesByPluginClass(iLinkType);
    List<Integer> workItemIDsFromLevel = new ArrayList<Integer>();
    workItemIDsFromLevel.add(linkPred);
    Set<Integer> linkPredSet = new HashSet<Integer>();
    while (!workItemIDsFromLevel.isEmpty()) {
        Map<Integer, SortedSet<Integer>> predToSuccLinkedWorkItemsMap = loadByWorkItemsAndLinkType(
                workItemIDsFromLevel, linkTypeIDs, direction, false, null, null);
        workItemIDsFromLevel = new ArrayList<Integer>();
        Iterator<Integer> itrSuccLinkedWorkItemsSet = predToSuccLinkedWorkItemsMap.keySet().iterator();
        while (itrSuccLinkedWorkItemsSet.hasNext()) {
            Integer crtLinkPred = itrSuccLinkedWorkItemsSet.next();
            //gather the predecessors from all levels
            linkPredSet.add(crtLinkPred);
            SortedSet<Integer> succLinkedWorkItemsSet = predToSuccLinkedWorkItemsMap.get(crtLinkPred);
            if (succLinkedWorkItemsSet.contains(linkSucc)) {
                return true;
            }
            //remove those successors which were already predecessors in a previous level
            //if the data is consistent this will never remove any entry,
            //but if data is not consistent not removing the entry it would lead to infinite cycle
            succLinkedWorkItemsSet.removeAll(linkPredSet);
            workItemIDsFromLevel.addAll(succLinkedWorkItemsSet);
        }
    }
    return false;
}

From source file:uk.gov.phe.gis.thematics.classification.classifiers.precision.rounding.Generic.java

public double[] round(double[] values, double[] excludes) {
    SortedSet<Double> excludeSet = new TreeSet<Double>(Arrays.asList(ArrayUtils.toObject(excludes)));
    SortedSet<Double> breakSet = new TreeSet<Double>();

    for (double b : values) {
        double roundedBreak = round(b);
        if (excludeSet.contains(roundedBreak) == false) {
            breakSet.add(roundedBreak);//www .  ja v a2s.  c o m
        }
    }
    return ArrayUtils.toPrimitive(breakSet.toArray(new Double[breakSet.size()]));
}

From source file:org.wso2.carbon.utils.Utils.java

/**
 * Process one file from the zip, given its name.
 * Either print the name, or create the file on disk.
 *
 * @param zipEntry              zip entry
 * @param zippy          jarfile//ww w  . j a  v  a 2  s  .c  om
 * @param targetLocation target
 * @param dirsMade       dir
 * @throws java.io.IOException will be thrown
 */
private static void getFile(ZipEntry zipEntry, JarFile zippy, File targetLocation, SortedSet<String> dirsMade)
        throws IOException {
    byte[] b = new byte[BYTE_ARRAY_SIZE];
    String zipName = zipEntry.getName();

    if (zipName.startsWith("/")) {
        zipName = zipName.substring(1);
    }
    //Process only fliles that start with "ui"
    if (!zipName.startsWith("ui")) {
        return;
    }
    // Strip off the ui bit
    zipName = zipName.substring(2);
    // if a directory, just return. We mkdir for every file,
    // since some widely-used Zip creators don't put out
    // any directory entries, or put them in the wrong place.
    if (zipName.endsWith("/")) {
        return;
    }
    // Else must be a file; open the file for output
    // Get the directory part.
    int ix = zipName.lastIndexOf('/');
    if (ix > 0) {
        String dirName = zipName.substring(0, ix);
        if (!dirsMade.contains(dirName)) {
            File d = new File(targetLocation, dirName);
            // If it already exists as a dir, don't do anything
            if (!(d.exists() && d.isDirectory())) {
                // Try to create the directory, warn if it fails
                if (log.isDebugEnabled()) {
                    log.debug("Deploying Directory: " + dirName);
                }
                if (!d.mkdirs()) {
                    log.warn("Warning: unable to mkdir " + dirName);
                }
                dirsMade.add(dirName);
            }
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("Deploying " + zipName);
    }

    int n;
    InputStream is = zippy.getInputStream(zipEntry);
    File file = new File(targetLocation, zipName);
    FileOutputStream os = null;

    try {
        os = new FileOutputStream(file);
        while ((n = is.read(b)) > 0) {
            os.write(b, 0, n);
        }
    } finally {
        try {
            is.close();
        } catch (IOException e) {
            log.warn("Unable to close the InputStream " + e.getMessage(), e);
        }

        try {
            if (os != null) {
                os.close();
            }
        } catch (IOException e) {
            log.warn("Unable to close the OutputStream " + e.getMessage(), e);
        }
    }
}

From source file:org.orbisgis.corejdbc.ReadTable.java

/**
 * Compute numeric stats of the specified table column using a limited input rows. Stats are not done in the sql side.
 * @param connection Available connection
 * @param tableName Table name/*from w ww.ja v a2  s.  c o  m*/
 * @param columnName Column name
 * @param rowNum Row id
 * @param pm Progress monitor
 * @return An array of attributes {@link STATS}
 * @throws SQLException
 */
public static String[] computeStatsLocal(Connection connection, String tableName, String columnName,
        SortedSet<Integer> rowNum, ProgressMonitor pm) throws SQLException {
    String[] res = new String[STATS.values().length];
    SummaryStatistics stats = new SummaryStatistics();
    try (Statement st = connection.createStatement()) {
        // Cancel select
        PropertyChangeListener listener = EventHandler.create(PropertyChangeListener.class, st, "cancel");
        pm.addPropertyChangeListener(ProgressMonitor.PROP_CANCEL, listener);
        try (ResultSet rs = st.executeQuery(String.format("SELECT %s FROM %s", columnName, tableName))) {
            ProgressMonitor fetchProgress = pm.startTask(rowNum.size());
            while (rs.next() && !pm.isCancelled()) {
                if (rowNum.contains(rs.getRow())) {
                    stats.addValue(rs.getDouble(columnName));
                    fetchProgress.endTask();
                }
            }
        } finally {
            pm.removePropertyChangeListener(listener);
        }
    }
    res[STATS.SUM.ordinal()] = Double.toString(stats.getSum());
    res[STATS.AVG.ordinal()] = Double.toString(stats.getMean());
    res[STATS.COUNT.ordinal()] = Long.toString(stats.getN());
    res[STATS.MIN.ordinal()] = Double.toString(stats.getMin());
    res[STATS.MAX.ordinal()] = Double.toString(stats.getMax());
    res[STATS.STDDEV_SAMP.ordinal()] = Double.toString(stats.getStandardDeviation());
    return res;
}

From source file:org.eclipse.gyrex.jobs.internal.commands.CancelJobCmd.java

@Override
protected void doExecute() throws Exception {
    if (StringUtils.isBlank(searchString)) {
        printf("ERROR: please specify a job filter (use '*' to cancel all)");
        return;//from  w  ww .  j av a  2 s  .c om
    }

    final IPath parsedContextPath = new Path(contextPath);
    final IRuntimeContext context = JobsActivator.getInstance().getService(IRuntimeContextRegistry.class)
            .get(parsedContextPath);
    if (null == context) {
        printf("Context '%s' not defined!", parsedContextPath);
        return;
    }

    final IJobManager jobManager = context.get(IJobManager.class);

    // get all matching jobs and sort
    final SortedSet<String> jobIds = new TreeSet<String>(jobManager.getJobs());

    // cancel single job if id matches
    if (!StringUtils.equals(searchString, "*") && IdHelper.isValidId(searchString)) {
        if (jobIds.contains(searchString)) {
            jobManager.cancelJob(searchString, "console");
            if (resetJobState) {
                ((JobManagerImpl) jobManager).setJobState(searchString, JobState.ABORTING, JobState.NONE, null,
                        System.currentTimeMillis());
            }
            printf("Job %s canceled.", searchString);
            return;
        }
    }

    // cancel all matching jobs
    for (final String jobId : jobIds) {
        if (StringUtils.equals(searchString, "*") || StringUtils.contains(jobId, searchString)) {
            try {
                jobManager.cancelJob(jobId, "console");
                if (resetJobState) {
                    ((JobManagerImpl) jobManager).setJobState(jobId, JobState.ABORTING, JobState.NONE, null,
                            System.currentTimeMillis());
                }
                printf("Job %s canceled.", jobId);
            } catch (final IllegalArgumentException e) {
                printf("Job %s not WAITING or RUNNING.", jobId);
            } catch (final IllegalStateException e) {
                printf("Error cancelling job %s. %s", jobId, ExceptionUtils.getRootCauseMessage(e));
            }
        }
    }
}

From source file:org.cast.cwm.data.User.java

/**
 * Determine whether this User is in the same period as another User.
 * @param other another User object to compare against
 * @return true if they have at least one Period in common
 *//* w  w w.ja  v a 2s . com*/
public boolean hasPeriodInCommonWith(User other) {
    SortedSet<Period> myPeriods = this.getPeriods();
    Hibernate.initialize(myPeriods);
    SortedSet<Period> otherPeriods = other.getPeriods();
    Hibernate.initialize(otherPeriods);

    for (Period p : myPeriods) {
        if (otherPeriods.contains(p))
            return true;
    }
    return false;
}

From source file:org.ngrinder.perftest.service.TagService.java

/**
 * Add tags./*  www  . j  a v  a 2 s.c om*/
 * 
 * @param user user
 * @param tags tag string list
 * @return inserted tags
 */
@Transactional
public SortedSet<Tag> addTags(User user, String[] tags) {
    if (ArrayUtils.isEmpty(tags)) {
        return new TreeSet<Tag>();
    }

    Specifications<Tag> spec = Specifications.where(lastModifiedOrCreatedBy(user)).and(valueIn(tags));
    List<Tag> foundTags = tagRepository.findAll(spec);
    SortedSet<Tag> allTags = new TreeSet<Tag>(foundTags);
    for (String each : tags) {
        Tag newTag = new Tag(StringUtils.trimToEmpty(StringUtils.replace(each, ",", "")));
        if (allTags.contains(newTag)) {
            continue;
        }
        if (!foundTags.contains(newTag) && !allTags.contains(newTag)) {
            allTags.add(saveTag(user, newTag));
        }
    }
    return allTags;
}