Example usage for com.google.common.collect ImmutableSortedMap copyOf

List of usage examples for com.google.common.collect ImmutableSortedMap copyOf

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableSortedMap copyOf.

Prototype

public static <K, V> ImmutableSortedMap<K, V> copyOf(
            Iterable<? extends Entry<? extends K, ? extends V>> entries, Comparator<? super K> comparator) 

Source Link

Usage

From source file:com.b2international.snowowl.datastore.server.history.HistoryInfoProvider.java

private List<IHistoryInfo> getHistoryInfo(final InternalHistoryInfoConfiguration configuration,
        final long timeout) throws SnowowlServiceException, SQLException {

    final long id = configuration.getStorageKey();

    if (!checkId(id)) {
        return ImmutableList.of();
    }//from   w w w  .  j a va 2 s  . c o  m

    final long startTime = System.currentTimeMillis();
    final CDOID cdoId = CDOIDUtil.createLong(id);

    try {

        final CDOView view = configuration.getView();
        final CDOBranch branch = view.getBranch();

        // If the object has been deleted return with DetachedHistoryInfo
        //XXX consider using com.b2international.snowowl.datastore.server.CDOServerUtils.getObjectRevisions(CDOBranchPoint, CDOID, int)
        if (view.getRevision(cdoId) == null) {
            return Collections.<IHistoryInfo>singletonList(new DetachedHistoryInfo(branch, cdoId));
        }

        final Stack<HistoryInfo> infos = new Stack<HistoryInfo>();
        final Map<Long, IVersion<CDOID>> query;

        // Try to find details for most recent commits first
        final HistoryInfoQueryExecutor executor = HistoryInfoQueryExecutorProvider.INSTANCE
                .getExecutor(configuration.getTerminologyComponentId());
        final Map<Long, IVersion<CDOID>> entries = executor.execute(configuration);

        query = ImmutableSortedMap.copyOf(entries, Ordering.natural().reverse());

        for (final Entry<Long, IVersion<CDOID>> entry : query.entrySet()) {
            final HistoryInfo historyInfo = createHistoryInfo(startTime, configuration, entry, timeout);

            // Ignore empty history infos, but add incomplete ones
            if (historyInfo.isIncomplete() || !historyInfo.getDetails().isEmpty()) {

                if (infos.empty()) {

                    infos.push(historyInfo);

                } else {

                    //try merge
                    final HistoryInfo previousItem = infos.pop();

                    final boolean success = previousItem.group(historyInfo);
                    infos.push(previousItem);

                    if (!success) {
                        infos.push(historyInfo);
                    }

                }

            }
        }

        int nextMinorVersion = 1;
        int nextMajorVersion = 1;

        final List<IHistoryInfo> $ = Lists.newArrayList();

        // Renumber remaining versions, process in chronological order
        while (!infos.isEmpty()) {

            final HistoryInfo info = infos.pop();
            final Version version = (Version) info.getVersion();

            if (version.representsMajorChange()) {
                version.setMajorVersion(nextMajorVersion);

                nextMajorVersion++;
                nextMinorVersion = 1;

            } else {

                // Use the previous major version when renumbering minor versions
                version.setMajorVersion(nextMajorVersion - 1);
                version.setMinorVersion(nextMinorVersion);

                nextMinorVersion++;
            }

            $.add(info);
        }

        return $;

    } catch (final OperationCanceledException e) {
        return emptyList();
    } finally {
        new NullProgressMonitor().done();
    }
}

From source file:edu.buaa.satla.analysis.core.counterexample.Model.java

@Override
public void appendTo(Appendable output) throws IOException {
    Map<AssignableTerm, Object> sorted = ImmutableSortedMap.copyOf(mModel, Ordering.usingToString());
    joiner.appendTo(output, sorted);/*  w  ww . j  a  v  a 2 s. c  om*/
}

From source file:uk.org.rbc1b.roms.controller.volunteer.VolunteersController.java

/**
 * @return reference map for all skills.
 *//*from   w  w  w .  j a  v a  2s .  c om*/
