@Override
      public Map<Symbol, Symbol> visitProject(ProjectNode node, Set<Symbol> lookupSymbols) {
        // Map from output Symbols to source Symbols
        Map<Symbol, Symbol> directSymbolTranslationOutputMap =
            Maps.transformValues(
                Maps.filterValues(node.getAssignments(), SymbolReference.class::isInstance),
                Symbol::from);
        Map<Symbol, Symbol> outputToSourceMap =
            lookupSymbols
                .stream()
                .filter(directSymbolTranslationOutputMap.keySet()::contains)
                .collect(toImmutableMap(identity(), directSymbolTranslationOutputMap::get));

        checkState(
            !outputToSourceMap.isEmpty(),
            "No lookup symbols were able to pass through the projection");

        // Map from source Symbols to underlying index source Symbols
        Map<Symbol, Symbol> sourceToIndexMap =
            node.getSource().accept(this, ImmutableSet.copyOf(outputToSourceMap.values()));

        // Generate the Map the connects lookup symbols to underlying index source symbols
        Map<Symbol, Symbol> outputToIndexMap =
            Maps.transformValues(
                Maps.filterValues(outputToSourceMap, in(sourceToIndexMap.keySet())),
                Functions.forMap(sourceToIndexMap));
        return ImmutableMap.copyOf(outputToIndexMap);
      }
  public Object apply(Object result) {
    if (result instanceof Collection<?>) {
      Collection<?> results = (Collection<?>) result;
      return Lists.newArrayList(Iterables.transform(results, this));
    }

    if (result instanceof Map<?, ?>) {
      Map<?, ?> resultAsMap = (Map<?, ?>) result;
      if (resultAsMap.containsKey("ELEMENT")) {
        RemoteWebElement element = newRemoteWebElement();
        element.setId(String.valueOf(resultAsMap.get("ELEMENT")));
        element.setFileDetector(driver.getFileDetector());
        return element;
      } else {
        return Maps.transformValues(resultAsMap, this);
      }
    }

    if (result instanceof Number) {
      if (result instanceof Float || result instanceof Double) {
        return ((Number) result).doubleValue();
      }
      return ((Number) result).longValue();
    }

    return result;
  }
 @Override
 public Map<SkyKey, SkyValue> getSuccessfulValues(Iterable<SkyKey> keys) {
   return Maps.filterValues(
       Maps.transformValues(
           graph.getBatch(null, Reason.WALKABLE_GRAPH_VALUE, keys), GET_SKY_VALUE_FUNCTION),
       Predicates.notNull());
 }
 @Override
 public Map<Set<Entry<String, String>>, Map<String, String>> getAllOptions() {
   return Maps.filterValues(
       Maps.transformValues(
           segments, dataEntry -> dataEntry == null ? null : dataEntry.getOptions()),
       el -> el != null);
 }
 @Override
 public Map<Set<Entry<String, String>>, Integer> getAllDefaultValues() {
   return Maps.filterValues(
       Maps.transformValues(
           segments, dataEntry -> dataEntry == null ? null : dataEntry.getPermissionDefault()),
       v -> v != null);
 }
