Example usage for java.util SortedSet addAll

List of usage examples for java.util SortedSet addAll

Introduction

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

Prototype

boolean addAll(Collection<? extends E> c);

Source Link

Document

Adds all of the elements in the specified collection to this set if they're not already present (optional operation).

Usage

From source file:net.sourceforge.fenixedu.domain.Lesson.java

public LessonInstance getLastLessonInstance() {
    SortedSet<LessonInstance> result = new TreeSet<LessonInstance>(
            LessonInstance.COMPARATOR_BY_BEGIN_DATE_TIME);
    result.addAll(getLessonInstancesSet());
    return !result.isEmpty() ? result.last() : null;
}

From source file:net.sourceforge.fenixedu.domain.Lesson.java

public LessonInstance getFirstLessonInstance() {
    SortedSet<LessonInstance> result = new TreeSet<LessonInstance>(
            LessonInstance.COMPARATOR_BY_BEGIN_DATE_TIME);
    result.addAll(getLessonInstancesSet());
    return !result.isEmpty() ? result.first() : null;
}

From source file:io.wcm.handler.url.suffix.SuffixBuilder.java

/**
 * Build complete suffix./*w w w. j a va2 s  .  c om*/
 * @return the suffix
 */
public String build() {
    SortedMap<String, Object> sortedParameterMap = new TreeMap<>(parameterMap);

    // gather resource paths in a treeset (having them in a defined order helps with caching)
    SortedSet<String> resourcePathsSet = new TreeSet<>();

    // iterate over all parts that should be kept from the current request
    for (String nextPart : initialSuffixParts) {
        // if this is a key-value-part:
        if (nextPart.indexOf(KEY_VALUE_DELIMITER) > 0) {
            String key = decodeKey(nextPart);
            // decode and keep the part if it is not overridden in the given parameter-map
            if (!sortedParameterMap.containsKey(key)) {
                String value = decodeValue(nextPart);
                sortedParameterMap.put(key, value);
            }
        } else {
            // decode and keep the resource paths (unless they are specified again in resourcePaths)
            String path = decodeResourcePathPart(nextPart);
            if (!resourcePaths.contains(path)) {
                resourcePathsSet.add(path);
            }
        }
    }

    // copy the resources specified as parameters to the sorted set of paths
    if (resourcePaths != null) {
        resourcePathsSet.addAll(ImmutableList.copyOf(resourcePaths));
    }

    // gather all suffix parts in this list
    List<String> suffixParts = new ArrayList<>();

    // now encode all resource paths
    for (String path : resourcePathsSet) {
        suffixParts.add(encodeResourcePathPart(path));
    }

    // now encode all entries from the parameter map
    for (Entry<String, Object> entry : sortedParameterMap.entrySet()) {
        Object value = entry.getValue();
        if (value == null) {
            // don't add suffix part if value is null
            continue;
        }
        String encodedKey = encodeKeyValuePart(entry.getKey());
        String encodedValue = encodeKeyValuePart(value.toString());
        suffixParts.add(encodedKey + KEY_VALUE_DELIMITER + encodedValue);
    }

    // finally join these parts to a single string
    return StringUtils.join(suffixParts, SUFFIX_PART_DELIMITER);
}

From source file:com.bigdata.dastor.db.ColumnFamilyStore.java

/**
 *
 * @param super_column//  ww w . j a  va2s  .c  om
 * @param range: either a Bounds, which includes start key, or a Range, which does not.
 * @param keyMax maximum number of keys to process, regardless of startKey/finishKey
 * @param sliceRange may be null if columnNames is specified. specifies contiguous columns to return in what order.
 * @param columnNames may be null if sliceRange is specified. specifies which columns to return in what order.      @return list of key->list<column> tuples.
 * @throws IOException
 * @throws ExecutionException
 * @throws InterruptedException
 */