private Map<Integer, DepartmentSkillNameModel> findSkills() {

    List<Department> departments = departmentDao.findDepartments();
    Map<Integer, String> departmentNames = new HashMap<Integer, String>();
    for (Department department : departments) {
        departmentNames.put(department.getDepartmentId(), department.getName());
    }

    List<Skill> skills = skillDao.findSkills(new SkillSearchCriteria());
    Map<Integer, DepartmentSkillNameModel> skillNames = new HashMap<Integer, DepartmentSkillNameModel>(
            skills.size());
    for (Skill skill : skills) {
        String departmentName = departmentNames.get(skill.getDepartment().getDepartmentId());

        skillNames.put(skill.getSkillId(), new DepartmentSkillNameModel(departmentName, skill.getName()));
    }

    // return the map, sorted by the value (department + skill name)
    return ImmutableSortedMap.copyOf(skillNames, Ordering.natural().onResultOf(Functions.forMap(skillNames)));
}

From source file:com.google.devtools.build.lib.analysis.config.BuildConfiguration.java

/**
 * Constructs a new BuildConfiguration instance.
 *//*from   w w w  .j  a va 2 s.  co m*/
public BuildConfiguration(BlazeDirectories directories, Map<Class<? extends Fragment>, Fragment> fragmentsMap,
        BuildOptions buildOptions, boolean actionsDisabled) {
    this.directories = directories;
    this.actionsEnabled = !actionsDisabled;
    this.fragments = ImmutableSortedMap.copyOf(fragmentsMap, lexicalFragmentSorter);

    this.skylarkVisibleFragments = buildIndexOfSkylarkVisibleFragments();

    this.buildOptions = buildOptions;
    this.options = buildOptions.get(Options.class);

    Map<String, String> testEnv = new TreeMap<>();
    for (Map.Entry<String, String> entry : this.options.testEnvironment) {
        if (entry.getValue() != null) {
            testEnv.put(entry.getKey(), entry.getValue());
        }
    }

    this.testEnvironment = ImmutableMap.copyOf(testEnv);

    // We can't use an ImmutableMap.Builder here; we need the ability to add entries with keys that
    // are already in the map so that the same define can be specified on the command line twice,
    // and ImmutableMap.Builder does not support that.
    Map<String, String> commandLineDefinesBuilder = new TreeMap<>();
    for (Map.Entry<String, String> define : options.commandLineBuildVariables) {
        commandLineDefinesBuilder.put(define.getKey(), define.getValue());
    }
    commandLineBuildVariables = ImmutableMap.copyOf(commandLineDefinesBuilder);

    this.mnemonic = buildMnemonic();
    this.outputDirName = (options.outputDirectoryName != null) ? options.outputDirectoryName : mnemonic;
    this.platformName = buildPlatformName();

    this.shellExecutable = computeShellExecutable();

    Pair<ImmutableMap<String, String>, ImmutableSet<String>> shellEnvironment = setupShellEnvironment();
    this.localShellEnvironment = shellEnvironment.getFirst();
    this.envVariables = shellEnvironment.getSecond();

    this.transitiveOptionsMap = computeOptionsMap(buildOptions, fragments.values());

    ImmutableMap.Builder<String, String> globalMakeEnvBuilder = ImmutableMap.builder();
    for (Fragment fragment : fragments.values()) {
        fragment.addGlobalMakeVariables(globalMakeEnvBuilder);
    }

    globalMakeEnvBuilder.put("COMPILATION_MODE", options.compilationMode.toString());
    /*
     * Attention! Document these in the build-encyclopedia
     */
    // the bin directory and the genfiles directory
    // These variables will be used on Windows as well, so we need to make sure
    // that paths use the correct system file-separator.
    globalMakeEnvBuilder.put("BINDIR", getBinDirectory().getExecPath().getPathString());
    globalMakeEnvBuilder.put("GENDIR", getGenfilesDirectory().getExecPath().getPathString());
    globalMakeEnv = globalMakeEnvBuilder.build();

    checksum = Fingerprint.md5Digest(buildOptions.computeCacheKey());
    hashCode = computeHashCode();
}