collections

Get /collection/id in backbone without loading the entire collection

a 夏天 提交于 2019-12-31 22:36:08
问题 Is there a way to load a single entity of a Backbone collection (from the server)? Backbone.Collection.extend({ url: '/rest/product' }); The following code can load the entire collection with a collection.fetch() but how to load a single model? Backbone's documentation says clearly that GET can be done /collection[/id] but not how. 回答1: While we set url:"api/user" for the collection, the equivalent for the model is urlRoot:"api/user" this will make backbone automatically append the /id when

How to receive difference of maps in java?

↘锁芯ラ 提交于 2019-12-31 19:20:34
问题 I have two maps: Map<String, Object> map1; Map<String, Object> map2; I need to receive difference between these maps. Does exist may be apache utils how to receive this difference? For now seems need take entry set of each map and found diff1 = set1 - set2 and diff2 = set2- set1. After create summary map =diff1 + diff2 It looks very awkwardly. Does exist another way? Thanks. 回答1: How about google guava?: Maps.difference(map1,map2) 回答2: Here is a simple snippet you can use instead of massive

Java Commons Collections removeAll

十年热恋 提交于 2019-12-31 17:49:10
问题 CollectionUtils::removeAll() Commons Collections 3.2.1 I must be going crazy, becuase it seems like this method is doing the inverse of what the docs state: Removes the elements in remove from collection. That is, this method returns a collection containing all the elements in c that are not in remove. This little JUnit test @Test public void testCommonsRemoveAll() throws Exception { String str1 = "foo"; String str2 = "bar"; String str3 = "qux"; List<String> collection = Arrays.asList(str1,

MongoDB collection hyphenated name

早过忘川 提交于 2019-12-31 10:19:29
问题 I'm using Node.js program to insert data into a MongoDB database. I have inserted data into a collection named "repl-failOver". var mongoClient = require("mongodb").MongoClient; mongoClient.connect("mongodb://localhost:30002/test", function(err, db) { if (err) throw err; db.collection("repl-failOver").insert( { "documentNumber" : document++}, function (err, doc) { if (err) throw err; console.log(doc); }); db.close(); }); When I use the Mongo shell and list down the collections in the database

How to efficiently (performance) remove many items from List in Java?

孤街浪徒 提交于 2019-12-31 08:44:54
问题 I have quite large List named items (>= 1,000,000 items) and some condition denoted by <cond> that selects items to be deleted and <cond> is true for many (maybe half) of items on my list. My goal is to efficiently remove items selected by <cond> and retain all other items, source list may be modified, new list may be created - best way to do it should be chosen considering performance. Here is my testing code: System.out.println("preparing items"); List<Integer> items = new ArrayList<Integer

compare 2 lists in java [closed]

不羁岁月 提交于 2019-12-31 07:26:06
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I am getting data from the two different databases and storing them in the java.util.List Elements of database:1 column 1 column 2 **Investment Number** Investment Name 123 abcwe 124 agsdf 454 lkjcv 784 ojncv 478 hfdgh 852 qweyu 745 mmkty 201 pbckl 560 jklfg 741 nbvbn storing them in list1 Elements of database:2

Sort a Map<Key, Value> by values

泄露秘密 提交于 2019-12-31 07:21:22
问题 I am relatively new to Java, and often find that I need to sort a Map<Key, Value> on the values. Since the values are not unique, I find myself converting the keySet into an array , and sorting that array through array sort with a custom comparator that sorts on the value associated with the key. Is there an easier way? 回答1: Here's a generic-friendly version: public class MapUtil { public static <K, V extends Comparable<? super V>> Map<K, V> sortByValue(Map<K, V> map) { List<Entry<K, V>> list

Best way to sort a Set?

跟風遠走 提交于 2019-12-31 07:11:24
问题 i have a class representing cars: public class Car implements Comparable<Car> { String name; int value; ... @Override public int compareTo(Car o) { return name.compareTo(o.name); } } and another class representing races: public class Race { cars = new HashSet<Car>(); ... public Collection<Car> sortByName() { List<Car> carList = new ArrayList<>(cars); Collections.sort(carList); return carList; } } Its my implementation to sorting the Set, i know there is a TreeSet but i dont know how to

Scala: Fill the gaps in a List with last non-empty value

耗尽温柔 提交于 2019-12-31 05:11:17
问题 I have a list like: val arr = Array("a", "", "", "b", "c", "") I am looking for a way to create: Array("a", "a", "a", "b", "c", "c") 回答1: You can try with fold, the easy (to understand) approach is fold left: (Array.empty[String] /: arr) { case (prev, "") => prev :+ prev.lastOption.getOrElse(""); case (prev, l) => prev :+ l } > res01: Array[String] = Array(a, a, a, b, c, c) This builds a new array from the previous by appending arr elements or the resulting list's last depending on whether

Strange UnsupportedOperationException when calling list.remove(0)

我的梦境 提交于 2019-12-31 04:50:08
问题 I have this method which takes a varargs of Strings, creates a List out of it, and then tries to remove the first element of the list. public void importFrom(String... files) { List<String> fileList = Arrays.asList(files); String first = fileList.remove(0); // other stuff } But as soon as remove gets called, an UnsupportedOperationException is thrown. My guess is that the return List-Type does not support the remove method. Am I correct? What alternatives do I have? 回答1: Arrays.asList only