Example usage for com.google.common.collect Sets newTreeSet

List of usage examples for com.google.common.collect Sets newTreeSet

Introduction

In this page you can find the example usage for com.google.common.collect Sets newTreeSet.

Prototype

public static <E> TreeSet<E> newTreeSet(Comparator<? super E> comparator) 

Source Link

Document

Creates a mutable, empty TreeSet instance with the given comparator.

Usage

From source file:com.edmunds.etm.identity.IdentityLoadBalancer.java

@Override
public synchronized HostAddress createVirtualServer(VirtualServer server,
        VirtualServerConfig virtualServerConfig, HttpMonitor httpMonitor)
        throws VirtualServerExistsException, RemoteException {

    final String name = server.getName();
    final HostAddress hostAddress = new HostAddress("localhost", virtualServerConfig.getPort());
    final SortedSet<PoolMember> poolMembers = Sets.newTreeSet(server.getPoolMembers());
    final VirtualServer serverCopy = new VirtualServer(name, hostAddress, poolMembers);

    virtualServers.put(name, serverCopy);

    return hostAddress;
}

From source file:org.apache.hadoop.hbase.regionserver.wal.FSWALEntry.java

FSWALEntry(final long sequence, final WALKey key, final WALEdit edit,
        final AtomicLong referenceToRegionSequenceId, final boolean inMemstore, final HTableDescriptor htd,
        final HRegionInfo hri, List<Cell> memstoreCells) {
    super(key, edit);
    this.regionSequenceIdReference = referenceToRegionSequenceId;
    this.inMemstore = inMemstore;
    this.htd = htd;
    this.hri = hri;
    this.sequence = sequence;
    this.memstoreCells = memstoreCells;
    if (inMemstore) {
        // construct familyNames here to reduce the work of log sinker.
        ArrayList<Cell> cells = this.getEdit().getCells();
        if (CollectionUtils.isEmpty(cells)) {
            this.familyNames = Collections.<byte[]>emptySet();
        } else {/*ww  w .j  a va  2 s .c o  m*/
            Set<byte[]> familySet = Sets.newTreeSet(Bytes.BYTES_COMPARATOR);
            for (Cell cell : cells) {
                if (!CellUtil.matchingFamily(cell, WALEdit.METAFAMILY)) {
                    familySet.add(CellUtil.cloneFamily(cell));
                }
            }
            this.familyNames = Collections.unmodifiableSet(familySet);
        }
    } else {
        this.familyNames = Collections.<byte[]>emptySet();
    }
}

From source file:azkaban.serialization.ComposedEFSerializer.java

@Override
public Map<String, Object> apply(ExecutableFlow executableFlow) {
    ComposedExecutableFlow flow = (ComposedExecutableFlow) executableFlow;

    final Map<String, Object> dependeeMap = globalSerializer.apply(flow.getDependee());
    final Map<String, Object> dependerMap = globalSerializer.apply(flow.getDepender());

    Map<String, Object> retVal = new HashMap<String, Object>();

    retVal.put("jobs", FoldLeft.fold(Iterables.transform(Arrays.asList(dependeeMap, dependerMap),
            new Function<Map<String, Object>, Map<String, Object>>() {
                @Override// ww w.  j a  v  a2s  .c o m
                public Map<String, Object> apply(Map<String, Object> descriptor) {
                    return Verifier.getVerifiedObject(descriptor, "jobs", Map.class);
                }
            }), new HashMap<String, Object>(), new FoldLeft<Map<String, Object>, HashMap<String, Object>>() {
                @Override
                public HashMap<String, Object> fold(HashMap<String, Object> oldValue,
                        Map<String, Object> newValue) {
                    for (Map.Entry<String, Object> entry : newValue.entrySet()) {
                        final String key = entry.getKey();

                        if (!oldValue.containsKey(key)) {
                            oldValue.put(key, entry.getValue());
                        }
                    }

                    return oldValue;
                }
            }));

    retVal.put("root", Verifier.getVerifiedObject(dependerMap, "root", List.class));

    Map<String, Object> dependenciesMap = new HashMap<String, Object>();
    for (Object o : Verifier.getVerifiedObject(dependeeMap, "dependencies", Map.class).entrySet()) {
        Map.Entry entry = (Map.Entry) o;
        dependenciesMap.put(entry.getKey().toString(), entry.getValue());
    }

    for (Object o : Verifier.getVerifiedObject(dependerMap, "dependencies", Map.class).entrySet()) {
        Map.Entry entry = (Map.Entry) o;
        String key = entry.getKey().toString();

        if (dependenciesMap.containsKey(key)) {
            dependenciesMap.put(key,
                    Sets.newTreeSet(Iterables.concat((Set) entry.getValue(), (Set) dependenciesMap.get(key))));
        } else {
            dependenciesMap.put(key, entry.getValue());
        }
    }

    for (Object o : Verifier.getVerifiedObject(dependerMap, "root", List.class)) {
        Set<String> set = new TreeSet<String>();
        String key = o.toString();

        for (Object o1 : Verifier.getVerifiedObject(dependeeMap, "root", List.class)) {
            set.add(o1.toString());
        }

        if (dependenciesMap.containsKey(key)) {
            dependenciesMap.put(key, Sets.newTreeSet(Iterables.concat(set, (Set) dependenciesMap.get(key))));
        } else {
            dependenciesMap.put(key, set);
        }
    }

    retVal.put("dependencies", dependenciesMap);
    retVal.put("id", flow.getId());

    return retVal;
}

