List of usage examples for com.google.common.collect ImmutableMap keySet
public ImmutableSet<K> keySet()
From source file:com.facebook.buck.io.PathListing.java
/** * Lists paths in descending modified time order, * excluding any paths which bring the number of files over {@code maxNumPaths} * or over {@code totalSizeFilter} bytes in size. *///from ww w .j av a 2s.c om public static ImmutableSortedSet<Path> listMatchingPathsWithFilters(Path pathToGlob, String globPattern, PathModifiedTimeFetcher pathModifiedTimeFetcher, FilterMode filterMode, Optional<Integer> maxPathsFilter, Optional<Long> totalSizeFilter) throws IOException { // Fetch the modification time of each path and build a map of // (path => modification time) pairs. ImmutableMap.Builder<Path, FileTime> pathFileTimesBuilder = ImmutableMap.builder(); try (DirectoryStream<Path> stream = Files.newDirectoryStream(pathToGlob, globPattern)) { for (Path path : stream) { try { pathFileTimesBuilder.put(path, pathModifiedTimeFetcher.getLastModifiedTime(path)); } catch (NoSuchFileException e) { // Ignore the path. continue; } } } ImmutableMap<Path, FileTime> pathFileTimes = pathFileTimesBuilder.build(); ImmutableSortedSet<Path> paths = ImmutableSortedSet.copyOf(Ordering.natural() // Order the keys of the map (the paths) by their values (the file modification times). .onResultOf(Functions.forMap(pathFileTimes)) // If two keys of the map have the same value, fall back to key order. .compound(Ordering.natural()) // Use descending order. .reverse(), pathFileTimes.keySet()); paths = applyNumPathsFilter(paths, filterMode, maxPathsFilter); paths = applyTotalSizeFilter(paths, filterMode, totalSizeFilter); return paths; }
From source file:com.facebook.buck.io.file.PathListing.java
/** * Lists paths in descending modified time order, excluding any paths which bring the number of * files over {@code maxNumPaths} or over {@code totalSizeFilter} bytes in size. *///from w w w . j a v a2 s . c om public static ImmutableSortedSet<Path> listMatchingPathsWithFilters(Path pathToGlob, String globPattern, PathModifiedTimeFetcher pathModifiedTimeFetcher, FilterMode filterMode, OptionalInt maxPathsFilter, Optional<Long> totalSizeFilter) throws IOException { // Fetch the modification time of each path and build a map of // (path => modification time) pairs. ImmutableMap.Builder<Path, FileTime> pathFileTimesBuilder = ImmutableMap.builder(); try (DirectoryStream<Path> stream = Files.newDirectoryStream(pathToGlob, globPattern)) { for (Path path : stream) { try { pathFileTimesBuilder.put(path, pathModifiedTimeFetcher.getLastModifiedTime(path)); } catch (NoSuchFileException e) { // Ignore the path. continue; } } } ImmutableMap<Path, FileTime> pathFileTimes = pathFileTimesBuilder.build(); ImmutableSortedSet<Path> paths = ImmutableSortedSet.copyOf(Ordering.natural() // Order the keys of the map (the paths) by their values (the file modification // times). .onResultOf(Functions.forMap(pathFileTimes)) // If two keys of the map have the same value, fall back to key order. .compound(Ordering.natural()) // Use descending order. .reverse(), pathFileTimes.keySet()); paths = applyNumPathsFilter(paths, filterMode, maxPathsFilter); paths = applyTotalSizeFilter(paths, filterMode, totalSizeFilter); return paths; }
From source file:com.facebook.buck.rules.CellProvider.java
public static CellProvider createForDistributedBuild(ImmutableMap<Path, BuckConfig> cellConfigs, ImmutableMap<Path, ProjectFilesystem> cellFilesystems, KnownBuildRuleTypesFactory knownBuildRuleTypesFactory) { return new CellProvider(cellProvider -> new CacheLoader<Path, Cell>() { @Override//from www.j a v a 2 s . c o m public Cell load(Path cellPath) throws Exception { ProjectFilesystem cellFilesystem = Preconditions.checkNotNull(cellFilesystems.get(cellPath)); BuckConfig buckConfig = Preconditions.checkNotNull(cellConfigs.get(cellPath)); return new Cell(cellConfigs.keySet(), cellFilesystem, Watchman.NULL_WATCHMAN, buckConfig, knownBuildRuleTypesFactory, cellProvider); } }, null); }
From source file:com.facebook.buck.features.apple.project.SchemeGenerator.java
public static Element serializeEnvironmentVariables(Document doc, ImmutableMap<String, String> environmentVariables) { Element rootElement = doc.createElement("EnvironmentVariables"); for (String variableKey : environmentVariables.keySet()) { Element variableElement = doc.createElement("EnvironmentVariable"); variableElement.setAttribute("key", variableKey); variableElement.setAttribute("value", environmentVariables.get(variableKey)); variableElement.setAttribute("isEnabled", "YES"); rootElement.appendChild(variableElement); }/*from w w w . ja v a2 s. c o m*/ return rootElement; }
From source file:com.telefonica.iot.cygnus.management.StatsHandlers.java
/** * Handles GET /v1/stats.// w w w . j av a2s .c om * @param response * @param sources * @param channels * @param sinks * @throws IOException */ public static void get(HttpServletResponse response, ImmutableMap<String, SourceRunner> sources, ImmutableMap<String, Channel> channels, ImmutableMap<String, SinkRunner> sinks) throws IOException { response.setContentType("application/json; charset=utf-8"); response.setStatus(HttpServletResponse.SC_OK); String jsonStr = "{\"success\":\"true\",\"stats\":{\"sources\":["; boolean first = true; for (String key : sources.keySet()) { if (first) { first = false; } else { jsonStr += ","; } // if else Source source; HTTPSourceHandler handler; try { SourceRunner sr = sources.get(key); source = sr.getSource(); Field f = source.getClass().getDeclaredField("handler"); f.setAccessible(true); handler = (HTTPSourceHandler) f.get(source); } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) { LOGGER.error("There was a problem when getting a sink. Details: " + e.getMessage()); continue; } // try catch jsonStr += "{\"name\":\"" + source.getName() + "\"," + "\"status\":\"" + source.getLifecycleState().toString() + "\","; if (handler instanceof CygnusHandler) { CygnusHandler ch = (CygnusHandler) handler; jsonStr += "\"setup_time\":\"" + CommonUtils.getHumanReadable(ch.getBootTime(), true) + "\"," + "\"num_received_events\":" + ch.getNumReceivedEvents() + "," + "\"num_processed_events\":" + ch.getNumProcessedEvents() + "}"; } else { jsonStr += "\"setup_time\":\"unknown\"," + "\"num_received_events\":-1," + "\"num_processed_events\":-1}"; } // if else } // for jsonStr += "],\"channels\":["; first = true; for (String key : channels.keySet()) { if (first) { first = false; } else { jsonStr += ","; } // if else Channel channel = channels.get(key); jsonStr += "{\"name\":\"" + channel.getName() + "\"," + "\"status\":\"" + channel.getLifecycleState().toString() + "\","; if (channel instanceof CygnusChannel) { CygnusChannel cc = (CygnusChannel) channel; jsonStr += "\"setup_time\":\"" + CommonUtils.getHumanReadable(cc.getSetupTime(), true) + "\"," + "\"num_events\":" + cc.getNumEvents() + "," + "\"num_puts_ok\":" + cc.getNumPutsOK() + "," + "\"num_puts_failed\":" + cc.getNumPutsFail() + "," + "\"num_takes_ok\":" + cc.getNumTakesOK() + "," + "\"num_takes_failed\":" + cc.getNumTakesFail() + "}"; } else { jsonStr += "\"setup_time\":\"unknown\"," + "\"num_events\":-1," + "\"num_puts_ok\":-1," + "\"num_puts_failed\":-1," + "\"num_takes_ok\":-1," + "\"num_takes_failed\":-1}"; } // if else } // for jsonStr += "],\"sinks\":["; first = true; for (String key : sinks.keySet()) { if (first) { first = false; } else { jsonStr += ","; } // if else Sink sink; try { SinkRunner sr = sinks.get(key); SinkProcessor sp = sr.getPolicy(); Field f = sp.getClass().getDeclaredField("sink"); f.setAccessible(true); sink = (Sink) f.get(sp); } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) { LOGGER.error("There was a problem when getting a sink. Details: " + e.getMessage()); continue; } // try catch jsonStr += "{\"name\":\"" + sink.getName() + "\"," + "\"status\":\"" + sink.getLifecycleState().toString() + "\","; if (sink instanceof CygnusSink) { CygnusSink cs = (CygnusSink) sink; jsonStr += "\"setup_time\":\"" + CommonUtils.getHumanReadable(cs.getSetupTime(), true) + "\"," + "\"num_processed_events\":" + cs.getNumProcessedEvents() + "," + "\"num_persisted_events\":" + cs.getNumPersistedEvents() + "}"; } else { jsonStr += "\"setup_time\":\"unknown\"," + "\"num_processed_events\":-1," + "\"num_persisted_events\":-1}"; } // if else } // for jsonStr += "]}}"; response.getWriter().println(jsonStr); }
From source file:com.google.auto.value.processor.AutoAnnotationProcessor.java
/** * Returns a map from the names of members with invariable hashCodes to the values of those * hashCodes./* w w w . jav a2 s . c o m*/ */ private static ImmutableMap<String, Integer> invariableHashes(ImmutableMap<String, Member> members, ImmutableSet<String> parameters) { ImmutableMap.Builder<String, Integer> builder = ImmutableMap.builder(); for (String element : members.keySet()) { if (!parameters.contains(element)) { Member member = members.get(element); AnnotationValue annotationValue = member.method.getDefaultValue(); Optional<Integer> invariableHash = invariableHash(annotationValue); if (invariableHash.isPresent()) { builder.put(element, (element.hashCode() * 127) ^ invariableHash.get()); } } } return builder.build(); }
From source file:com.google.api.codegen.InterfaceConfig.java
/** * Creates an instance of InterfaceConfig based on ConfigProto, linking up method configurations * with specified methods in methodConfigMap. On errors, null will be returned, and diagnostics * are reported to the model./*from w w w . j a va2s. c om*/ */ @Nullable public static InterfaceConfig createInterfaceConfig(DiagCollector diagCollector, InterfaceConfigProto interfaceConfigProto, Interface iface) { ImmutableMap<String, CollectionConfig> collectionConfigs = createCollectionConfigs(diagCollector, interfaceConfigProto); ImmutableMap<String, ImmutableSet<Status.Code>> retryCodesDefinition = createRetryCodesDefinition( diagCollector, interfaceConfigProto); ImmutableMap<String, RetrySettings> retrySettingsDefinition = createRetrySettingsDefinition(diagCollector, interfaceConfigProto); ImmutableMap<String, MethodConfig> methodConfigMap = null; if (retryCodesDefinition != null && retrySettingsDefinition != null) { methodConfigMap = createMethodConfigMap(diagCollector, interfaceConfigProto, iface, retryCodesDefinition.keySet(), retrySettingsDefinition.keySet()); } if (collectionConfigs == null || methodConfigMap == null) { return null; } else { return new InterfaceConfig(collectionConfigs, methodConfigMap, retryCodesDefinition, retrySettingsDefinition); } }
From source file:com.palantir.common.concurrent.ExecutorInheritableThreadLocal.java
/** * @return the old map installed on that thread *///from w w w .j a v a 2 s.c o m static ConcurrentMap<ExecutorInheritableThreadLocal<?>, Object> installMapOnThread( ImmutableMap<ExecutorInheritableThreadLocal<?>, Object> map) { ConcurrentMap<ExecutorInheritableThreadLocal<?>, Object> oldMap = mapForThisThread.get(); if (map.isEmpty()) { mapForThisThread.remove(); } else { ConcurrentMap<ExecutorInheritableThreadLocal<?>, Object> newMap = makeNewMap(); newMap.putAll(map); // Install the map in case callInstallOnChildThread makes use // of existing thread locals (UserSessionClientInfo does this). mapForThisThread.set(newMap); for (ExecutorInheritableThreadLocal<?> e : map.keySet()) { @SuppressWarnings("unchecked") ExecutorInheritableThreadLocal<Object> eitl = (ExecutorInheritableThreadLocal<Object>) e; eitl.set(eitl.callInstallOnChildThread(eitl.get())); } } return oldMap; }
From source file:com.github.rinde.rinsim.central.Solvers.java
static GlobalStateObject convert(PDPRoadModel rm, PDPModel pm, Collection<Vehicle> vehicles, Set<Parcel> availableParcels, Measure<Long, Duration> time, Optional<ImmutableList<ImmutableList<Parcel>>> currentRoutes, boolean fixRoutes) { final ImmutableMap.Builder<VehicleStateObject, Vehicle> vbuilder = ImmutableMap.builder(); @Nullable//from w w w. jav a 2 s.co m Iterator<ImmutableList<Parcel>> routeIterator = null; if (currentRoutes.isPresent()) { checkArgument(currentRoutes.get().size() == vehicles.size(), "The number of routes (%s) must equal the number of vehicles (%s).", currentRoutes.get().size(), vehicles.size()); routeIterator = currentRoutes.get().iterator(); } final ImmutableSet.Builder<Parcel> availableDestParcels = ImmutableSet.builder(); for (final Vehicle v : vehicles) { final ImmutableSet<Parcel> contentsMap = ImmutableSet.copyOf(pm.getContents(v)); @Nullable ImmutableList<Parcel> route = null; if (routeIterator != null) { route = routeIterator.next(); } final VehicleStateObject vehicleState = convertToVehicleState(rm, pm, v, contentsMap, route, availableDestParcels); vbuilder.put(vehicleState, v); } final ImmutableSet<Parcel> availableDestMap = availableDestParcels.build(); final Set<Parcel> toAdd = Sets.difference(availableParcels, availableDestMap); final ImmutableSet<Parcel> availableParcelsKeys = ImmutableSet.<Parcel>builder().addAll(availableParcels) .addAll(toAdd).build(); final ImmutableMap<VehicleStateObject, Vehicle> vehicleMap = vbuilder.build(); GlobalStateObject gso = GlobalStateObject.create(availableParcelsKeys, vehicleMap.keySet().asList(), time.getValue().longValue(), time.getUnit(), rm.getSpeedUnit(), rm.getDistanceUnit()); if (fixRoutes) { gso = fixRoutes(gso); } return gso; }
From source file:dollar.api.types.DollarFactory.java
@Nullable private static Object mapToJsonInternal(@NotNull Value value) { final JsonObject json = new JsonObject(); ImmutableMap<Value, Value> map = value.toVarMap(); final Set<Value> fieldNames = map.keySet(); for (Value fieldName : fieldNames) { Value v = map.get(fieldName);/*from ww w. j a v a 2 s .c o m*/ json.putValue(fieldName.toString(), toJson(v)); } return json; }