Example usage for java.util SortedSet add

List of usage examples for java.util SortedSet add

Introduction

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

Prototype

boolean add(E e);

Source Link

Document

Adds the specified element to this set if it is not already present (optional operation).

Usage

From source file:models.ModuleVersion.java

public static SortedMap<String, SortedSet<ModuleVersion>> findDependants(String moduleName, String version) {
    String query = "SELECT d.version, v FROM ModuleVersion v JOIN v.dependencies d LEFT JOIN FETCH v.module WHERE d.name=:name";
    if (version != null && !version.isEmpty()) {
        query += " AND d.version=:version";
    }//  w  w  w .j  a  v a  2  s .co m
    Query jpa = JPA.em().createQuery(query).setParameter("name", moduleName);
    if (version != null && !version.isEmpty()) {
        jpa.setParameter("version", version);
    }
    List<Object[]> results = jpa.getResultList();

    Comparator<String> versionComparator = new Comparator<String>() {
        @Override
        public int compare(String v1, String v2) {
            return Util.compareVersions(v1, v2);
        }
    };

    Comparator<ModuleVersion> dependantComparator = new Comparator<ModuleVersion>() {
        @Override
        public int compare(ModuleVersion v1, ModuleVersion v2) {
            int result = v1.module.name.compareTo(v2.module.name);
            if (result == 0) {
                result = Util.compareVersions(v1.version, v2.version);
            }
            return result;
        }
    };

    SortedMap<String, SortedSet<ModuleVersion>> dependantsMap = new TreeMap<String, SortedSet<ModuleVersion>>(
            versionComparator);
    for (Object[] result : results) {
        String ver = (String) result[0];
        ModuleVersion dependant = (ModuleVersion) result[1];

        SortedSet<ModuleVersion> dependants = dependantsMap.get(ver);
        if (dependants == null) {
            dependants = new TreeSet<ModuleVersion>(dependantComparator);
            dependantsMap.put(ver, dependants);
        }
        dependants.add(dependant);
    }

    return dependantsMap;
}

From source file:de.shadowhunt.sonar.plugins.ignorecode.model.AbstractPattern.java

static SortedSet<Integer> parseLineValues(final String lineValues) {
    final SortedSet<Integer> lines = new TreeSet<>();
    if ("*".equals(lineValues)) {
        return lines;
    }//from ww  w  .  j a v a  2s  .c om

    final String s = StringUtils.substringBetween(StringUtils.trim(lineValues), "[", "]");
    final String[] parts = StringUtils.split(s, ',');
    for (final String part : parts) {
        if (StringUtils.contains(part, '-')) {
            final String[] range = StringUtils.split(part, '-');
            final int from = Integer.parseInt(range[0]);
            final int to = Integer.parseInt(range[1]);
            addLines(lines, from, to);
        } else {
            lines.add(Integer.parseInt(part));
        }
    }
    return lines;
}

From source file:com.cloudera.whirr.cm.CmServerClusterInstance.java

