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 extends Comparable> TreeSet<E> newTreeSet() 

Source Link

Document

Creates a mutable, empty TreeSet instance sorted by the natural sort ordering of its elements.

Usage

From source file:com.googlesource.gerrit.plugins.verifystatus.init.InitPlugin.java

@Override
public void run() throws Exception {
    ui.header("SQL Database for CI plugin");

    Set<String> allowedValues = Sets.newTreeSet();
    Injector i = Guice.createInjector(PRODUCTION, new DatabaseConfigModule(site));

    List<Binding<DatabaseConfigInitializer>> dbConfigBindings = i
            .findBindingsByType(new TypeLiteral<DatabaseConfigInitializer>() {
            });// w  ww . ja  v  a2  s .  c  o m
    for (Binding<DatabaseConfigInitializer> binding : dbConfigBindings) {
        Annotation annotation = binding.getKey().getAnnotation();
        if (annotation instanceof Named) {
            allowedValues.add(((Named) annotation).value());
        }
    }

    if (!Strings.isNullOrEmpty(configSection.get("dbUrl"))
            && Strings.isNullOrEmpty(configSection.get("dbType"))) {
        configSection.set("dbType", "h2");
    }

    String dbType = configSection.select("Database server type", "dbType", "h2", allowedValues);

    DatabaseConfigInitializer dci = i
            .getInstance(Key.get(DatabaseConfigInitializer.class, Names.named(dbType.toLowerCase())));

    /**
     * TODO(davido): We probably don't need that, as CI database would be from the same type as
     * ReviewDb. So we expect that the needed libraries were already installed.
     *
     * <p>if (dci instanceof MySqlInitializer) { libraries.mysqlDriver.downloadRequired(); } else if
     * (dci instanceof OracleInitializer) { libraries.oracleDriver.downloadRequired(); } else if
     * (dci instanceof DB2Initializer) { libraries.db2Driver.downloadRequired(); }
     */
    dci.initConfig(configSection);
}

From source file:com.yahoo.pulsar.broker.service.persistent.PersistentDispatcherMultipleConsumers.java

public PersistentDispatcherMultipleConsumers(PersistentTopic topic, ManagedCursor cursor) {
    this.cursor = cursor;
    this.name = topic.getName() + " / " + Codec.decode(cursor.getName());
    this.topic = topic;
    this.messagesToReplay = Sets.newTreeSet();
    this.readBatchSize = MaxReadBatchSize;
}

From source file:com.googlesource.gerrit.plugins.ci.init.InitPlugin.java

@Override
public void run() throws Exception {
    ui.header("SQL Database for CI plugin");

    Set<String> allowedValues = Sets.newTreeSet();
    Injector i = Guice.createInjector(PRODUCTION, new DatabaseConfigModule(site));

    List<Binding<DatabaseConfigInitializer>> dbConfigBindings = i
            .findBindingsByType(new TypeLiteral<DatabaseConfigInitializer>() {
            });/* w w  w  .  j av a  2 s .  co m*/
    for (Binding<DatabaseConfigInitializer> binding : dbConfigBindings) {
        Annotation annotation = binding.getKey().getAnnotation();
        if (annotation instanceof Named) {
            allowedValues.add(((Named) annotation).value());
        }
    }

    if (!Strings.isNullOrEmpty(configSection.get("dbUrl"))
            && Strings.isNullOrEmpty(configSection.get("dbType"))) {
        configSection.set("dbType", "h2");
    }

    String dbType = configSection.select("Database server type", "dbType", "h2", allowedValues);

    DatabaseConfigInitializer dci = i
            .getInstance(Key.get(DatabaseConfigInitializer.class, Names.named(dbType.toLowerCase())));

    /** TODO(davido): We probably don't need that, as
     * CI database would be from the same type as
     * ReviewDb. So we expect that the needed libraries
     * were already installed.
     *
    if (dci instanceof MySqlInitializer) {
      libraries.mysqlDriver.downloadRequired();
    } else if (dci instanceof OracleInitializer) {
      libraries.oracleDriver.downloadRequired();
    } else if (dci instanceof DB2Initializer) {
      libraries.db2Driver.downloadRequired();
    }
    **/

    dci.initConfig(configSection);
}

From source file:no.ssb.vtl.script.operations.KeepOperation.java

/**
 * Find the index of the component in the child data structure.
 *//*from   w w  w  . jav a 2 s .  co  m*/
private ImmutableSet<Integer> computeIndexes(List<Component> componentsToRemove) {
    TreeSet<Integer> indexes = Sets.newTreeSet();
    List<Component> components = Lists.newArrayList(getChild().getDataStructure().values());
    for (Component component : componentsToRemove) {
        ListIterator<Component> iterator = components.listIterator();
        while (iterator.hasNext()) {
            int index = iterator.nextIndex();
            Component next = iterator.next();
            if (component.equals(next))
                indexes.add(index);
        }
    }
    return ImmutableSet.copyOf(indexes.descendingIterator());
}