Exemple #6
0
 public ModMetadata(JsonNode node) {
   Map<JsonStringNode, Object> processedFields =
       Maps.transformValues(node.getFields(), new JsonStringConverter());
   modId = (String) processedFields.get(aStringBuilder("modid"));
   if (Strings.isNullOrEmpty(modId)) {
     FMLLog.log(Level.SEVERE, "Found an invalid mod metadata file - missing modid");
     throw new LoaderException();
   }
   name = Strings.nullToEmpty((String) processedFields.get(aStringBuilder("name")));
   description = Strings.nullToEmpty((String) processedFields.get(aStringBuilder("description")));
   url = Strings.nullToEmpty((String) processedFields.get(aStringBuilder("url")));
   updateUrl = Strings.nullToEmpty((String) processedFields.get(aStringBuilder("updateUrl")));
   logoFile = Strings.nullToEmpty((String) processedFields.get(aStringBuilder("logoFile")));
   version = Strings.nullToEmpty((String) processedFields.get(aStringBuilder("version")));
   credits = Strings.nullToEmpty((String) processedFields.get(aStringBuilder("credits")));
   parent = Strings.nullToEmpty((String) processedFields.get(aStringBuilder("parent")));
   authorList =
       Objects.firstNonNull(
           ((List<String>) processedFields.get(aStringBuilder("authors"))),
           Objects.firstNonNull(
               ((List<String>) processedFields.get(aStringBuilder("authorList"))), authorList));
   requiredMods =
       processReferences(processedFields.get(aStringBuilder("requiredMods")), HashSet.class);
   dependencies =
       processReferences(processedFields.get(aStringBuilder("dependencies")), ArrayList.class);
   dependants =
       processReferences(processedFields.get(aStringBuilder("dependants")), ArrayList.class);
   useDependencyInformation =
       Boolean.parseBoolean(
           Strings.nullToEmpty(
               (String) processedFields.get(aStringBuilder("useDependencyInformation"))));
 }
 @Override
 public Map<Set<Entry<String, String>>, Map<String, Integer>> getAllPermissions() {
   return Maps.filterValues(
       Maps.transformValues(
           segments, dataEntry -> dataEntry == null ? null : dataEntry.getPermissions()),
       o -> o != null);
 }
  @Override
  public void setGroupMapping(Map<String, String> mapping) {
    Map<String, String> internal;
    if (mapping == null) {
      internal = Collections.emptyMap();
    } else {
      // we store ids internally but external users use the group names
      try {
        final Map<String, Role> nameToRole =
            Maps.uniqueIndex(roleService.loadAll(), Roles.roleToNameFunction());

        internal =
            Maps.newHashMap(
                Maps.transformValues(
                    mapping,
                    new Function<String, String>() {
                      @Nullable
                      @Override
                      public String apply(@Nullable String groupName) {
                        if (groupName == null || !nameToRole.containsKey(groupName)) {
                          return null;
                        }
                        return nameToRole.get(groupName).getId();
                      }
                    }));
      } catch (NotFoundException e) {
        LOG.error("Unable to convert group names to ids", e);
        throw new IllegalStateException("Unable to convert group names to ids", e);
      }
    }

    fields.put(GROUP_MAPPING, internal);
  }
  @Test
  public void test_Function_by_static_var() {
    System.out.println(eur);

    Map<String, Double> usd = Maps.transformValues(eur, PriceUtil.transfer);

    System.out.println(usd);
  }
 @Override
 public PlanNode visitProject(ProjectNode node, RewriteContext<Void> context) {
   PlanNode source = context.rewrite(node.getSource());
   Map<Symbol, Expression> assignments =
       ImmutableMap.copyOf(
           Maps.transformValues(node.getAssignments(), this::simplifyExpression));
   return new ProjectNode(node.getId(), source, assignments);
 }
Exemple #11
0
  private static String generateHelpText() {
    Map<Integer, String> details =
        Maps.transformValues(
            Maps.uniqueIndex(RESPONSE_CODES.values(), Pair::getFirst), Pair::getSecond);

    return "This endpoint can indicate to a load balancer which among a group of schedulers "
        + "is leading.\n\nThe response codes are:\n"
        + Joiner.on("\n").withKeyValueSeparator(": ").join(details);
  }
Exemple #12
0
 private Map<String, ImmutableMultiset<String>> parametersAsMap() {
   Maps.transformValues(
       this.parameters.asMap(),
       new Function() {
         public ImmutableMultiset<String> apply(Collection<String> input) {
           return ImmutableMultiset.copyOf(input);
         }
       });
 }
  @SuppressWarnings({"unchecked", "rawtypes"})
  @Override
  public Map getParameterMap() {
    Map parameterMap = Maps.newHashMap(super.getParameterMap());
    parseIfNecessary();
    parameterMap.putAll(Maps.transformValues(params.asMap(), MULTIMAP_VALUE_TRANSFORMER));

    return parameterMap;
  }
 /** Returns document counts for each partition. */
 Map<Object, Integer> getDocumentCountByPartition(List<Document> documents) {
   return ImmutableMap.copyOf(
       Maps.transformValues(
           getDocumentsByPartition(documents).asMap(),
           new Function<Collection<Document>, Integer>() {
             public Integer apply(Collection<Document> documents) {
               return documents.size();
             }
           }));
 }
