collections

Guava CacheBuilder: imply additional conditions to entity removal

ぃ、小莉子 提交于 2019-12-23 17:06:58
问题 I want: Remove entity when both conditions are true timeout expired some external conditions are true Question: How should I imply additional removal conditions besides timeout? Or how can I restore entity from removal listener (see code below)? My code (which already remove based on timeout only): LoadingCache<String, Integer> ints = CacheBuilder.newBuilder() .maximumSize(10000) .expireAfterAccess(ACCESS_TIMEOUT, TimeUnit.MILLISECONDS) .removalListener( new RemovalListener() { public void

What interface to I need to implement to allow ForEach in VBA on a COM object written in delphi?

馋奶兔 提交于 2019-12-23 15:48:15
问题 Imagine I want to do something like this in VBA (pseudocode), and assuming my has an enumerable property IDList: Dim MyObject object set MyObject= CreateObject("MyObjectClass") for each Item as integer in MyObject.IDList Debug.Write(Cstr(Item) & ";") Next What would my property IDList have to look like in Delphi? Simply deriving it from IEnumerable<integer> or IEnumerable does not seem to do the job. Base code In order to avoid trouble with the default IENum and IEnum<T> interfaces I have

How to test for null keys on any Java map implementation?

寵の児 提交于 2019-12-23 15:44:14
问题 I would like to ensure that a Map being passed as an argument to a method doesn't include null keys. One would assume that the following would do: if ( map.containsKey(null) ) … but that will break if the method is passed something like a TreeMap , which per the general Java Map contract is free to reject null keys with a NPE. Do we have a sensible way to test for null keys while accepting any Map implementation? 回答1: boolean hasAnyNull = yourMap.keySet() .stream() .anyMatch(Objects::isNull);

Why Array list increase dynamically and not decrease dynamically [closed]

夙愿已清 提交于 2019-12-23 15:33:05
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . I have a simple doubt , Arraylist increase its size with factor ( 2,1.5 or old_capacity*3/2 +1 or what ever) as it got full , and add

Do something when exactly one option is non-empty

做~自己de王妃 提交于 2019-12-23 15:27:33
问题 I want to compute something if exactly one of two options is non-empty. Obviously this could be done by a pattern match, but is there some better way? (o1, o2) match { case (Some(o), None) => Some(compute(o)) case (None, Some(o)) => Some(compute(o)) case _ => None } 回答1: You could do something like this: if (o1.isEmpty ^ o2.isEmpty) List(o1,o2).flatMap(_.map(x=>Some(compute(x)))).head else None But pattern matching is probably the better way to go. 回答2: Thanks to helpful comments from @Suma,

ConcurrentDictionary doesn't seem to mark elements for GC when they are removed

混江龙づ霸主 提交于 2019-12-23 15:10:31
问题 I was surprised to find that my app memory footprint kept growing - the longer it run, the more memory it consumed. So with some magic of windbg I pinpointed a problem to my little LRU cache based on ConcurrentDictionary . The CD has bunch of benefits that were very cool for me (one of which is that its data never ends up in LOH). TryAdd and TryRemove are two methods used to add and evict items. !gcroot of some older element lead me back to my cache. Some investigation with ILSpy led me to

Parse out monthly items from a collection of DateTime objects

蓝咒 提交于 2019-12-23 12:56:26
问题 I previously asked this question to take a oollection of datetime objects and group them by dayOfweek and time So just to recap: I take a collection of DateTime List<DateTime> collectionOfDateTime = GetDateColletion(); and then grouping by dayofWeek and time of day by doing this var byDayOfWeek = collectionOfDateTime.GroupBy(dt => dt.DayOfWeek + "-" + dt.Hour + "-" + dt.Minute); So at this point, I have these grouped by week (consistent time) working perfectly. I now have a new requirement to

Multi-Assignment based on Collection

假如想象 提交于 2019-12-23 12:52:08
问题 Edit originally the question was "Collection to Tuple" as I assumed I needed a tuple in order to do variable multi-assignment. It turns out that one can do variable multi-assignment directly on collections. Retitled the question accordingly. Original Have a simple Seq[String] derived from a regex that I would like to convert to a Tuple. What's the most direct way to do so? I currently have: val(clazz, date) = captures match { case x: Seq[String] => (x(0), x(1)) } Which is ok, but my routing

Java combination of Set and List interfaces

谁都会走 提交于 2019-12-23 12:46:56
问题 I have a data structure, for which I am currently using an ArrayList . I realised that in this structure I do not want any duplicates to be present. My first thought was to use some form of set, however the order is also important. After a bit of googling and searching the Collections docs I found LinkedHashSet which almost does the job. Unfortunately, one of the primary reasons for preserving order is because I am using the get(int index) method of the ArrayList for random access, and I can

High performance, lock free Java collection with very specific requirements

本小妞迷上赌 提交于 2019-12-23 12:35:14
问题 What would be a suitable candidate for a high-performance concurrent collection with the following requirements: The number of elements in the collection is small (a few elements, usually less than 10) and rarely changes. The main use case is iterating through the elements. This happens a lot and must be super fast (i.e. should be lock free). Occasionally an element will be removed by use of the iterator remove() method. This should preferably also work very fast (but it's less significant