From source file:cuchaz.m3l.util.transformation.BytecodeTools.java

public static Bytecode copyBytecodeToConstPool(ConstPool dest, Bytecode bytecode) throws BadBytecode {

    // get the entries this bytecode needs from the const pool
    Set<Integer> indices = Sets.newTreeSet();
    ConstPoolEditor editor = new ConstPoolEditor(bytecode.getConstPool());
    BytecodeIndexIterator iterator = new BytecodeIndexIterator(bytecode);
    for (BytecodeIndexIterator.Index index : iterator.indices()) {
        assert (index.isValid(bytecode));
        InfoType.gatherIndexTree(indices, editor, index.getIndex());
    }//from w  w w. j  a  va 2s .  c  om

    Map<Integer, Integer> indexMap = Maps.newTreeMap();

    ConstPool src = bytecode.getConstPool();
    ConstPoolEditor editorSrc = new ConstPoolEditor(src);
    ConstPoolEditor editorDest = new ConstPoolEditor(dest);

    // copy entries over in order of level so the index mapping is easier
    for (InfoType type : InfoType.getSortedByLevel()) {
        for (int index : indices) {
            ConstInfoAccessor entry = editorSrc.getItem(index);

            // skip entries that aren't this type
            if (entry.getType() != type) {
                continue;
            }

            // make sure the source entry is valid before we copy it
            assert (type.subIndicesAreValid(entry, editorSrc));
            assert (type.selfIndexIsValid(entry, editorSrc));

            // make a copy of the entry so we can modify it safely
            ConstInfoAccessor entryCopy = editorSrc.getItem(index).copy();
            assert (type.subIndicesAreValid(entryCopy, editorSrc));
            assert (type.selfIndexIsValid(entryCopy, editorSrc));

            // remap the indices
            type.remapIndices(indexMap, entryCopy);
            assert (type.subIndicesAreValid(entryCopy, editorDest));

            // put the copy in the destination pool
            int newIndex = editorDest.addItem(entryCopy.getItem());
            entryCopy.setIndex(newIndex);
            assert (type.selfIndexIsValid(entryCopy, editorDest)) : type + ", self: " + entryCopy + " dest: "
                    + editorDest.getItem(entryCopy.getIndex());

            // make sure the source entry is unchanged
            assert (type.subIndicesAreValid(entry, editorSrc));
            assert (type.selfIndexIsValid(entry, editorSrc));

            // add the index mapping so we can update the bytecode later
            if (indexMap.containsKey(index)) {
                throw new Error("Entry at index " + index + " already copied!");
            }
            indexMap.put(index, newIndex);
        }
    }

    // make a new bytecode
    Bytecode newBytecode = new Bytecode(dest, bytecode.getMaxStack(), bytecode.getMaxLocals());
    bytecode.setStackDepth(bytecode.getStackDepth());
    setBytecode(newBytecode, bytecode.get());
    setExceptionTable(newBytecode, bytecode.getExceptionTable());

    // apply the mappings to the bytecode
    BytecodeIndexIterator iter = new BytecodeIndexIterator(newBytecode);
    for (BytecodeIndexIterator.Index index : iter.indices()) {
        int oldIndex = index.getIndex();
        Integer newIndex = indexMap.get(oldIndex);
        if (newIndex != null) {
            // make sure this mapping makes sense
            InfoType typeSrc = editorSrc.getItem(oldIndex).getType();
            InfoType typeDest = editorDest.getItem(newIndex).getType();
            assert (typeSrc == typeDest);

            // apply the mapping
            index.setIndex(newIndex);
        }
    }
    iter.saveChangesToBytecode();

    // make sure all the indices are valid
    iter = new BytecodeIndexIterator(newBytecode);
    for (BytecodeIndexIterator.Index index : iter.indices()) {
        assert (index.isValid(newBytecode));
    }

    return newBytecode;
}

From source file:org.apache.mahout.utils.vectors.lucene.LuceneIterator.java

/**
 * @param indexReader {@link IndexReader} to read the documents from.
 * @param idField    field containing the id. May be null.
 * @param field      field to use for the Vector
 * @param termInfo   termInfo// www.  j ava2  s .co m
 * @param weight     weight
 * @param normPower  the normalization value. Must be non-negative, or {@link LuceneIterable#NO_NORMALIZING}
 * @param maxPercentErrorDocs most documents that will be tolerated without a term freq vector. In [0,1].
 * @see #LuceneIterator(org.apache.lucene.index.IndexReader, String, String, org.apache.mahout.utils.vectors.TermInfo,
 * org.apache.mahout.vectorizer.Weight, double)
 */