Exemple #15
0
 public static Map<String, Key> getKeyInstances(final EvaluationConstraint constraint) {
   return Maps.transformValues(
       Maps.filterValues(
           KEY_MAP,
           CollectionUtils.propertyContainsPredicate(
               constraint,
               Functions.compose(
                   PolicyKeyToEvaluationConstraints.INSTANCE, KeyClassToPolicyKey.INSTANCE))),
       KeyClassToKeyInstance.INSTANCE);
 }
  @Override
  public ImmutableSubjectData clearParents() {
    if (this.segments.isEmpty()) {
      return this;
    }

    Map<Set<Entry<String, String>>, Segment> newValue =
        Maps.transformValues(
            this.segments, dataEntry -> dataEntry == null ? null : dataEntry.withoutParents());
    return newWithUpdate(newValue, createBulkUpdateFunc(newValue.keySet()));
  }
 @Override
 public BuildOutput initializeFromDisk(OnDiskBuildInfo onDiskBuildInfo) throws IOException {
   int linearAllocEstimate =
       Integer.parseInt(onDiskBuildInfo.getValue(LINEAR_ALLOC_KEY_ON_DISK_METADATA).get());
   Map<String, String> map =
       MAPPER.readValue(
           onDiskBuildInfo.getValue(CLASSNAMES_TO_HASHES).get(),
           new TypeReference<Map<String, String>>() {});
   Map<String, HashCode> classnamesToHashes = Maps.transformValues(map, TO_HASHCODE);
   return new BuildOutput(linearAllocEstimate, ImmutableSortedMap.copyOf(classnamesToHashes));
 }
Exemple #18
0
 /**
  * Gets the current values of all exported stats.
  *
  * @return All exported stat names and their associated values.
  */
 public Map<String, ? extends Number> getAllValues() {
   return ImmutableMap.copyOf(
       Maps.transformValues(
           stats,
           new Function<Supplier<? extends Number>, Number>() {
             @Override
             public Number apply(Supplier<? extends Number> supplier) {
               return supplier.get();
             }
           }));
 }
    @Override
    public Map<String, ReferenceType> get() {
      return Maps.transformValues(
          sessionSupplier.get().getOrgs(),
          new Function<ReferenceType, ReferenceType>() {

            @Override
            public ReferenceType apply(ReferenceType from) {
              return client.findOrgNamed(from.getName()).getKeys();
            }
          });
    }
 @Override
 public AsyncLeaderElector newAsyncLeaderElector(String name) {
   checkNotNull(name);
   Map<PartitionId, AsyncLeaderElector> leaderElectors =
       Maps.transformValues(members, partition -> partition.newAsyncLeaderElector(name));
   Hasher<String> hasher =
       topic -> {
         long hashCode = HashCode.fromBytes(topic.getBytes(Charsets.UTF_8)).asLong();
         return sortedMemberPartitionIds.get(Hashing.consistentHash(hashCode, members.size()));
       };
   return new PartitionedAsyncLeaderElector(name, leaderElectors, hasher);
 }
 @SuppressWarnings("unchecked")
 private Map<String, String> getRequestParameters(HttpServletRequest request) {
   Map<String, String[]> parametersMap = request.getParameterMap();
   final Function<String[], String> valuesJoiner =
       new Function<String[], String>() {
         @Override
         public String apply(String[] parameters) {
           return Joiner.on(", ").join(parameters);
         }
       };
   return Maps.newHashMap(Maps.transformValues(parametersMap, valuesJoiner));
 }
  /** Returns a map of the sub-resources on this resource. */
  public Map<String, RestResource> getResources() {
    if (resource.getResources() == null) {
      return Collections.emptyMap();
    }

    return Maps.transformValues(
        resource.getResources(),
        new Function<Restresource, RestResource>() {
          public RestResource apply(Restresource input) {
            return new RestResource(input, topLevelSchemas);
          }
        });
  }
  /** Returns a map of the methods on this resource. */
  public Map<String, RestMethod> getMethods() {
    if (resource.getMethods() == null) {
      return Collections.emptyMap();
    }

    return Maps.transformValues(
        resource.getMethods(),
        new Function<Restmethod, RestMethod>() {
          public RestMethod apply(Restmethod input) {
            return new RestMethod(topLevelSchemas, input);
          }
        });
  }
 private Map<String, EquivalenceSummary> summaryMap(
     OptionalMap<String, EquivalenceSummary> childSummaries) {
   return Maps.filterValues(
       Maps.transformValues(
           childSummaries,
           new Function<Optional<EquivalenceSummary>, EquivalenceSummary>() {
             @Override
             public EquivalenceSummary apply(@Nullable Optional<EquivalenceSummary> input) {
               return input.orNull();
             }
           }),
       Predicates.notNull());
 }
 @Override
 public Map<Set<Entry<String, String>>, List<Entry<String, String>>> getAllParents() {
   return Maps.filterValues(
       Maps.transformValues(
           segments,
           dataEntry ->
               dataEntry == null
                   ? null
                   : dataEntry.getParents() == null
                       ? null
                       : ImmutableList.copyOf(dataEntry.getParents())),
       v -> v != null);
 }
 public ExternalTree<COLOR, PAYLOAD> build() {
   return new ExternalTree<COLOR, PAYLOAD>(
       payload,
       Maps.transformValues(
           branches,
           new Function<TreeHolder<COLOR, PAYLOAD>, ExternalTree<COLOR, PAYLOAD>>() {
             @Override
             public ExternalTree<COLOR, PAYLOAD> apply(
                 @Nullable TreeHolder<COLOR, PAYLOAD> from) {
               return from.build();
             }
           }));
 }