public RangeSliceReply getRangeSlice(byte[] super_column, final AbstractBounds range, int keyMax,
        SliceRange sliceRange, List<byte[]> columnNames)
        throws IOException, ExecutionException, InterruptedException {
    List<String> keys = new ArrayList<String>();
    assert range instanceof Bounds || (!((Range) range).isWrapAround()
            || range.right.equals(StorageService.getPartitioner().getMinimumToken())) : range;
    getKeyRange(keys, range, keyMax);
    List<Row> rows = new ArrayList<Row>(keys.size());
    final QueryPath queryPath = new QueryPath(columnFamily_, super_column, null);
    final SortedSet<byte[]> columnNameSet = new TreeSet<byte[]>(getComparator());
    if (columnNames != null)
        columnNameSet.addAll(columnNames);
    for (String key : keys) {
        QueryFilter filter = sliceRange == null ? new NamesQueryFilter(key, queryPath, columnNameSet)
                : new SliceQueryFilter(key, queryPath, sliceRange.start, sliceRange.finish, sliceRange.reversed,
                        sliceRange.count);
        rows.add(new Row(key, getColumnFamily(filter)));
    }

    return new RangeSliceReply(rows);
}

From source file:org.fenixedu.academic.domain.ExecutionCourse.java

private static <T> SortedSet<T> constructSortedSet(Collection<T> collection, Comparator<? super T> c) {
    final SortedSet<T> sortedSet = new TreeSet<T>(c);
    sortedSet.addAll(collection);
    return sortedSet;
}

From source file:org.cloudata.core.tabletserver.MemorySSTable.java

public SortedSet<Row.Key> getAllRowKeys() {
    columnCollectionsLock.readLock().lock();
    try {/*www  .  j ava  2  s  . c  om*/
        SortedSet<Row.Key> result = new TreeSet<Row.Key>();
        for (Map.Entry<String, ColumnCollection> entry : columnCollections.entrySet()) {
            ColumnCollection columnCollection = entry.getValue();
            result.addAll(columnCollection.getRowKeySet());
        }
        return result;
    } finally {
        columnCollectionsLock.readLock().unlock();
    }
}

From source file:org.jahia.services.content.nodetypes.initializers.TemplatesChoiceListInitializerImpl.java