public static boolean logCluster(CmServerLog logger, String label, Configuration configuration,
        CmServerCluster cluster, Set<Instance> instances) throws IOException {
    if (!instances.isEmpty()) {
        logger.logOperationInProgressSync(label, "HOST ADDRESSES");
        for (Instance instance : instances) {
            logger.logOperationInProgressSync(label,
                    "  " + instance.getId() + "@" + instance.getPublicHostName() + "@" + instance.getPublicIp()
                            + "@" + instance.getPrivateIp());
        }/*from   w  ww  .  j a  va  2  s.  co m*/
    }
    if (!cluster.getAgents().isEmpty()) {
        logger.logOperationInProgressSync(label, "HOST SSH");
    }
    SortedSet<String> cmAgentsSorted = new TreeSet<String>();
    for (CmServerService cmAgent : cluster.getAgents()) {
        cmAgentsSorted.add("  ssh -o StrictHostKeyChecking=no -i "
                + configuration.getString(ClusterSpec.Property.PRIVATE_KEY_FILE.getConfigName()) + " "
                + configuration.getString(ClusterSpec.Property.CLUSTER_USER.getConfigName()) + "@"
                + cmAgent.getIp());
    }
    for (String cmAgentSorted : cmAgentsSorted) {
        logger.logOperationInProgressSync(label, cmAgentSorted);
    }
    if (!cluster.getServiceTypes(CmServerServiceType.CLUSTER).isEmpty()) {
        for (CmServerServiceType type : cluster.getServiceTypes()) {
            logger.logOperationInProgressSync(label, "CDH " + type.toString() + " SERVICE");
            for (CmServerService service : cluster.getServices(type)) {
                logger.logOperationInProgressSync(label,
                        "  " + service.getName() + "@" + service.getIp() + "=" + service.getStatus());
            }
        }
    }
    Set<Instance> balancerInstances = new HashSet<Cluster.Instance>();
    for (Instance instance : instances) {
        if (instance.getRoles().contains(CmBalancerHandler.ROLE)) {
            balancerInstances.add(instance);
        }
    }
    if (!balancerInstances.isEmpty()) {
        logger.logOperationInProgressSync(label, "BALANCER IMPALA");
        for (Instance instance : balancerInstances) {
            logger.logOperationInProgressSync(label, "  impala-shell -i " + instance.getPrivateIp() + ":"
                    + configuration.getString(CmConstants.CONFIG_WHIRR_INTERNAL_PORT_BALANCER_IMPALA));
        }
    }
    logger.logOperationInProgressSync(label, "CONSOLE MANAGER");
    if (cluster.getServer() != null) {
        logger.logOperationInProgressSync(label, "  http://" + cluster.getServer().getHost() + ":"
                + configuration.getString(CmConstants.CONFIG_WHIRR_INTERNAL_PORT_WEB));
    } else {
        logger.logOperationInProgressSync(label, "NO CM SERVER");
    }
    logger.logOperationInProgressSync(label, "CONSOLE NAVIGATOR");
    if (cluster.getServer() != null) {
        logger.logOperationInProgressSync(label, "  http://" + cluster.getServer().getHost() + ":"
                + configuration.getString(CmConstants.CONFIG_WHIRR_INTERNAL_PORT_NAV));
    } else {
        logger.logOperationInProgressSync(label, "NO NAVIGATOR SERVER");
    }
    logger.logOperationInProgressSync(label, "CONSOLE HUE");
    if (cluster.getServiceTypes(CmServerServiceType.HUE) != null) {
        String hueHost = null;
        for (Instance instance : instances) {
            if (instance.getRoles().contains(CmCdhHueServerHandler.ROLE)) {
                hueHost = instance.getPublicHostName();
                break;
            }
        }
        logger.logOperationInProgressSync(label, "  http://" + hueHost + ":"
                + configuration.getString(CmConstants.CONFIG_WHIRR_INTERNAL_PORT_HUE));
    } else {
        logger.logOperationInProgressSync(label, "NO HUE SERVER");
    }
    return !cluster.isEmpty();
}

From source file:net.rrm.ehour.ui.admin.config.MainConfigBackingBean.java

public static List<Locale> getAvailableCurrencies() {
    List<Locale> locales = getAvailableLocales();
    SortedSet<Locale> currencyLocales = new TreeSet<>(new Comparator<Locale>() {
        public int compare(Locale o1, Locale o2) {
            Currency curr1 = Currency.getInstance(o1);
            Currency curr2 = Currency.getInstance(o2);

            return (o1.getDisplayCountry() + ": " + curr1.getSymbol(o1))
                    .compareTo(o2.getDisplayCountry() + ": " + curr2.getSymbol(o2));
        }/*from   ww  w.  j  a  va2s  . c  om*/
    });

    for (Locale locale : locales) {
        if (!StringUtils.isBlank(locale.getCountry())) {
            currencyLocales.add(locale);
        }
    }

    return new ArrayList<>(currencyLocales);
}

From source file:com.spotify.heroic.filter.impl.OrFilterImpl.java

private static SortedSet<Filter> flatten(final Collection<Filter> statements) {
    final SortedSet<Filter> result = new TreeSet<>();

    for (final Filter f : statements) {
        final Filter o = f.optimize();

        if (o == null) {
            continue;
        }/*from www  .  j  a v a 2  s  .  c  om*/

        if (o instanceof Filter.Or) {
            result.addAll(((Filter.Or) o).terms());
            continue;
        }

        if (o instanceof Filter.Not) {
            final Filter.Not not = (Filter.Not) o;

            if (not.first() instanceof Filter.And) {
                result.addAll(collapseNotAnd((Filter.And) not.first()));
                continue;
            }
        }

        result.add(o);
    }

    return result;
}

From source file:com.spotify.heroic.filter.impl.AndFilterImpl.java

private static SortedSet<Filter> flatten(final Collection<Filter> statements) {
    final SortedSet<Filter> result = new TreeSet<>();

    for (final Filter f : statements) {
        final Filter o = f.optimize();

        if (o == null) {
            continue;
        }/*  ww  w  . j  a v a2 s .  c  om*/

        if (o instanceof Filter.And) {
            result.addAll(((Filter.And) o).terms());
            continue;
        }

        if (o instanceof Filter.Not) {
            final Filter.Not not = (Filter.Not) o;

            if (not.first() instanceof Filter.Or) {
                result.addAll(collapseNotOr((Filter.Or) not.first()));
                continue;
            }
        }

        result.add(o);
    }

    return result;
}

From source file:com.greenpepper.server.rpc.xmlrpc.XmlRpcDataMarshaller.java

