Example usage for com.google.common.collect Maps asMap

List of usage examples for com.google.common.collect Maps asMap

Introduction

In this page you can find the example usage for com.google.common.collect Maps asMap.

Prototype

@GwtIncompatible("NavigableMap")
public static <K, V> NavigableMap<K, V> asMap(NavigableSet<K> set, Function<? super K, V> function) 

Source Link

Document

Returns a view of the navigable set as a map, mapping keys from the set according to the specified function.

Usage

From source file:de.bund.bfr.knime.nls.chart.ChartConfigPanel.java

public void setParamValues(Map<String, Double> values, Map<String, Double> minValues,
        Map<String, Double> maxValues) {
    if (outerParameterPanel != null) {
        outerParameterPanel.removeAll();
        parameterPanel = new VariablePanel(
                Maps.asMap(parameterPanel.getValues().keySet(), Functions.constant(new ArrayList<>())),
                minValues, maxValues, false, true, true);
        parameterPanel.setValues(values);
        parameterPanel.addValueListener(e -> fireConfigChanged());
        outerParameterPanel.add(parameterPanel, BorderLayout.WEST);

        Container container = getParent();

        while (container != null) {
            if (container instanceof JPanel) {
                ((JPanel) container).revalidate();
                break;
            }/*from www.jav  a  2s  .c o m*/

            container = container.getParent();
        }
    }
}

From source file:de.bund.bfr.knime.nls.chart.ChartConfigPanel.java

public void setVariableValues(Map<String, Double> values, Map<String, Double> minValues,
        Map<String, Double> maxValues) {
    if (outerVariablePanel != null) {
        outerVariablePanel.removeAll();//from  ww  w . jav  a  2s.  c  o m
        variablePanel = new VariablePanel(
                Maps.asMap(variablePanel.getValues().keySet(), Functions.constant(new ArrayList<>())),
                minValues, maxValues, false, true, true);
        variablePanel.setValues(values);
        variablePanel.setEnabled(getVarX(), false);
        variablePanel.addValueListener(e -> fireConfigChanged());
        outerVariablePanel.add(variablePanel, BorderLayout.WEST);

        Container container = getParent();

        while (container != null) {
            if (container instanceof JPanel) {
                ((JPanel) container).revalidate();
                break;
            }

            container = container.getParent();
        }
    }
}

From source file:com.android.build.gradle.tasks.PackageAndroidArtifact.java

