当前位置: 首页>>代码示例>>Java>>正文


Java EntryTransformer类代码示例

本文整理汇总了Java中com.google.common.collect.Maps.EntryTransformer的典型用法代码示例。如果您正苦于以下问题:Java EntryTransformer类的具体用法?Java EntryTransformer怎么用?Java EntryTransformer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


EntryTransformer类属于com.google.common.collect.Maps包,在下文中一共展示了EntryTransformer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testSortedMapTransformEntries

import com.google.common.collect.Maps.EntryTransformer; //导入依赖的package包/类
public void testSortedMapTransformEntries() {
  SortedMap<String, String> map =
      sortedNotNavigable(ImmutableSortedMap.of("a", "4", "b", "9"));
  EntryTransformer<String, String, String> concat =
      new EntryTransformer<String, String, String>() {
        @Override
        public String transformEntry(String key, String value) {
          return key + value;
        }
      };
  SortedMap<String, String> transformed = transformEntries(map, concat);

  /*
   * We'd like to sanity check that we didn't get a NavigableMap out, but we
   * can't easily do so while maintaining GWT compatibility.
   */
  assertEquals(ImmutableSortedMap.of("a", "a4", "b", "b9"), transformed);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:19,代码来源:MapsTest.java

示例2: updateFields

import com.google.common.collect.Maps.EntryTransformer; //导入依赖的package包/类
@Override
public <ID> int updateFields(String tableName, ID id, Map<String, Object> valueMap) {
	StringBuilder sqlSb = new StringBuilder();
	sqlSb.append("UPDATE `");
	sqlSb.append(tableName);
	sqlSb.append("`  SET ");
	EntryTransformer<String, Object, String> transformer = new EntryTransformer<String, Object, String>() {
		@Override
		public String transformEntry(String key, Object value) {
			String column = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, key);
			return "`" + column + "`='" + value + "'";
		}
	};
	Map<String, String> transformed = Maps.transformEntries(valueMap, transformer);
	sqlSb.append(Joiner.on(",").join(transformed.values()));
	sqlSb.append(" WHERE `id`='" + id + "';");
	return jdbcTemplate.update(sqlSb.toString());
}
 
开发者ID:East196,项目名称:maker,代码行数:19,代码来源:CommonRepositoryImpl.java

示例3: TransformedEntries

import com.google.common.collect.Maps.EntryTransformer; //导入依赖的package包/类
TransformedEntries(
    final EntryTransformer<? super K, ? super V1, V2> transformer) {
  super(fromMultimap.entries(),
      new Function<Entry<K, V1>, Entry<K, V2>>() {
        @Override public Entry<K, V2> apply(final Entry<K, V1> entry) {
          return new AbstractMapEntry<K, V2>() {

            @Override public K getKey() {
              return entry.getKey();
            }

            @Override public V2 getValue() {
              return transformer.transformEntry(
                  entry.getKey(), entry.getValue());
            }
          };
        }
      });
}
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:20,代码来源:Multimaps.java

示例4: testTransformEntriesSecretlyNavigable

import com.google.common.collect.Maps.EntryTransformer; //导入依赖的package包/类
@GwtIncompatible("NavigableMap")
public void testTransformEntriesSecretlyNavigable() {
  Map<String, String> map = ImmutableSortedMap.of("a", "4", "b", "9");
  EntryTransformer<String, String, String> concat =
      new EntryTransformer<String, String, String>() {
        @Override
        public String transformEntry(String key, String value) {
          return key + value;
        }
      };
  Map<String, String> transformed;

  transformed = transformEntries(map, concat);
  assertEquals(ImmutableMap.of("a", "a4", "b", "b9"), transformed);
  assertTrue(transformed instanceof NavigableMap);

  transformed = transformEntries((SortedMap<String, String>) map, concat);
  assertEquals(ImmutableMap.of("a", "a4", "b", "b9"), transformed);
  assertTrue(transformed instanceof NavigableMap);
}
 
开发者ID:sander120786,项目名称:guava-libraries,代码行数:21,代码来源:MapsTest.java

示例5: createAsMap

import com.google.common.collect.Maps.EntryTransformer; //导入依赖的package包/类
Map<K, Collection<V>> createAsMap() {
  // Select the values that satisify the predicate.
  EntryTransformer<K, Collection<V>, Collection<V>> transformer
      = new EntryTransformer<K, Collection<V>, Collection<V>>() {
        @Override public Collection<V> transformEntry(K key, Collection<V> collection) {
          return filterCollection(collection, new ValuePredicate(key));
        }
  };
  Map<K, Collection<V>> transformed
      = Maps.transformEntries(unfiltered.asMap(), transformer);

  // Select the keys that have at least one value remaining.
  Map<K, Collection<V>> filtered = Maps.filterValues(transformed, NOT_EMPTY);

  // Override the removal methods, since removing a map entry should not
  // affect values that don't satisfy the filter.
  return new AsMap(filtered);
}
 
