Guava

Why there is no getFirst(iterable) method?

半腔热情 提交于 2019-12-30 05:32:08
问题 Iterables present two methods for getLast public static <T> T getLast(Iterable<T> iterable); public static <T> T getLast(Iterable<T> iterable, @Nullable T defaultValue); but only one for getFirst public static <T> T getFirst(Iterable<T> iterable, @Nullable T defaultValue); Is there are any design/implementation reason for breaking symmetry? 回答1: I think the point is that there is no reason for a getFirst(iterable) in that this could be done with iterable.iterator().next() . Guava makes an

How to scan classes for annotations?

时光怂恿深爱的人放手 提交于 2019-12-30 01:51:13
问题 I have a plain jane servlets web application, and some of my classes have the following annotations: @Controller @RequestMapping(name = "/blog/") public class TestController { .. } Now when my servlet applications starts up, I would like to get a list of all classes that have the @Controller annotation, and then get the value of the @RequestMapping annotation and insert it in a dictionary. How can I do this? I'm using Guice and Guava also, but not sure if that has any annotation related

Library method to partition a collection by a predicate

别说谁变了你拦得住时间么 提交于 2019-12-30 01:37:11
问题 I have a collection of objects that I would like to partition into two collections, one of which passes a predicate and one of which fails a predicate. I was hoping there would be a Guava method to do this, but the closest they come is filter, which doesn't give me the other collection. I would image the signature of the method would be something like this: public static <E> Pair<Collection<E>, Collection<E>> partition(Collection<E> source, Predicate<? super E> predicate) I realize this is

Parse a string with key=value pair in a map? [duplicate]

廉价感情. 提交于 2019-12-29 08:06:51
问题 This question already has answers here : Parse a string with delimiters and load it in a map? (2 answers) Closed 3 years ago . I have below String which is in the format of key1=value1, key2=value2 which I need to load it in a map (Map<String, String>) as key=value so I need to split on comma , and then load cossn as key and 0 its value. String payload = "cossn=0, itwrqm=200006033213"; Map<String, String> holder = Splitter.on(",").trimResults().withKeyValueSeparator("=").split(payload); I am

How to use TypeToken to get type parameter?

寵の児 提交于 2019-12-29 07:56:27
问题 I am attempting to look up a type parameter at runtime using TypeToken as showing in the Guava documentation example IKnowMyType : public class Test<E extends Enum<E>> { private static enum MyEnum { FIRST, SECOND }; private final TypeToken<E> enumType = new TypeToken<E>(getClass()) { }; public static void main(String[] args) { Test<MyEnum> container = new Test<>(); System.out.println(container.enumType.getRawType()); } } When I run this code, I get class java.lang.Enum as output. Why am not

Guava and Weblogic:ClassNotFoundException

别等时光非礼了梦想. 提交于 2019-12-29 01:54:11
问题 I'm trying to work on a web application that deploys to Weblogic 10.3.5. One of the maven dependencies is Guava. Unfortunately, upon attempting to publish the project, weblogic throws this exception: java.lang.ClassNotFoundException: com.google.common.eventbus.EventBus at weblogic.utils.classloaders.GenericClassLoader.findLocalClass(GenericClassLoader.java:297) at weblogic.utils.classloaders.GenericClassLoader.findClass(GenericClassLoader.java:270) at weblogic.utils.classloaders

NoSuchMethodError: com.google.common.util.concurrent.MoreExecutors.directExecutor conflits on Elastic Search jar

扶醉桌前 提交于 2019-12-28 13:47:26
问题 While creating Elasticsearch Client, I'm getting the exception java.lang.NoSuchMethodError: com.google.common.util.concurrent.MoreExecutors.directExecutor()Ljava/util/concurrent/Executor; After some lookup, seams like the Guava-18 is being overwrite by an older version at runtime, and Guava-18 only works during compile task. My Maven configuration is the follow: <build> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.0</version> <configuration> <source>1.7</source

drill guava包冲突

旧巷老猫 提交于 2019-12-26 18:50:02
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 报错原因:guava包同时存在高版本和低版本,其它类依赖时直接选择了低版本,导致冲突 解决办法:直接在pom.xml文件里加高版本的guava依赖 来源: oschina 链接: https://my.oschina.net/u/2499632/blog/651125

How to iterate two multi maps and print the difference in file?

心已入冬 提交于 2019-12-25 07:40:02
问题 I have two multimaps as below : ListMultimap<String, String> source_multimap = ArrayListMultimap.create(); ListMultimap<String, String> target_multimap = ArrayListMultimap.create(); for (SwiftTagListBlock s : source_tagListBlock) { Iterator<Tag> sourcetag_iterator = s.tagIterator(); while (sourcetag_iterator.hasNext()) { Tag tag = (Tag) sourcetag_iterator.next(); source_multimap.put(tag.getName(), tag.getValue()); } } for (SwiftTagListBlock t : target_tagListBlock) { Iterator<Tag> targettag

How to reliably drop records from Guava LoadingCache?

99封情书 提交于 2019-12-25 04:33:14
问题 I am using Guava LoadingCache to populate some data into it and I want to remove all the entries from that LoadingCache every 1 minute. public class MetricHolder { private final ExecutorService executor = Executors.newFixedThreadPool(2); private final LoadingCache<String, AtomicLongMap<String>> clientIdMetricCounterCache = CacheBuilder.newBuilder().expireAfterWrite(1, TimeUnit.MINUTES) .removalListener(RemovalListeners.asynchronous(new SendToDatabase(), executor)) .build(new CacheLoader