Example usage for java.util SortedSet isEmpty

List of usage examples for java.util SortedSet isEmpty

Introduction

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

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this set contains no elements.

Usage

From source file:org.apache.hadoop.hbase.regionserver.MemStore.java

/**
 * Given the specs of a column, update it, first by inserting a new record,
 * then removing the old one.  Since there is only 1 KeyValue involved, the memstoreTS
 * will be set to 0, thus ensuring that they instantly appear to anyone. The underlying
 * store will ensure that the insert/delete each are atomic. A scanner/reader will either
 * get the new value, or the old value and all readers will eventually only see the new
 * value after the old was removed./*from  w  ww  .  j av  a2 s  .c om*/
 *
 * @param row
 * @param family
 * @param qualifier
 * @param newValue
 * @param now
 * @return  Timestamp
 */
public long updateColumnValue(byte[] row, byte[] family, byte[] qualifier, long newValue, long now) {
    this.lock.readLock().lock();
    try {
        KeyValue firstKv = KeyValue.createFirstOnRow(row, family, qualifier);
        // Is there a KeyValue in 'snapshot' with the same TS? If so, upgrade the timestamp a bit.
        SortedSet<KeyValue> snSs = snapshot.tailSet(firstKv);
        if (!snSs.isEmpty()) {
            KeyValue snKv = snSs.first();
            // is there a matching KV in the snapshot?
            if (snKv.matchingRow(firstKv) && snKv.matchingQualifier(firstKv)) {
                if (snKv.getTimestamp() == now) {
                    // poop,
                    now += 1;
                }
            }
        }

        // logic here: the new ts MUST be at least 'now'. But it could be larger if necessary.
        // But the timestamp should also be max(now, mostRecentTsInMemstore)

        // so we cant add the new KV w/o knowing what's there already, but we also
        // want to take this chance to delete some kvs. So two loops (sad)

        SortedSet<KeyValue> ss = kvset.tailSet(firstKv);
        Iterator<KeyValue> it = ss.iterator();
        while (it.hasNext()) {
            KeyValue kv = it.next();

            // if this isnt the row we are interested in, then bail:
            if (!kv.matchingColumn(family, qualifier) || !kv.matchingRow(firstKv)) {
                break; // rows dont match, bail.
            }

            // if the qualifier matches and it's a put, just RM it out of the kvset.
            if (kv.getType() == KeyValue.Type.Put.getCode() && kv.getTimestamp() > now
                    && firstKv.matchingQualifier(kv)) {
                now = kv.getTimestamp();
            }
        }

        // create or update (upsert) a new KeyValue with
        // 'now' and a 0 memstoreTS == immediately visible
        return upsert(Arrays.asList(new KeyValue(row, family, qualifier, now, Bytes.toBytes(newValue))));
    } finally {
        this.lock.readLock().unlock();
    }
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.coordinator.thesis.ManageThesisDA.java

private void fillLastThesisInfo(final ThesisBean bean, final Student student, final Enrolment enrolment) {
    final SortedSet<Enrolment> dissertationEnrolments = student.getDissertationEnrolments(null);
    dissertationEnrolments.remove(enrolment);
    if (!dissertationEnrolments.isEmpty()) {
        final Thesis previous = findPreviousThesis(dissertationEnrolments);
        if (previous != null) {
            bean.setTitle(previous.getTitle());
            return;
        }/* w w w  .ja  va 2 s .co m*/
    }
}

From source file:de.faustedition.tei.TeiValidator.java

@Override
public void run() {
    try {//from ww  w.  java2s.  c  om
        final SortedSet<FaustURI> xmlErrors = new TreeSet<FaustURI>();
        final SortedMap<FaustURI, String> teiErrors = new TreeMap<FaustURI, String>();
        for (FaustURI source : xml.iterate(new FaustURI(FaustAuthority.XML, "/transcript"))) {
            try {
                final List<String> errors = validate(source);
                if (!errors.isEmpty()) {
                    teiErrors.put(source, Joiner.on("\n").join(errors));
                }
            } catch (SAXException e) {
                logger.debug("XML error while validating transcript: " + source, e);
                xmlErrors.add(source);
            } catch (IOException e) {
                logger.warn("I/O error while validating transcript: " + source, e);
            }
        }

        if (xmlErrors.isEmpty() && teiErrors.isEmpty()) {
            return;
        }

        reporter.send("TEI validation report", new ReportCreator() {

            public void create(PrintWriter body) {
                if (!xmlErrors.isEmpty()) {
                    body.println(Strings.padStart(" XML errors", 79, '='));
                    body.println();
                    body.println(Joiner.on("\n").join(xmlErrors));
                    body.println();
                }
                if (!teiErrors.isEmpty()) {
                    body.println(Strings.padStart(" TEI errors", 79, '='));
                    body.println();

                    for (Map.Entry<FaustURI, String> teiError : teiErrors.entrySet()) {
                        body.println(Strings.padStart(" " + teiError.getKey(), 79, '-'));
                        body.println();
                        body.println(teiError.getValue());
                        body.println();
                        body.println();
                    }
                }
            }
        });
    } catch (EmailException e) {
        e.printStackTrace();
    }
}

From source file:org.geoserver.taskmanager.external.impl.FileServiceImpl.java

@Override
public FileReference getVersioned(String filePath) {
    if (filePath.indexOf(FileService.PLACEHOLDER_VERSION) < 0) {
        return new FileReferenceImpl(this, filePath, filePath);
    }//from w ww  .  j  a v  a 2 s  .c  o m

    Path parent = getAbsolutePath(filePath).getParent();
    String[] fileNames = parent.toFile()
            .list(new WildcardFileFilter(filePath.replace(FileService.PLACEHOLDER_VERSION, "*")));

    SortedSet<Integer> set = new TreeSet<Integer>();
    Pattern pattern = Pattern
            .compile(Pattern.quote(filePath).replace(FileService.PLACEHOLDER_VERSION, "\\E(.*)\\Q"));
    for (String fileName : fileNames) {
        Matcher matcher = pattern.matcher(fileName);
        if (matcher.matches()) {
            try {
                set.add(Integer.parseInt(matcher.group(1)));
            } catch (NumberFormatException e) {
                LOGGER.log(Level.WARNING, "could not parse version in versioned file " + fileName, e);
            }
        } else {
            LOGGER.log(Level.WARNING,
                    "this shouldn't happen: couldn't find version in versioned file " + fileName);
        }
    }
    int last = set.isEmpty() ? 0 : set.last();
    return new FileReferenceImpl(this, filePath.replace(FileService.PLACEHOLDER_VERSION, last + ""),
            filePath.replace(FileService.PLACEHOLDER_VERSION, (last + 1) + ""));
}

From source file:org.wrml.werminal.Werminal.java

private void addKeySlotValuesToHistory(final URI historyListSchemaUri, final Keys keys) {

    final Context context = getContext();
    final SchemaLoader schemaLoader = context.getSchemaLoader();
    if (keys == null || keys.getCount() == 0) {
        return;/*w w  w  .  j  a v a2  s.  co m*/
    }

    for (final URI keyedSchemaUri : keys.getKeyedSchemaUris()) {
        final Object keyValue = keys.getValue(keyedSchemaUri);

        final Prototype keyDeclaredPrototype = schemaLoader.getPrototype(keyedSchemaUri);
        if (keyDeclaredPrototype == null) {
            continue;
        }
        final SortedSet<String> keySlotNames = keyDeclaredPrototype.getDeclaredKeySlotNames();

        if (keySlotNames == null || keySlotNames.isEmpty()) {
            continue;
        }

        if (keySlotNames.size() == 1) {
            final String keySlotName = keySlotNames.first();

            addSlotValueToHistory(historyListSchemaUri, keySlotName, keyValue);
        } else {
            final CompositeKey compositeKey = (CompositeKey) keyValue;
            if (compositeKey == null) {
                continue;
            }

            final Map<String, Object> compositeKeySlots = compositeKey.getKeySlots();
            for (final String compositeKeySlotName : compositeKeySlots.keySet()) {
                final Object compositeKeySlotValue = compositeKeySlots.get(compositeKeySlotName);
                if (compositeKeySlotValue != null) {
                    addSlotValueToHistory(historyListSchemaUri, compositeKeySlotName, compositeKeySlotValue);
                }
            }
        }
    }
}

From source file:net.pms.dlna.protocolinfo.DeviceProtocolInfo.java

/**
 * Checks if the {@link Set} for the given {@link DeviceProtocolInfoSource}
 * type is empty.//from w  ww . j a  va 2s . c  o  m
 *
 * @param type the {@link DeviceProtocolInfoSource} type to check.
 * @return {@code true} if {@code protocolInfoSets} contains no elements of
 *         {@code type}.
 */
public boolean isEmpty(DeviceProtocolInfoSource<?> type) {
    setsLock.readLock().lock();
    try {
        SortedSet<ProtocolInfo> set = protocolInfoSets.get(type);
        return set == null ? true : set.isEmpty();
    } finally {
        setsLock.readLock().unlock();
    }
}

From source file:net.pms.dlna.protocolinfo.DeviceProtocolInfo.java

/**
 * Checks if all the {@link DeviceProtocolInfoSource} {@link Set}s are
 * empty./*from   w  w  w  .  j a v  a2 s. c  o m*/
 *
 * @return {@code true} if neither of the {@link DeviceProtocolInfoSource}
 *         {@link Set}s contain any elements, {@code false} otherwise.
 */
public boolean isEmpty() {
    setsLock.readLock().lock();
    try {
        for (SortedSet<ProtocolInfo> set : protocolInfoSets.values()) {
            if (set != null && !set.isEmpty()) {
                return false;
            }
        }
    } finally {
        setsLock.readLock().unlock();
    }
    return true;
}

From source file:org.eclipse.skalli.view.internal.window.ProjectEditPanelEntry.java

public void showIssues(SortedSet<Issue> issues, boolean collapseValid) {
    if (issueLabel == null) {
        issueLabel = new Label(StringUtils.EMPTY, Label.CONTENT_XHTML);
        issueLabel.setWidth(100, UNITS_PERCENTAGE);
        issueLabel.addStyleName(STYLE_ISSUES);
        tray.addComponent(issueLabel);/*ww  w  . j  a v  a  2 s .com*/
    }

    if (issues == null || issues.isEmpty()) {
        issueLabel.setValue(StringUtils.EMPTY);
        issueLabel.setVisible(false);
        if (collapseValid) {
            collapse();
        }
    } else {
        issueLabel.setValue(Issue.asHTMLList(null, issues));
        issueLabel.setVisible(true);
        expand();
    }
}

From source file:org.silverpeas.components.whitepages.control.WhitePagesSessionController.java

public Set<String> getSearchFieldIds() throws WhitePagesException {
    Set<String> ids = new HashSet<>();
    SortedSet<SearchField> searchFields = getSearchFields();
    if (searchFields != null && !searchFields.isEmpty()) {
        for (SearchField field : searchFields) {
            ids.add(field.getFieldId());
        }//from  w ww .j ava2 s. co m
    }
    return ids;
}

From source file:org.talend.license.LicenseRetriver.java

public Collection<File> updateLicense(final String version, final File file) {
    logger.info("start to update {} license ", version);
    String url = String.format(Configer.getBuildURL() + Configer.getLicenseURL(), version);

    Document doc = connector.getPage(url);
    if (null == doc) {
        logger.error("no {} license page url:{}", version, url);
        return null;
    }/*from  www . j av a  2s .com*/
    String regex = String.format(Configer.getLicenseItem(), version);

    Elements eles = doc.getElementsMatchingOwnText(regex);

    if (eles.isEmpty()) {
        logger.error("no {} license page url:{}", version, url);
        return null;
    }

    final Pattern pattern = Pattern.compile(regex);

    SortedSet<String> set = new TreeSet<String>(new Comparator<String>() {

        public int compare(String o1, String o2) {
            String m1;
            String m2;
            Matcher matcher = pattern.matcher(o1);
            if (matcher.find()) {
                m1 = matcher.group(2);
            } else {
                return 1;
            }
            matcher = pattern.matcher(o2);
            if (matcher.find()) {
                m2 = matcher.group(2);
            } else {
                return -1;
            }
            return m2.compareTo(m1);
        }
    });
    logger.info("there are {} license build", eles.size());
    for (Element ele : eles) {
        String text = ele.text();
        set.add(text);
    }
    if (set.isEmpty()) {
        return null;
    }

    Iterator<String> ite = set.iterator();
    while (ite.hasNext()) {
        String target = ite.next();
        url = url + target;
        logger.info("retrive from newest build {}", url);
        Collection<File> fs = checkout(version, file, url);
        if (!fs.isEmpty()) {
            return fs;
        }
        logger.info("no available license in build");
    }
    logger.error("retrive license failed");
    return null;
}