开发者ID:10xEngineer,项目名称:My-Wallet-Android,代码行数:19,代码来源:Multimaps.java

示例6: testSortedMapTransformEntries

import com.google.common.collect.Maps.EntryTransformer; //导入依赖的package包/类
public void testSortedMapTransformEntries() {
  SortedMap<String, String> map = sortedNotNavigable(ImmutableSortedMap.of("a", "4", "b", "9"));
  EntryTransformer<String, String, String> concat =
      new EntryTransformer<String, String, String>() {
        @Override
        public String transformEntry(String key, String value) {
          return key + value;
        }
      };
  SortedMap<String, String> transformed = transformEntries(map, concat);

  /*
   * We'd like to sanity check that we didn't get a NavigableMap out, but we
   * can't easily do so while maintaining GWT compatibility.
   */
  assertEquals(ImmutableSortedMap.of("a", "a4", "b", "b9"), transformed);
}
 
开发者ID:google,项目名称:guava,代码行数:18,代码来源:MapsTest.java

示例7: EnumVocab

import com.google.common.collect.Maps.EntryTransformer; //导入依赖的package包/类
/**
 * Creates a new vocabulary backed by the given {@link Enum} class and with
 * properties having the common URI stem <code>base</code> and prefix
 * <code>prefix</code>
 * 
 * @param clazz
 *          the enumeration backing this vocabulary.
 * @param base
 *          the common stem URI of properties in this vocabulary.
 * @param prefix
 *          the common prefix of properties in this vocabulary.
 */
public EnumVocab(final Class<P> clazz, final String base, final String prefix)
{
  this.uri = Strings.nullToEmpty(base);
  this.index = ImmutableMap
      .copyOf(Maps.transformEntries(Maps.uniqueIndex(EnumSet.allOf(clazz), ENUM_TO_NAME),
          new EntryTransformer<String, P, Property>()
          {

            @Override
            public Property transformEntry(String name, P enumee)
            {
              return Property.newFrom(name, base, prefix, enumee);
            }

          }));
}
 
开发者ID:jcdarwin,项目名称:epubcheck-web,代码行数:29,代码来源:EnumVocab.java

示例8: scopeRequest

import com.google.common.collect.Maps.EntryTransformer; //导入依赖的package包/类
/**
 * Scopes the given callable inside a request scope. This is not the same
 * as the HTTP request scope, but is used if no HTTP request scope is in
 * progress. In this way, keys can be scoped as @RequestScoped and exist
 * in non-HTTP requests (for example: RPC requests) as well as in HTTP
 * request threads.
 *
 * <p>The returned callable will throw a {@link ScopingException} when called
 * if there is a request scope already active on the current thread.
 *
 * @param callable code to be executed which depends on the request scope.
 *     Typically in another thread, but not necessarily so.
 * @param seedMap the initial set of scoped instances for Guice to seed the
 *     request scope with.  To seed a key with null, use {@code null} as
 *     the value.
 * @return a callable that when called will run inside the a request scope
 *     that exposes the instances in the {@code seedMap} as scoped keys.
 * @since 3.0
 */