/**
 * Obtains all changed inputs of a given input set. Given a set of files mapped to their
 * changed status, this method returns a list of changes computed as follows:
 *
 * <ol>/*from w w w.  jav  a2 s .co m*/
 *     <li>Changed inputs are split into deleted and non-deleted inputs. This separation is
 *     needed because deleted inputs may no longer be mappable to any {@link InputSet} just
 *     by looking at the file path, without using {@link KnownFilesSaveData}.
 *     <li>Deleted inputs are filtered through {@link KnownFilesSaveData} to get only those
 *     whose input set matches {@code inputSet}.
 *     <li>Non-deleted inputs are processed through
 *     {@link IncrementalRelativeFileSets#makeFromBaseFiles(Collection, Map, FileCacheByPath)}
 *     to obtain the incremental file changes.
 *     <li>The results of processed deleted and non-deleted are merged and returned.
 * </ol>
 *
 * @param changedInputs all changed inputs
 * @param saveData the save data with all input sets from last run
 * @param inputSet the input set to filter
 * @param baseFiles the base files of the input set
 * @param cacheByPath where to cache files
 * @return the status of all relative files in the input set
 */
@NonNull
private ImmutableMap<RelativeFile, FileStatus> getChangedInputs(@NonNull Map<File, FileStatus> changedInputs,
        @NonNull KnownFilesSaveData saveData, @NonNull InputSet inputSet, @NonNull Collection<File> baseFiles,
        @NonNull FileCacheByPath cacheByPath) throws IOException {

    /*
     * Figure out changes to deleted files.
     */
    Set<File> deletedFiles = Maps.filterValues(changedInputs, Predicates.equalTo(FileStatus.REMOVED)).keySet();
    Set<RelativeFile> deletedRelativeFiles = saveData.find(deletedFiles, inputSet);

    /*
     * Figure out changes to non-deleted files.
     */
    Map<File, FileStatus> nonDeletedFiles = Maps.filterValues(changedInputs,
            Predicates.not(Predicates.equalTo(FileStatus.REMOVED)));
    Map<RelativeFile, FileStatus> nonDeletedRelativeFiles = IncrementalRelativeFileSets
            .makeFromBaseFiles(baseFiles, nonDeletedFiles, cacheByPath);

    /*
     * Merge everything.
     */
    return new ImmutableMap.Builder<RelativeFile, FileStatus>()
            .putAll(Maps.asMap(deletedRelativeFiles, Functions.constant(FileStatus.REMOVED)))
            .putAll(nonDeletedRelativeFiles).build();
}

From source file:com.android.builder.core.AtlasBuilder.java

@Deprecated
public void oldPackageApk(@NonNull String androidResPkgLocation, @NonNull Set<File> dexFolders,
        @NonNull Collection<File> javaResourcesLocations, @NonNull Collection<File> jniLibsLocations,
        @Nullable File assetsFolder, @NonNull Set<String> abiFilters, boolean jniDebugBuild,
        @Nullable SigningConfig signingConfig, @NonNull File outApkLocation, int minSdkVersion,
        @NonNull Predicate<String> noCompressPredicate)
        throws KeytoolException, PackagerException, SigningException, IOException {
    checkNotNull(androidResPkgLocation, "androidResPkgLocation cannot be null.");
    checkNotNull(outApkLocation, "outApkLocation cannot be null.");

    /*/*from   w  ww . j  a v a2 s .c om*/
     * This is because this method is not supposed be be called in an incremental build. So, if
     * an out APK already exists, we delete it.
     */
    if (outApkLocation.exists()) {
        FileUtils.forceDelete(outApkLocation);
    }

    Map<RelativeFile, FileStatus> javaResourceMods = Maps.newHashMap();
    Map<File, FileStatus> javaResourceArchiveMods = Maps.newHashMap();
    for (File resourceLocation : javaResourcesLocations) {
        if (resourceLocation.isFile()) {
            javaResourceArchiveMods.put(resourceLocation, FileStatus.NEW);
        } else {
            Set<RelativeFile> files = RelativeFiles.fromDirectory(resourceLocation,
                    new java.util.function.Predicate<RelativeFile>() {
                        @Override
                        public boolean test(RelativeFile relativeFile) {
                            return relativeFile.getFile().isFile();
                        }
                    });
            javaResourceMods.putAll(Maps.asMap(files, Functions.constant(FileStatus.NEW)));
        }
    }

    NativeLibraryAbiPredicate nativeLibraryPredicate = new NativeLibraryAbiPredicate(abiFilters, jniDebugBuild);
    Map<RelativeFile, FileStatus> jniMods = Maps.newHashMap();
    Map<File, FileStatus> jniArchiveMods = Maps.newHashMap();
    for (File jniLoc : jniLibsLocations) {
        if (jniLoc.isFile()) {
            jniArchiveMods.put(jniLoc, FileStatus.NEW);
        } else {
            Set<RelativeFile> files = RelativeFiles.fromDirectory(jniLoc,
                    RelativeFiles.fromPathPredicate(nativeLibraryPredicate));
            jniMods.putAll(Maps.asMap(files, Functions.constant(FileStatus.NEW)));
        }
    }

    Set<RelativeFile> assets = assetsFolder == null ? Collections.emptySet()
            : RelativeFiles.fromDirectory(assetsFolder, new java.util.function.Predicate<RelativeFile>() {
                @Override
                public boolean test(RelativeFile relativeFile) {
                    return relativeFile.getFile().isFile();
                }
            });

    PrivateKey key = null;
    X509Certificate certificate = null;
    boolean v1SigningEnabled = false;
    boolean v2SigningEnabled = false;

    ApkCreatorFactory.CreationData creationData = new ApkCreatorFactory.CreationData(outApkLocation, key,
            certificate, v1SigningEnabled, v2SigningEnabled, null, // BuiltBy
            "atlas", minSdkVersion, NativeLibrariesPackagingMode.COMPRESSED, noCompressPredicate::apply);
    try (OldPackager packager = new OldPackager(creationData, androidResPkgLocation,
            LoggerWrapper.getLogger(AtlasBuilder.class))) {
        // add dex folder to the apk root.
        if (!dexFolders.isEmpty()) {
            packager.addDexFiles(dexFolders);
        }

        // add the output of the java resource merger
        for (Map.Entry<RelativeFile, FileStatus> resourceUpdate : javaResourceMods.entrySet()) {
            packager.updateResource(resourceUpdate.getKey(), resourceUpdate.getValue());
        }

        for (Map.Entry<File, FileStatus> resourceArchiveUpdate : javaResourceArchiveMods.entrySet()) {
            packager.updateResourceArchive(resourceArchiveUpdate.getKey(), resourceArchiveUpdate.getValue(),
                    new java.util.function.Predicate<String>() {
                        @Override
                        public boolean test(String s) {
                            return false;
                        }
                    });
        }

        for (Map.Entry<RelativeFile, FileStatus> jniLibUpdates : jniMods.entrySet()) {
            packager.updateResource(jniLibUpdates.getKey(), jniLibUpdates.getValue());
        }

        for (Map.Entry<File, FileStatus> resourceArchiveUpdate : jniArchiveMods.entrySet()) {
            packager.updateResourceArchive(resourceArchiveUpdate.getKey(), resourceArchiveUpdate.getValue(),
                    new java.util.function.Predicate<String>() {
                        @Override
                        public boolean test(String s) {
                            return nativeLibraryPredicate.test(s);
                        }
                    });
        }

        for (RelativeFile asset : assets) {
            packager.addFile(asset.getFile(),
                    SdkConstants.FD_ASSETS + "/" + asset.getOsIndependentRelativePath());
        }
    }
}

From source file:com.microsoft.azure.management.appservice.implementation.WebAppBaseImpl.java

@Override
@SuppressWarnings("unchecked")
public FluentImplT withStickyAppSettings(Map<String, String> settings) {
    withAppSettings(settings);/*from  w w  w  . j ava 2s  . c  om*/
    appSettingStickiness.putAll(Maps.asMap(settings.keySet(), new Function<String, Boolean>() {
        @Override
        public Boolean apply(String input) {
            return true;
        }
    }));
    return (FluentImplT) this;
}

From source file:com.palantir.atlasdb.transaction.impl.SnapshotTransaction.java

protected void throwIfWriteAlreadyCommitted(String tableName, Map<Cell, byte[]> writes,
        ConflictHandler conflictHandler, LockRefreshToken commitLocksToken,
        TransactionService transactionService) throws TransactionConflictException {
    if (writes.isEmpty() || conflictHandler == ConflictHandler.IGNORE_ALL) {
        return;//w ww.  j a  v a2  s  .c  o  m
    }
    Set<CellConflict> spanningWrites = Sets.newHashSet();
    Set<CellConflict> dominatingWrites = Sets.newHashSet();
    Map<Cell, Long> keysToLoad = Maps.asMap(writes.keySet(), Functions.constant(Long.MAX_VALUE));
    while (!keysToLoad.isEmpty()) {
        keysToLoad = detectWriteAlreadyCommittedInternal(tableName, keysToLoad, spanningWrites,
                dominatingWrites, transactionService);
    }

    if (conflictHandler == ConflictHandler.RETRY_ON_VALUE_CHANGED) {
        throwIfValueChangedConflict(tableName, writes, spanningWrites, dominatingWrites, commitLocksToken);
    } else if (conflictHandler == ConflictHandler.RETRY_ON_WRITE_WRITE
            || conflictHandler == ConflictHandler.RETRY_ON_WRITE_WRITE_CELL
            || conflictHandler == ConflictHandler.SERIALIZABLE) {
        if (!spanningWrites.isEmpty() || !dominatingWrites.isEmpty()) {
            throw TransactionConflictException.create(tableName, getStartTimestamp(), spanningWrites,
                    dominatingWrites, System.currentTimeMillis() - timeCreated);
        }
    } else {
        throw new IllegalArgumentException("Unknown conflictHandler type: " + conflictHandler);
    }
}