/**
 * Rebuild a List of systemUnderTests based on the vector of systemUnderTests parameters.
 * </p>//from   w  w  w . ja va2  s . co  m
 *
 * @param sutsParams a {@link java.util.Vector} object.
 * @return a List of systemUnderTests based on the vector of systemUnderTests parameters.
 * @see #toSystemUnderTest(Vector)
 */
@SuppressWarnings("unchecked")
public static SortedSet<SystemUnderTest> toSystemUnderTestList(Vector<Object> sutsParams) {
    SortedSet<SystemUnderTest> suts = new TreeSet<SystemUnderTest>(new SystemUnderTestByNameComparator());
    for (Object sutParams : sutsParams) {
        suts.add(toSystemUnderTest((Vector<Object>) sutParams));
    }

    return suts;
}

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

/**
 * Handles known special cases, i.e bugs in renderers' {@code protocolInfo}
 * output so that we are able to parse them despite them being broken.
 *
 * @param element the {@code protocolInfo} element to handle if needed.
 * @return {@code null} if {@code element} doesn't match a known special
 *         case, or a {@link SortedSet} of {@link ProtocolInfo} instances
 *         with the result of the parsed special case.
 * @throws ParseException If {@code element} is a known special case but the
 *             parsing fails.// w w w . j a v a  2  s  .c  om
 */
public static SortedSet<ProtocolInfo> handleSpecialCaseString(String element) throws ParseException {
    if (isBlank(element)) {
        return null;
    }
    switch (element) {
    /*
     * Seen on a LG-BP550-1, missing comma between elements
     */
    case "http-get:*:audio/sonyoma:*http-get:*:audio/ogg:*":
        SortedSet<ProtocolInfo> currentSet = new TreeSet<>();
        currentSet.add(new ProtocolInfo("http-get:*:audio/sonyoma:*"));
        currentSet.add(new ProtocolInfo("http-get:*:audio/ogg:*"));
        return currentSet;
    }
    return null;
}

From source file:hudson.logging.LogRecorder.java

@Restricted(NoExternalUse.class)
@VisibleForTesting/*from w ww  .  j av  a  2s.co m*/
public static Set<String> getAutoCompletionCandidates(List<String> loggerNamesList) {
    Set<String> loggerNames = new HashSet<>(loggerNamesList);

    // now look for package prefixes that make sense to offer for autocompletion:
    // Only prefixes that match multiple loggers will be shown.
    // Example: 'org' will show 'org', because there's org.apache, org.jenkinsci, etc.
    // 'io' might only show 'io.jenkins.plugins' rather than 'io' if all loggers starting with 'io' start with 'io.jenkins.plugins'.
    HashMap<String, Integer> seenPrefixes = new HashMap<>();
    SortedSet<String> relevantPrefixes = new TreeSet<>();
    for (String loggerName : loggerNames) {
        String[] loggerNameParts = loggerName.split("[.]");

        String longerPrefix = null;
        for (int i = loggerNameParts.length; i > 0; i--) {
            String loggerNamePrefix = StringUtils.join(Arrays.copyOf(loggerNameParts, i), ".");
            seenPrefixes.put(loggerNamePrefix, seenPrefixes.getOrDefault(loggerNamePrefix, 0) + 1);
            if (longerPrefix == null) {
                relevantPrefixes.add(loggerNamePrefix); // actual logger name
                longerPrefix = loggerNamePrefix;
                continue;
            }

            if (seenPrefixes.get(loggerNamePrefix) > seenPrefixes.get(longerPrefix)) {
                relevantPrefixes.add(loggerNamePrefix);
            }
            longerPrefix = loggerNamePrefix;
        }
    }
    return relevantPrefixes;
}

From source file:com.spotify.heroic.filter.OrFilter.java

static Filter optimize(final SortedSet<Filter> filters) {
    final SortedSet<Filter> result = new TreeSet<>();

    for (final Filter f : filters) {
        if (f instanceof NotFilter) {
            // Optimize away expressions which are always true.
            // Example: foo = bar or !(foo = bar)

            if (filters.contains(((NotFilter) f).getFilter())) {
                return TrueFilter.get();
            }/*from  w w  w  . j a v  a  2  s  .  c  o  m*/
        } else if (f instanceof StartsWithFilter) {
            // Optimize away prefixes which encompass each other.
            // Example: foo ^ hello or foo ^ helloworld -> foo ^ hello

            if (FilterUtils.containsPrefixedWith(filters, (StartsWithFilter) f,
                    (inner, outer) -> FilterUtils.prefixedWith(outer.getValue(), inner.getValue()))) {
                continue;
            }
        }

        result.add(f);
    }

    if (result.isEmpty()) {
        return TrueFilter.get();
    }

    if (result.size() == 1) {
        return result.iterator().next();
    }

    return new OrFilter(ImmutableList.copyOf(result));
}