collections

Collect a list of ids based on multiple fields

走远了吗. 提交于 2021-02-04 07:38:10
问题 I have a person object with personId, age and gender. public class Person { private int personId; private int age; private int gender; // 0 for male and 1 for female } List<Person> person = new Arraylist<>(); person.add(new Person(1,1,1)); person.add(new Person(2,2,0)); person.add(new Person(3,10,1)); person.add(new Person(4,11,0)); person.add(new Person(5,20,1)); person.add(new Person(6,20,1)); person.add(new Person(7,2,0)); person.add(new Person(8,20,0)); person.add(new Person(9,11,0));

How to delete item from Hashmap inside a RefCell within an RwLock-ed Struct

眉间皱痕 提交于 2021-01-29 13:11:08
问题 I have a struct: pub struct CommunityContents { pub friends: RefCell<HashMap<FriendID, FriendData>>, pub index: RefCell<HashMap<u64, BTreeMap<FriendID, FriendData>>>, pub authenticated: bool, pub age: u64, pub height: u64, } Which is protected with a RwLock with a parent struct: pub struct Community { pub community_contents: RwLock<CommunityContents>, } pub struct FriendData { pointer: Rc<Data>, } pub struct Data { pub key: Key, pub friend_ids: Vec<FriendID>, } I want to be able to modify the

AbstractList UnsupportedOperationException when calling .sort on a List

匆匆过客 提交于 2021-01-29 05:40:19
问题 I'm sorting a List using Collections.sort(), which seems to be working every way I can test it. Some of my users are crashing though. Caused by java.lang.UnsupportedOperationException java.util.AbstractList.set (AbstractList.java:681) java.util.AbstractList$FullListIterator.set (AbstractList.java:143) java.util.Collections.sort (Collections.java:1909) com.myapp.MyFragment.myMethod (MyFragment.java:225) But, all I'm doing is trying to sort a List private void myMethod(List<MyThing> myThings) {

Is there any way to allow moving a container that has a borrowed element but not dropping it?

我们两清 提交于 2021-01-28 20:59:45
问题 I have this container: use std::ptr::NonNull; struct Container { data: NonNull<u8>, } impl Container { fn new() -> Container { todo!() } fn borrow_some_heap_data<'a>(&'a self) -> &'a u8 { todo!() } fn borrow_some_heap_data_mut<'a>(&'a mut self) -> &'a mut u8 { todo!() } } impl Drop for Container { fn drop(&mut self) { todo!() } } fn main() { let container = Container::new(); let data = container.borrow_some_heap_data(); // or mut { let container = container; // move // This is safe because

Collection of Collections - How to make sub-collections by value rather than reference?

蓝咒 提交于 2021-01-28 19:24:43
问题 What I am trying to do is for Autodesk Inventor. I'm writing a program that goes iterates through a bunch of lines in a sketch. It gathers the groups of connected lines and puts them in a collection. Then it makes a collection of these collections to be processed. I'm trying to do this by adding the lines to a temporary collection, then adding this temporary collection to the collection of loops, so that I don't have to generate an unknown amount of collections for each loop. However, as soon

Is there a way to validate fields in a Request Object that am using as a wrapper, such that one of them is optional

时光毁灭记忆、已成空白 提交于 2021-01-28 08:03:30
问题 Controller Code: @RequestMapping(value="/update", method=RequestMethod.POST, produces = "application/json; charset=utf-8") @ResponseBody public ResponseEntityWrapper update( HttpServletRequest request, @RequestBody @Valid InputForm form, HttpServletResponse response ) { //logic } InputForm: public class InputForm{ @NotNull private String formId; private List<Employee> addEmpList; private List<Employee> removeEmpList; //Other fields & getters & setters..... } Employee: public Employee{

Collision in hashmap

≯℡__Kan透↙ 提交于 2021-01-28 06:30:53
问题 I have read about the Hashmap collision and took the following example. Since i am not able to understand what is collision and how to avoid collision is occurs. The example is follows import java.util.*; class JavaCollision{ public static void main(String args[]){ HashMap<Person, String> map=new HashMap<Person, String>(); Person p1 = new Person(1,"ABC"); Person p2 = new Person(2,"DEF"); Person p3 = new Person(1,"XYZ"); Person p4 = new Person(1,"PQR"); Person p5 = new Person(1,"PQR"); System

How can I lock the internals of my Rust data structure?

百般思念 提交于 2021-01-28 04:35:38
问题 I'm trying to implement a collection that stores values in both a vector and a hashmap and this is what I have so far: pub struct CollectionWrapper { items: Vec<Item>, items_map: HashMap<ItemKey, Item>, } impl CollectionWrapper { pub fn new() -> Self { CollectionWrapper { items: Vec::new(), items_map: HashMap::new(), } } pub fn add(&mut self, item: Item) { let key = item.get_key(); self.items.push(item.clone()); self.items_map.insert(key, item.clone()); } } I obviously need some kind of lock.

How can I lock the internals of my Rust data structure?

邮差的信 提交于 2021-01-28 04:31:29
问题 I'm trying to implement a collection that stores values in both a vector and a hashmap and this is what I have so far: pub struct CollectionWrapper { items: Vec<Item>, items_map: HashMap<ItemKey, Item>, } impl CollectionWrapper { pub fn new() -> Self { CollectionWrapper { items: Vec::new(), items_map: HashMap::new(), } } pub fn add(&mut self, item: Item) { let key = item.get_key(); self.items.push(item.clone()); self.items_map.insert(key, item.clone()); } } I obviously need some kind of lock.

generic collection generation with a generic type

别来无恙 提交于 2021-01-28 04:24:45
问题 Sometimes, I find myself wishing scala collections to include some missing functionality, and it's rather easy "extending" a collection, and provide a custom method. This is a bit more difficult when it comes to building the collection from scratch. Consider useful methods such as .iterate . I'll demonstrate the usecase with a similar, familiar function: unfold . unfold is a method to construct a collection from an initial state z: S , and a function to generate an optional tuple of the next