public List<ChoiceListValue> getChoiceListValues(ExtendedPropertyDefinition declaringPropertyDefinition,
        String param, List<ChoiceListValue> values, Locale locale, Map<String, Object> context) {
    if (context == null) {
        return new ArrayList<ChoiceListValue>();
    }/*from   www.  j a v  a 2  s.  c o  m*/
    JCRNodeWrapper node = (JCRNodeWrapper) context.get("contextNode");
    JCRNodeWrapper parentNode = (JCRNodeWrapper) context.get("contextParent");
    ExtendedNodeType realNodeType = (ExtendedNodeType) context.get("contextType");
    String propertyName = context.containsKey("dependentProperties")
            ? ((List<String>) context.get("dependentProperties")).get(0)
            : null;

    JCRSiteNode site = null;

    SortedSet<View> views = new TreeSet<View>();

    boolean subViews = false;

    try {
        if (node != null) {
            site = node.getResolveSite();
        }
        if (site == null && parentNode != null) {
            site = parentNode.getResolveSite();
        }

        final List<String> nodeTypeList = new ArrayList<String>();
        String nextParam = "";
        if (param.contains(",")) {
            nextParam = StringUtils.substringAfter(param, ",");
            param = StringUtils.substringBefore(param, ",");
        }
        if ("subnodes".equals(param)) {
            subViews = true;
            if (propertyName == null) {
                propertyName = "j:allowedTypes";
            }
            if (context.containsKey(propertyName)) {
                List<String> types = (List<String>) context.get(propertyName);
                for (String type : types) {
                    nodeTypeList.add(type);
                }
            } else if (node != null && node.hasProperty(propertyName)) {
                JCRPropertyWrapper property = node.getProperty(propertyName);
                if (property.isMultiple()) {
                    Value[] types = property.getValues();
                    for (Value type : types) {
                        nodeTypeList.add(type.getString());
                    }
                } else {
                    nodeTypeList.add(property.getValue().getString());
                }
            } else if (node != null && !"j:allowedTypes".equals(propertyName)
                    && node.hasProperty("j:allowedTypes")) {
                Value[] types = node.getProperty("j:allowedTypes").getValues();
                for (Value type : types) {
                    nodeTypeList.add(type.getString());
                }
            } else if (node != null) {
                // No restrictions get node type list from already existing nodes
                NodeIterator nodeIterator = node.getNodes();
                while (nodeIterator.hasNext()) {
                    Node next = (Node) nodeIterator.next();
                    String name = next.getPrimaryNodeType().getName();
                    if (!nodeTypeList.contains(name) && next.isNodeType("jnt:content")) {
                        nodeTypeList.add(name);
                    }
                }
            }
            param = nextParam;
        } else if ("reference".equals(param)) {
            if (propertyName == null) {
                propertyName = Constants.NODE;
            }
            if (context.containsKey(propertyName)) {
                JCRSessionWrapper session = JCRSessionFactory.getInstance().getCurrentUserSession();
                List<String> refNodeUuids = (List<String>) context.get(propertyName);
                for (String refNodeUuid : refNodeUuids) {
                    try {
                        JCRNodeWrapper refNode = session.getNodeByUUID(refNodeUuid);
                        nodeTypeList.addAll(refNode.getNodeTypes());
                    } catch (Exception e) {
                        logger.warn("Referenced node not found to retrieve its nodetype for initializer", e);
                    }
                }
            } else if (node != null && node.hasProperty(propertyName)) {
                try {
                    JCRNodeWrapper refNode = (JCRNodeWrapper) node.getProperty(propertyName).getNode();
                    nodeTypeList.addAll(refNode.getNodeTypes());
                } catch (ItemNotFoundException e) {
                }
            } else if (node != null && !Constants.NODE.equals(propertyName)
                    && node.hasProperty(Constants.NODE)) {
                try {
                    JCRNodeWrapper refNode = (JCRNodeWrapper) node.getProperty(Constants.NODE).getNode();
                    nodeTypeList.addAll(refNode.getNodeTypes());
                } catch (ItemNotFoundException e) {
                }
            }
            param = nextParam;
        } else if ("mainresource".equals(param)) {
            JCRNodeWrapper matchingParent;
            JCRNodeWrapper parent;
            if (node == null) {
                parent = (JCRNodeWrapper) context.get("contextParent");
                site = parent.getResolveSite();
            } else {
                parent = node.getParent();
            }
            try {
                while (true) {
                    if (parent.isNodeType("jnt:template")) {
                        matchingParent = parent;
                        break;
                    }
                    parent = parent.getParent();
                }
                if (matchingParent.hasProperty("j:applyOn")) {
                    Value[] vs = matchingParent.getProperty("j:applyOn").getValues();
                    for (Value v : vs) {
                        nodeTypeList.add(v.getString());
                    }
                }
            } catch (ItemNotFoundException e) {
            }
            if (nodeTypeList.isEmpty()) {
                nodeTypeList.add("jnt:page");
            }
            param = nextParam;
        } else if (param != null && param.indexOf(":") > 0) {
            nodeTypeList.add(param);
            param = nextParam;
        } else {
            if (node != null) {
                nodeTypeList.addAll(node.getNodeTypes());
            } else if (realNodeType != null) {
                nodeTypeList.add(realNodeType.getName());
            }
        }

        if (nodeTypeList.isEmpty()) {
            nodeTypeList.add("nt:base");
        }

        SortedSet<ViewWrapper> wrappedViews = new TreeSet<ViewWrapper>();
        Set<ViewWrapper> wrappedViewsSet = new HashSet<ViewWrapper>();
        for (String s : nodeTypeList) {
            SortedSet<View> viewsSet = RenderService.getInstance()
                    .getViewsSet(NodeTypeRegistry.getInstance().getNodeType(s), site, "html");

            if (!viewsSet.isEmpty()) {
                // use of wrapper class to get a simpler equals method, based on the key
                // to keep only views in common between sub nodes
                for (Iterator<View> iterator = viewsSet.iterator(); iterator.hasNext();) {
                    wrappedViewsSet.add(new ViewWrapper(iterator.next()));
                }

                if (subViews && !wrappedViews.isEmpty()) {
                    wrappedViews.retainAll(wrappedViewsSet);
                } else {
                    wrappedViews.addAll(wrappedViewsSet);
                }
            }
            wrappedViewsSet.clear();
        }

        for (Iterator<ViewWrapper> iterator = wrappedViews.iterator(); iterator.hasNext();) {
            views.add(iterator.next().getView());
        }

    } catch (RepositoryException e) {
        logger.error(e.getMessage(), e);
    }

    List<ChoiceListValue> vs = new ArrayList<ChoiceListValue>();
    for (View view : views) {
        HashMap<String, Object> map = new HashMap<String, Object>();
        fillProperties(map, view.getDefaultProperties());
        fillProperties(map, view.getProperties());
        boolean isStudio = site != null && site.getPath().startsWith("/modules");
        if (isViewVisible(view.getKey(), param, map, isStudio)) {
            JahiaTemplatesPackage pkg = view.getModule() != null ? view.getModule()
                    : ServicesRegistry.getInstance().getJahiaTemplateManagerService()
                            .getTemplatePackageById(JahiaTemplatesPackage.ID_DEFAULT);
            String displayName = Messages.get(pkg, declaringPropertyDefinition.getResourceBundleKey() + "."
                    + JCRContentUtils.replaceColon(view.getKey()), locale, view.getKey());
            ChoiceListValue c = new ChoiceListValue(displayName, map,
                    new ValueImpl(view.getKey(), PropertyType.STRING, false));
            try {
                final Resource imagePath = pkg.getResource(
                        File.separator + "img" + File.separator + c.getValue().getString() + ".png");

                if (imagePath != null && imagePath.exists()) {
                    String s = Jahia.getContextPath();
                    if (s.equals("/")) {
                        s = "";
                    }
                    c.addProperty("image", s + (pkg.getRootFolderPath().startsWith("/") ? "" : "/")
                            + pkg.getRootFolderPath() + "/img/" + c.getValue().getString() + ".png");
                }
            } catch (RepositoryException e) {
                logger.error(e.getMessage(), e);
            }

            vs.add(c);
        }
    }
    Collections.sort(vs);
    return vs;
}