From source file:com.textocat.textokit.commons.cas.TreeMapOverlapIndex.java

@Override
public Set<A> getOverlapping(int begin, int end) {
    // TODO this implementation is broken
    // it does not handle cas when one annotations cover another
    Set<A> result = Sets.newTreeSet(innerComparator);
    // annotations whose begin in [begin, end) interval
    NavigableMap<Integer, Set<A>> subByBegin = beginIdx.subMap(begin, true, end, false);
    for (Set<A> annoSet : subByBegin.values()) {
        if (annoSet != null) {
            result.addAll(annoSet);//from ww w  . java2s. c om
        }
    }
    // annotations whose end in (begin, end]
    NavigableMap<Integer, Set<A>> subByEnd = endIdx.subMap(begin, false, end, true);
    for (Set<A> annoSet : subByEnd.values()) {
        if (annoSet != null) {
            result.addAll(annoSet);
        }
    }
    return result;
}

From source file:org.gradle.api.reporting.components.internal.ComponentReportRenderer.java

public void renderBinaries(Iterable<BinarySpec> binaries) {
    Set<BinarySpec> additionalBinaries = Sets.newTreeSet(TypeAwareBinaryRenderer.SORT_ORDER);
    for (BinarySpec binary : binaries) {
        if (!componentBinaries.contains(binary)) {
            additionalBinaries.add(binary);
        }/*from www.  j a  va2s. co  m*/
    }
    if (!additionalBinaries.isEmpty()) {
        getBuilder().getOutput().println();
        getBuilder().collection("Additional binaries", additionalBinaries, binaryRenderer, "binaries");
    }
}

From source file:com.opengamma.integration.viewer.status.impl.ViewStatusCalculationWorker.java

public ViewStatusCalculationWorker(final ToolContext toolContext, UniqueId portfolioId,
        final ViewStatusOption option, final ExecutorService executorService) {
    ArgumentChecker.notNull(toolContext, "toolContex");
    ArgumentChecker.notNull(portfolioId, "portfolioId");
    ArgumentChecker.notNull(option, "option");
    ArgumentChecker.notNull(option.getUser(), "option.user");
    ArgumentChecker.notNull(option.getMarketDataSpecification(), "option.marketDataSpecification");
    ArgumentChecker.notNull(executorService, "executorService");

    validateComponentsInToolContext(toolContext);
    _portfolioId = portfolioId;//from   w w w  .j  a  va  2 s .  c  o  m
    _user = option.getUser();
    _marketDataSpecification = option.getMarketDataSpecification();
    Map<String, Collection<String>> valueRequirementBySecType = scanValueRequirementBySecType(portfolioId,
            toolContext);
    if (s_logger.isDebugEnabled()) {
        StringBuilder strBuf = new StringBuilder();
        for (String securityType : Sets.newTreeSet(valueRequirementBySecType.keySet())) {
            Set<String> valueNames = Sets.newTreeSet(valueRequirementBySecType.get(securityType));
            strBuf.append(
                    String.format("%s\t%s\n", StringUtils.rightPad(securityType, 40), valueNames.toString()));
        }
        s_logger.debug("\n{}\n", strBuf.toString());
    }
    _toolContext = toolContext;
    _executor = executorService;
    _valueRequirementBySecType = valueRequirementBySecType;
}

