collections

Return empty Vector collection instead of null

こ雲淡風輕ζ 提交于 2019-12-13 22:26:51
问题 I have a function that returns a Vector and in case of an error, I want to return an empty Vector which can be checked using Collections.isEmpty by the calling method. But I am unable to find the way to do it as Collections provides Collections.emptyList functions for List, Maps, etc. but not for Vector and I am forced to return null by function which I want to avoid. How to achieve this? 回答1: You could return a new Vector<X>() , but a better solution would be to move away from Vector which

C# Component collection property not serialized when filled from property setter

倾然丶 夕夏残阳落幕 提交于 2019-12-13 21:02:43
问题 I have a C# component which has two properties, Property1 and Property2. Property1 is a simple property of type int and Property2 is a List where T is a custom class. Property2 has the DesignerSerializationVisibility.Content attribute set. When Property1 is set at Designtime the component should generate the number of custom classes that is set. This works but the classes aren't serialized to the Designer.cs file. When I add a custom class through the standard collection editor of Visual

Check whether a List of object has a node which matches a given property of that object

╄→гoц情女王★ 提交于 2019-12-13 20:15:33
问题 I have a List of Leave object, the properties of Leave are leaveDate (java.util.Date), leaveTime(int), leaveType(String). Now to check whether or not that List has a node whose property leaveDate matches with timeStamp, timeStamp is another Date object, we can Iterate through that list. Is there any other way to do it? I also have the following condition checker : if (Lambda.select(this.fullLeaves, Lambda.having(Lambda.on(Leave.class).getLeaveDate(), Matchers.equalTo(timeStamp))).size() == 0)

Asynchronous execution in BlockingQueue

强颜欢笑 提交于 2019-12-13 19:33:30
问题 I am using Java collections BlockingQueue for data processing. The current code looks like while(true){ if(queue.size() > 0) handle(queue.take()) } Is there a way (in Java or other frameworks) where I can process it asynchronously, like, queue.setHandler(new Handler<E>()); somewhere down the class.. class Handler implements IHandler<E>{ void handle(E e){ handle(e) } } 来源: https://stackoverflow.com/questions/32793159/asynchronous-execution-in-blockingqueue

Pass varray variables into stored procedure - basic

余生颓废 提交于 2019-12-13 19:13:39
问题 Hello I am a php developer, trying to get going with Oracle. So I need to pass a collection of variables into an Oracle stored procedure. So as a basic try, I am trying to access a procedure which would accept three parameters, out of which two would be varrays, but when I pass the declared varrays, I am getting an error. I am pretty sure, it is something to do with a little syntax, but i am not able to figure out that thing. Below is my table schema and stored procedure: create table emails

Arraylist - compiler is confusing me

陌路散爱 提交于 2019-12-13 17:17:36
问题 For some reason, when I compile this simple code, an error pops up. (If I had 10 rep I would post it) It basically says (File Directory) uses unchecked or unsafe operations. Recompile with -Xlint: unchecked for details. I experimented a little and it seems if I take away the Bin.add() the error goes away. Can someone explain what I should do? import java.util.ArrayList; public class Summoned_Bin { ArrayList Bin = new ArrayList(); Summoned_Bin() { } void addToBin() { Summon summoned = new

Remove Duplicates from List of HashMap Entries

房东的猫 提交于 2019-12-13 16:50:04
问题 I have a List<HashMap<String,Object>> which represents a database where each list record is a database row. I have 10 columns in my database. There are several rows where the values of 2 particular columns are equals. I need to remove the duplicates from the list after the list is updated with all the rows from database. What is the efficient way? FYI - I am not able to do distinct while querying the database, because the GroupName is added at a later stage to the Map after the database is

Java : PriorityQueue queue results and natural ordering

早过忘川 提交于 2019-12-13 16:18:29
问题 I know, queue follow FIFO (First in first out) order, but I am not sure why the following output appears with below java sample program JAVA Sample public static void main(String args[]) { Queue<String> q = new PriorityQueue<String>(); q.add("3"); q.add("1"); q.add("2"); Iterator<String> itr = q.iterator(); while (itr.hasNext()) { System.out.println(itr.next() + " "); } } OUTPUT : 1 3 2 As per Java doc of java.util.PriorityQueue.PriorityQueue() Creates a PriorityQueue with the default initial

synchronized collection thread safety

妖精的绣舞 提交于 2019-12-13 15:50:32
问题 I have System.Collections.Generic.SynchronizedCollection shared collection. Our code uses .Net 4.0 Task library to span threads and pass the synchronized collection to the thread. So far threads has not been adding or removing items into the collection. But the new requirement which requires one of the thread has to remove items from the collection while the other thread just read the collection. Do I need to add lock before removing the items from the Collection? If so, would reader thread

Is there an STL-Multiset equivalent container in Java?

穿精又带淫゛_ 提交于 2019-12-13 15:31:47
问题 I'm still seeking an ideal solution to this question. To summarize, I am modeling a power subsystem in Java and I need a Directed-Acyclic-Graph (DAG)-type container for my data. I found exactly what I need in C++'s Standard Template Library (STL). It is the multiset, which supports storing multiple data values for the same key. I can clearly see how storing power nodes and keys, and their upstream/downstream connections as values, could be pulled off with this data structure. My customer has