From source file:de.ii.ldproxy.service.LdProxyService.java

private SortedSet<String> harvestIndex(WfsProxyFeatureType featureType, String property)
        throws ExecutionException {
    // TODO: only if WFS 2.0.0, else GetFeature
    // TODO: seems to be incomplete, try GetFeature with paging

    String propertyName = property.substring(property.lastIndexOf(':') + 1);

    SortedSet<String> values = new TreeSet<>();
    int count = 15000;
    int startIndex = 0;
    int numberMatched = 1;
    int tries = 0;

    //WFSOperation operation = new GetPropertyValuePaging(getWfsAdapter().getNsStore().getNamespacePrefix(featureType.getNamespace()), featureType.getName(), propertyName, -1, 0);
    while (numberMatched > 0 && startIndex < numberMatched) {
        WFSOperation operation = new GetFeaturePaging(
                getWfsAdapter().getNsStore().getNamespacePrefix(featureType.getNamespace()),
                featureType.getName(), count, startIndex);
        WFSRequest request = new WFSRequest(getWfsAdapter(), operation);

        IndexValueWriter indexValueWriter = new IndexValueWriter(propertyName);

        GMLParser gmlParser = new GMLParser(indexValueWriter, staxFactory);
        try {//from  w w w.j a v a2s .c  o m
            gmlParser.parse(request.getResponse(), WFS.getNS(WFS.VERSION._2_0_0), "member");
        } catch (Throwable e) {
            // ignore
        }
        if (indexValueWriter.hasFailed() && tries < 3) {
            tries++;
            LOGGER.getLogger().debug("TRYING AGAIN {}", tries);
            continue;
        }

        values.addAll(indexValueWriter.getValues());
        numberMatched = indexValueWriter.getNumberMatched();
        startIndex += count;
        tries = 0;
        LOGGER.getLogger().debug("{}/{}", startIndex, numberMatched);
    }

    return values;
}

From source file:net.sourceforge.fenixedu.domain.Lesson.java

public SortedSet<YearMonthDay> getAllLessonDatesWithoutInstanceDates() {
    SortedSet<YearMonthDay> dates = new TreeSet<YearMonthDay>();
    if (!wasFinished()) {
        YearMonthDay startDateToSearch = getLessonStartDay();
        YearMonthDay endDateToSearch = getLessonEndDay();
        dates.addAll(getAllValidLessonDatesWithoutInstancesDates(startDateToSearch, endDateToSearch));
    }/*from   w  w  w .  ja v a  2  s  .  c  om*/
    return dates;
}

From source file:net.sourceforge.fenixedu.domain.Lesson.java

public SortedSet<YearMonthDay> getAllLessonDates() {
    SortedSet<YearMonthDay> dates = getAllLessonInstanceDates();
    if (!wasFinished()) {
        YearMonthDay startDateToSearch = getLessonStartDay();
        YearMonthDay endDateToSearch = getLessonEndDay();
        dates.addAll(getAllValidLessonDatesWithoutInstancesDates(startDateToSearch, endDateToSearch));
    }/*  w w  w .  j  av a 2  s  .  c  o  m*/
    return dates;
}