From source file:be.nbb.jackcess.JackcessStatement.java

private static SortedSet<Column> mergeAndSortByInternalIndex(Iterable<Column>... list) {
    SortedSet<Column> result = Sets.newTreeSet(BY_COLUMN_INDEX);
    for (Iterable<Column> o : list) {
        Iterables.addAll(result, o);//from ww w .  j  a  v  a2 s. co m
    }
    return result;
}

From source file:org.apache.pulsar.client.impl.conf.ConsumerConfigurationData.java

public ConsumerConfigurationData<T> clone() {
    try {//from   w ww.  j  a  va2  s .c om
        @SuppressWarnings("unchecked")
        ConsumerConfigurationData<T> c = (ConsumerConfigurationData<T>) super.clone();
        c.topicNames = Sets.newTreeSet(this.topicNames);
        c.properties = Maps.newTreeMap(this.properties);
        return c;
    } catch (CloneNotSupportedException e) {
        throw new RuntimeException("Failed to clone ConsumerConfigurationData");
    }
}

From source file:azkaban.serialization.GroupedEFSerializer.java

@Override
public Map<String, Object> apply(ExecutableFlow executableFlow) {
    GroupedExecutableFlow flow = (GroupedExecutableFlow) executableFlow;

    List<ExecutableFlow> children = flow.getChildren();
    List<Map<String, Object>> childMaps = new ArrayList<Map<String, Object>>(children.size());

    for (ExecutableFlow child : children) {
        childMaps.add(globalSerializer.apply(child));
    }// w  ww.  j  a v a  2  s  .  co  m

    Map<String, Object> retVal = new HashMap<String, Object>();

    Map<String, Object> jobsMap = new HashMap<String, Object>();
    for (Map<String, Object> childMap : childMaps) {
        Map<String, Object> childJobsMap = Verifier.getVerifiedObject(childMap, "jobs", Map.class);

        for (Map.Entry<String, Object> entry : childJobsMap.entrySet()) {
            final String key = entry.getKey();

            if (!jobsMap.containsKey(key)) {
                jobsMap.put(key, entry.getValue());
            }
        }
    }

    retVal.put("jobs", jobsMap);

    List<Object> rootList = new ArrayList<Object>(childMaps.size());
    for (Map<String, Object> childMap : childMaps) {
        for (Object root : Verifier.getVerifiedObject(childMap, "root", List.class)) {
            rootList.add(root);
        }
    }

    retVal.put("root", rootList);

    Map<String, Object> dependenciesMap = new HashMap<String, Object>();
    for (Map<String, Object> childMap : childMaps) {
        for (Object o : Verifier.getVerifiedObject(childMap, "dependencies", Map.class).entrySet()) {
            Map.Entry entry = (Map.Entry<String, Object>) o;

            String key = entry.getKey().toString();

            Object value = entry.getValue();
            if (value == null || !(value instanceof Set)) {
                throw new RuntimeException(String.format("Key[%s] pointed to a %s instead of a %s.  Map[%s]",
                        key, value.getClass(), Set.class, childMaps));
            }
            Set newDependencies = (Set) value;

            if (dependenciesMap.containsKey(key)) {
                Set existingDependencies = Verifier.getVerifiedObject(dependenciesMap, key, Set.class);

                dependenciesMap.put(key,
                        Sets.newTreeSet(Iterables.concat(existingDependencies, newDependencies)));
            } else {
                dependenciesMap.put(key, newDependencies);
            }
        }
    }

    retVal.put("dependencies", dependenciesMap);
    retVal.put("id", flow.getId());

    return retVal;
}

From source file:com.google.api.tools.framework.aspects.http.model.CollectionAttribute.java

/** @return names of all the rest methods inside this collection. */
public Set<String> getRestMethodNames() {
    return Sets.newTreeSet(methods.keySet());
}