collections

C# List<object>.RemoveAll() - How to remove a subset of the list?

半腔热情 提交于 2019-12-30 06:30:11
问题 I have a 2 classes feeds_Auto and Product with multiple matching properties. For this particular problem, the AutoID is the only field I need to use. I have a List<FeedsAuto> with several hundred unique entries. I have a small List<Product> with 10, 20 unique entries. I now want to remove all items in the small list from the large list. How do I use RemoveAll({lambda expression}) to accomplish this? All of the examples I have found depend on the generic list being of simple types (strings,

C# List<object>.RemoveAll() - How to remove a subset of the list?

ぐ巨炮叔叔 提交于 2019-12-30 06:29:07
问题 I have a 2 classes feeds_Auto and Product with multiple matching properties. For this particular problem, the AutoID is the only field I need to use. I have a List<FeedsAuto> with several hundred unique entries. I have a small List<Product> with 10, 20 unique entries. I now want to remove all items in the small list from the large list. How do I use RemoveAll({lambda expression}) to accomplish this? All of the examples I have found depend on the generic list being of simple types (strings,

Better Map Constructor

陌路散爱 提交于 2019-12-30 06:26:26
问题 Is there a more streamlined way to do the following? Map<String, String> map = new HashMap<String, String>(); map.put("a", "apple"); map.put("b", "bear"); map.put("c", "cat"); I'm looking for something closer to this. Map<String, String> map = MapBuilder.build("a", "apple", "b", "bear", "c", "cat"); 回答1: No, there isn't, but I wrote a method to do exactly this, inspired by Objective-C NSDictionary class: public static Map<String, Object> mapWithKeysAndObjects(Object... objects) { if (objects

Guava way of sorting List according to another list?

↘锁芯ラ 提交于 2019-12-30 06:20:02
问题 I have List<Integer> consisting Ids of my Users. And after a database query, I am retrieving List<User> . I would like to order this list according to first Id list. List<User> may not include some of the Ids. What is the Guava way for sorting this list? 回答1: The fully "functional" way, using Guava, would combine Ordering#explicit() with Ordering#onResultOf() public class UserService { @Inject private UserDao userDao; public List<User> getUsersWithIds(List<Integer> userIds) { List<User> users

Guava way of sorting List according to another list?

懵懂的女人 提交于 2019-12-30 06:19:07
问题 I have List<Integer> consisting Ids of my Users. And after a database query, I am retrieving List<User> . I would like to order this list according to first Id list. List<User> may not include some of the Ids. What is the Guava way for sorting this list? 回答1: The fully "functional" way, using Guava, would combine Ordering#explicit() with Ordering#onResultOf() public class UserService { @Inject private UserDao userDao; public List<User> getUsersWithIds(List<Integer> userIds) { List<User> users

List implementations: does LinkedList really perform so poorly vs. ArrayList and TreeList?

为君一笑 提交于 2019-12-30 05:45:11
问题 Taken from the Apache TreeList doc: The following relative performance statistics are indicative of this class: get add insert iterate remove TreeList 3 5 1 2 1 ArrayList 1 1 40 1 40 LinkedList 5800 1 350 2 325 It goes on to say: LinkedList is rarely a good choice of implementation. TreeList is almost always a good replacement for it, although it does use sligtly more memory. My questions are: What is with the ArrayList add , insert , and remove times crushing LinkedList ? Should we expect,

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

com.sun.faces.renderkit.html_basic.MenuRenderer createCollection: Unable to create new Collection instance for type java.util.Arrays$ArrayList

给你一囗甜甜゛ 提交于 2019-12-30 04:43:07
问题 I'm trying to use JSF / SelectManyCheckBox tag with an enum : Here is my xhtml code : <h:form id="searchForm"> <h:panelGrid columns="2"> <h:outputText value="Searched queues" /> <h:panelGroup> <h:selectManyCheckbox layout="pageDirection" value="#{jmsErrorController.errorSearchCriteria.searchedQueues}" converter="queueConverter"> <f:selectItems value="#{jmsErrorController.completeQueueList}" /> </h:selectManyCheckbox> </h:panelGroup> </h:panelGrid> <h:commandButton action="#{jmsErrorController

How to initialize a map using a lambda?

时间秒杀一切 提交于 2019-12-30 04:24:11
问题 I want to declare a fully populated map field in a single statement, (which may contain several nested statements,) like this: private static final Map<Integer,Boolean> map = something-returning-an-unmodifiable-fully-populated-HashMap; Anonymous initializers won't do, for the same reason that invoking a function which returns a new populated map won't do: they require two top-level statements: one for the variable declaration, and one for the method or initializer. The double curly bracket (

Why does Collections.sort(List) work in Java 8 with CopyOnWriteArrayList but not in Java 7?

邮差的信 提交于 2019-12-30 04:06:33
问题 I can sort a list of users without any problems using the following code and Java 8: CopyOnWriteArrayList<User> allCurrentLoginnedUsersList = new CopyOnWriteArrayList<>(); Collections.sort(allCurrentLoginnedUsersList); Now, I changed to Java 7 and I saw no errors on eclipse. But now, when running under Java 7 I got this error: java.lang.UnsupportedOperationException at java.util.concurrent.CopyOnWriteArrayList$COWIterator.set(CopyOnWriteArrayList.java:1049) at java.util.Collections.sort