Example usage for com.google.common.collect ImmutableMap put

List of usage examples for com.google.common.collect ImmutableMap put

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableMap put.

Prototype

public final V put(K k, V v) 

Source Link

Usage

From source file:com.spectralogic.dsbrowser.gui.util.ParseJobInterruptionMap.java

public static void saveValuesToFiles(final JobInterruptionStore jobInterruptionStore,
        final Map<String, Path> filesMap, final Map<String, Path> foldersMap, final String endpoint,
        final UUID jobId, final long totalJobSize, final String targetLocation,
        final DateTimeUtils dateTimeUtils, final String jobType, final String bucket) {
    if (jobInterruptionStore != null && jobInterruptionStore.getJobIdsModel() != null) {
        final ObservableList<Map<String, Map<String, FilesAndFolderMap>>> completeArrayList = FXCollections
                .observableArrayList(jobInterruptionStore.getJobIdsModel().getEndpoints());
        final boolean isNonAdjacent = !(Guard.isMapNullOrEmpty(filesMap) || Guard.isMapNullOrEmpty(foldersMap));

        final FilesAndFolderMap filesAndFolderMap = new FilesAndFolderMap(filesMap, foldersMap, jobType,
                dateTimeUtils.nowAsString(), isNonAdjacent, targetLocation, totalJobSize, bucket);
        if (!Guard.isNullOrEmpty(completeArrayList)
                && completeArrayList.stream().anyMatch(i -> i.containsKey(endpoint))) {

            final Optional<Map<String, Map<String, FilesAndFolderMap>>> first = completeArrayList.stream()
                    .filter(i -> i.containsKey(endpoint)).findFirst();

            if (first.isPresent()) {
                final Map<String, Map<String, FilesAndFolderMap>> endpointsMap = first.get();

                if (!Guard.isMapNullOrEmpty(endpointsMap) && endpointsMap.containsKey(endpoint)) {
                    final Map<String, FilesAndFolderMap> jobIdImmutableMap = endpointsMap.get(endpoint);
                    jobIdImmutableMap.put(jobId.toString(), filesAndFolderMap);
                } else {
                    final ImmutableMap<String, FilesAndFolderMap> jobIdHashMap = ImmutableMap
                            .of(jobId.toString(), filesAndFolderMap);
                    endpointsMap.put(endpoint, jobIdHashMap);
                }// w  w w .ja v  a2s. co  m
                jobInterruptionStore.getJobIdsModel().setEndpoints(completeArrayList);
            }
        } else {
            final Map<String, Map<String, FilesAndFolderMap>> endpointsHashMap = new HashMap<>();
            final Map<String, FilesAndFolderMap> jobIdHashMap = new HashMap<>();
            jobIdHashMap.put(jobId.toString(), filesAndFolderMap);
            endpointsHashMap.put(endpoint, jobIdHashMap);
            completeArrayList.add(endpointsHashMap);
            jobInterruptionStore.getJobIdsModel().setEndpoints(completeArrayList);
            LOG.info("No entry found");
        }
        try {
            JobInterruptionStore.saveJobInterruptionStore(jobInterruptionStore);
        } catch (final IOException e) {
            LOG.error("Failed to save job ids", e);
        }
    }
}