public static <T> Callable<T> scopeRequest(final Callable<T> callable,
    Map<Key<?>, Object> seedMap) {
  Preconditions.checkArgument(null != seedMap,
      "Seed map cannot be null, try passing in Collections.emptyMap() instead.");

  // Copy the seed values into our local scope map.
  final Context context = new Context();
  Map<Key<?>, Object> validatedAndCanonicalizedMap =
      Maps.transformEntries(seedMap, new EntryTransformer<Key<?>, Object, Object>() {
        @Override public Object transformEntry(Key<?> key, Object value) {
          return validateAndCanonicalizeValue(key, value);
        }
      });
  context.map.putAll(validatedAndCanonicalizedMap);

  return new Callable<T>() {
    public T call() throws Exception {
      checkScopingState(null == GuiceFilter.localContext.get(),
          "An HTTP request is already in progress, cannot scope a new request in this thread.");
      checkScopingState(null == requestScopeContext.get(),
          "A request scope is already in progress, cannot scope a new request in this thread.");
      return context.call(callable);
    }
  };
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:45,代码来源:ServletScopes.java

示例9: createAsMap

import com.google.common.collect.Maps.EntryTransformer; //导入依赖的package包/类
@Override
Map<K, Collection<V2>> createAsMap() {
  return Maps.transformEntries(
      fromMultimap.asMap(),
      new EntryTransformer<K, Collection<V1>, Collection<V2>>() {
        @Override
        public Collection<V2> transformEntry(K key, Collection<V1> value) {
          return transform(key, value);
        }
      });
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:12,代码来源:Multimaps.java

示例10: testTransformEntries

import com.google.common.collect.Maps.EntryTransformer; //导入依赖的package包/类
public void testTransformEntries() {
  Map<String, String> map = ImmutableMap.of("a", "4", "b", "9");
  EntryTransformer<String, String, String> concat =
      new EntryTransformer<String, String, String>() {
        @Override
        public String transformEntry(String key, String value) {
          return key + value;
        }
      };
  Map<String, String> transformed = transformEntries(map, concat);

  assertEquals(ImmutableMap.of("a", "a4", "b", "b9"), transformed);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:14,代码来源:MapsTest.java

示例11: testTransformEntriesExample

import com.google.common.collect.Maps.EntryTransformer; //导入依赖的package包/类
public void testTransformEntriesExample() {
  Map<String, Boolean> options =
      ImmutableMap.of("verbose", true, "sort", false);
  EntryTransformer<String, Boolean, String> flagPrefixer =
      new EntryTransformer<String, Boolean, String>() {
        @Override
        public String transformEntry(String key, Boolean value) {
          return value ? key : "no" + key;
        }
      };
  Map<String, String> transformed = transformEntries(options, flagPrefixer);
  assertEquals("{verbose=verbose, sort=nosort}", transformed.toString());
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:14,代码来源:MapsTest.java

示例12: testNavigableMapTransformEntries

import com.google.common.collect.Maps.EntryTransformer; //导入依赖的package包/类
@GwtIncompatible // NavigableMap
public void testNavigableMapTransformEntries() {
  NavigableMap<String, String> map =
      ImmutableSortedMap.of("a", "4", "b", "9");
  EntryTransformer<String, String, String> concat =
      new EntryTransformer<String, String, String>() {
        @Override
        public String transformEntry(String key, String value) {
          return key + value;
        }
      };
  NavigableMap<String, String> transformed = transformEntries(map, concat);

  assertEquals(ImmutableSortedMap.of("a", "a4", "b", "b9"), transformed);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:16,代码来源:MapsTest.java

示例13: createAsMap

import com.google.common.collect.Maps.EntryTransformer; //导入依赖的package包/类
@Override
Map<K, Collection<V2>> createAsMap() {
  return Maps.transformEntries(fromMultimap.asMap(), new EntryTransformer<K, Collection<V1>, Collection<V2>>() {
                                                       @Override
                                                       public Collection<V2> transformEntry(K key, Collection<V1> value) {
                                                         return transform(key, value);
                                                       }
                                                     });
}
 
开发者ID:antlr,项目名称:codebuff,代码行数:10,代码来源:Multimaps.java

示例14: createRequestRouter

import com.google.common.collect.Maps.EntryTransformer; //导入依赖的package包/类
@Override
protected RequestRouter createRequestRouter(final Registry registry, final GlobalConfiguration globalConfiguration) {
  final Dispatcher dispatcher = createDispatcher(globalConfiguration.getDispatcherClass());
  return new RequestRouter(registry, globalConfiguration, dispatcher)
  {
    @Override
    public void processPollRequest(final Reader reader, final Writer writer, final String pathInfo)
        throws IOException
    {
      new PollRequestProcessor(registry, dispatcher, globalConfiguration)
      {
        @Override
        // HACK: we determine parameters from request not by reading request content as request content could had
        // been already read exactly for getting the params, case when request content is already empty
        protected Object[] getParameters()
        {
          if (reader instanceof RequestBoundReader) {
            ServletRequest request = ((RequestBoundReader) reader).getRequest();
            Map<String, String[]> parameterMap = request.getParameterMap();
            Map<String, String> parameters = Maps.newHashMap();
            if (parameterMap != null) {
              parameters = Maps.transformEntries(parameterMap, new EntryTransformer<String, String[], String>()
              {
                @Override
                public String transformEntry(@Nullable final String key, @Nullable final String[] values) {
                  return values == null || values.length == 0 ? null : values[0];
                }
              });
            }
            return new Object[]{parameters};
          }
          return super.getParameters();
        }
      }.process(reader, writer, pathInfo);
    }
  };
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:38,代码来源:ExtDirectServlet.java

示例15: getPartitionsForTopic

import com.google.common.collect.Maps.EntryTransformer; //导入依赖的package包/类
/**
 * @param brokers in multiple clusters, keyed by cluster id
 * @param topic
 * @return Get the partition metadata list for the specific topic via the brokers
 * null if topic is not found
 */
public static Map<String, List<PartitionMetadata>> getPartitionsForTopic(SetMultimap<String, String> brokers, final String topic)
{
  return Maps.transformEntries(brokers.asMap(), new EntryTransformer<String, Collection<String>, List<PartitionMetadata>>()
  {
    @Override
    public List<PartitionMetadata> transformEntry(String key, Collection<String> bs)
    {
      return getPartitionsForTopic(new HashSet<String>(bs), topic);
    }
  });
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:18,代码来源:KafkaMetadataUtil.java


注:本文中的com.google.common.collect.Maps.EntryTransformer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。