public LuceneIterator(IndexReader indexReader, String idField, String field, TermInfo termInfo, Weight weight,
        double normPower, double maxPercentErrorDocs) {
    super(termInfo, normPower, indexReader, weight, maxPercentErrorDocs, field);
    // term docs(null) is a better way of iterating all the docs in Lucene
    Preconditions.checkArgument(normPower == LuceneIterable.NO_NORMALIZING || normPower >= 0,
            "normPower must be non-negative or -1, but normPower = " + normPower);
    Preconditions.checkArgument(maxPercentErrorDocs >= 0.0 && maxPercentErrorDocs <= 1.0,
            "Must be: 0.0 <= maxPercentErrorDocs <= 1.0");
    this.idField = idField;
    if (idField != null) {
        idFieldSelector = Sets.newTreeSet();
        idFieldSelector.add(idField);
    } else {
        /*The field in the index  containing the index. If null, then the Lucene internal doc id is used
        which is prone to error if the underlying index changes*/
        idFieldSelector = null;
    }
}

From source file:com.yahoo.pulsar.admin.cli.CliCommand.java

Set<AuthAction> getAuthActions(List<String> actions) {
    Set<AuthAction> res = Sets.newTreeSet();
    for (String action : actions) {
        res.add(AuthAction.valueOf(action));
    }/*from   w w  w .j a v a2s .c  o m*/

    return res;
}

From source file:blackboard.plugin.hayabusa.provider.UserManagerProvider.java

@Override
public Iterable<Command> getCommands() {
    try {/*  ww w.j a va 2  s . co m*/
        // TODO wire these dependencies as fields/constructor inject
        NavigationItemDbLoader niLoader = NavigationItemDbLoader.Default.getInstance();
        ModuleDbLoader moduleLoader = ModuleDbLoader.Default.getInstance();
        Module module = moduleLoader.loadByExtRef("platform/admin-users");

        NavigationItemControl family = NavigationItemControl
                .createInstance(niLoader.loadByInternalHandle(INTERNAL_HANDLER));

        // For admin
        List<NavigationItemControl> userAdminNics = getUserAdminNics();
        Set<Command> commands = Sets.newTreeSet();

        for (NavigationItemControl nic : userAdminNics) {
            if (!nic.userHasAccess()) {
                continue;
            }
            String title = String.format("%s - %s: %s", module.getTitle(), family.getLabel(), nic.getLabel());
            String url = processUri(nic);
            url = FramesetUtil.getTabGroupUrl(blackboard.data.navigation.Tab.TabType.admin, url);
            commands.add(new SimpleCommand(title, url, Category.SYSTEM_ADMIN));
        }

        List<NavigationItemControl> personalEditNics = getPersonalEditNics();

        for (NavigationItemControl nic : personalEditNics) {
            if (!nic.userHasAccess()) {
                continue;
            }
            String title = String.format("%s: %s", family.getLabel(), nic.getLabel());
            String uri = processUri(nic);
            uri = FramesetUtil.getTabGroupUrl(blackboard.data.navigation.Tab.TabType.my_institution, uri);
            commands.add(new SimpleCommand(title, uri, Category.USER));
        }
        return commands;
    } catch (PersistenceException e) {
        throw new PersistenceRuntimeException(e);
    }
}

From source file:org.spdx.rdfparser.VerificationCodeGenerator.java

/**
 * Generate the SPDX Package Verification Code from a directory of files included in the archive
 * @param sourceDirectory//from   ww w  . j ava 2  s.c o  m
 * @return
 * @throws NoSuchAlgorithmException 
 * @throws IOException 
 */
public SpdxPackageVerificationCode generatePackageVerificationCode(File sourceDirectory, File[] skippedFiles)
        throws NoSuchAlgorithmException, IOException {
    // create a sorted list of file paths
    Set<String> skippedFilesPath = Sets.newTreeSet();
    String rootOfDirectory = sourceDirectory.getAbsolutePath();
    int rootLen = rootOfDirectory.length() + 1;
    for (int i = 0; i < skippedFiles.length; i++) {
        String skippedPath = normalizeFilePath(skippedFiles[i].getAbsolutePath().substring(rootLen));
        skippedFilesPath.add(skippedPath);
    }
    List<String> fileChecksums = Lists.newArrayList();
    collectFileData(rootOfDirectory, sourceDirectory, fileChecksums, skippedFilesPath);
    String[] skippedFileNames = new String[skippedFilesPath.size()];
    Iterator<String> iter = skippedFilesPath.iterator();
    int i = 0;
    while (iter.hasNext()) {
        skippedFileNames[i++] = iter.next();
    }
    return generatePackageVerificationCode(fileChecksums, skippedFileNames);
}

From source file:org.locationtech.geogig.porcelain.CheckoutOp.java

public CheckoutOp() {
    paths = Sets.newTreeSet();
}