Exemple #27
0
 private Map<String, String> transformTagMap(Map<String, String> tags) {
   return Maps.transformValues(
       tags,
       new Function<String, String>() {
         @Override
         public String apply(String value) {
           if (ANY_TAG_VALUE.equals(value)) {
             return null;
           } else {
             return value;
           }
         }
       });
 }
 /**
  * Asserts that {@code component.things()} returns an expected map. Each time this is called,
  * the current values in the map are wrapped in {@link WeakReference}s so we can {@linkplain
  * #weakThingReferenceUncollected(Object) check whether they've been cleared} later.
  */
 final void assertBindingCallCounts() {
   Map<Class<?>, Thing> things = component.things();
   assertThat(things).containsExactlyEntriesIn(expectedThingMap());
   weakThings =
       ImmutableMap.copyOf(
           Maps.transformValues(
               things,
               new Function<Thing, WeakReference<Thing>>() {
                 @Override
                 public WeakReference<Thing> apply(Thing thing) {
                   return new WeakReference<>(thing);
                 }
               }));
 }
      @Override
      public Map<String, ReferenceType> get() {
        return Maps.transformValues(
            sessionSupplier.get().getOrgs(),
            new Function<ReferenceType, ReferenceType>() {

              @Override
              public ReferenceType apply(ReferenceType from) {
                return new ReferenceTypeImpl(
                    from.getName(),
                    TerremarkVCloudExpressMediaType.KEYSLIST_XML,
                    URI.create(from.getHref().toASCIIString() + "/keysList"));
              }
            });
      }
 @Override
 public <K, V> AsyncConsistentMap<K, V> newAsyncConsistentMap(String name, Serializer serializer) {
   checkNotNull(name);
   checkNotNull(serializer);
   Map<PartitionId, AsyncConsistentMap<K, V>> maps =
       Maps.transformValues(
           members, partition -> partition.newAsyncConsistentMap(name, serializer));
   Hasher<K> hasher =
       key -> {
         long hashCode =
             HashCode.fromBytes(Bytes.ensureCapacity(serializer.encode(key), 8, 0)).asLong();
         return sortedMemberPartitionIds.get(Hashing.consistentHash(hashCode, members.size()));
       };
   return new PartitionedAsyncConsistentMap<>(name, maps, hasher);
 }