Concurrent Set Queue

If you want better concurrency than full synchronization, there is one way I know of to do it, using a ConcurrentHashMap as the backing map. The following is a sketch only. public final class ConcurrentHashSet<E> extends ForwardingSet<E> implements Set<E>, Queue<E> { private enum Dummy { VALUE } private final ConcurrentMap<E, Dummy> map; ConcurrentHashSet(ConcurrentMap<E, Dummy> map) … Read more

What are the benefits of the Iterator interface in Java?

Why is this interface used? Because it supports the basic operations that would allow a client programmer to iterate over any kind of collection (note: not necessarily a Collection in the Object sense). Why are the methods… not directly coded to the data structure implementation itself? They are, they’re just marked Private so you can’t … Read more

Publishing/subscribing multiple subsets of the same server collection

Could you not just use the same query client-side when you want to look at the items? In a lib directory: enabledItems = function() { return Items.find({enabled: true}); } processedItems = function() { return Items.find({processed: true}); } On the server: Meteor.publish(‘enabled_items’, function() { return enabledItems(); }); Meteor.publish(‘processed_items’, function() { return processedItems(); }); On the client … Read more

Which .Net collection for adding multiple objects at once and getting notified?

It seems that the INotifyCollectionChanged interface allows for updating when multiple items were added, so I’m not sure why ObservableCollection<T> doesn’t have an AddRange. You could make an extension method for AddRange, but that would cause an event for every item that is added. If that isn’t acceptable you should be able to inherit from … Read more

Is there any reason EnumMap and EnumSet are not Navigable

Many “obvious” features are missing from the JDK and its various APIs. Why this particular feature was omitted / forgotten? We can only guess. But your question has been a RFE at Sun/Oracle for a long time: https://bugs.java.com/bugdatabase/view_bug?bug_id=6278287 http://www.java.net/node/644910 You could support those RFEs by commenting on them. Note, here’s an authoritative answer by Joshua … Read more

How do I easily convert from one collection type to another during a filter, map, flatMap in Scala?

Using breakOut Use breakOut as the CanBuildFrom and let the typer know what you want your result type to be (unfortunately you need to specify String here) scala> import collection.breakOut import collection.breakOut scala> List(1, 2, 3) res0: List[Int] = List(1, 2, 3) scala> res0.map(_.toString)(breakOut) : Vector[String] res2: Vector[String] = Vector(1, 2, 3) Using to[Collection] (starting … Read more

Make dictionary read only in C#

It would be as easy as casting the whole dictionary reference to IReadOnlyDictionary<string, IReadOnlyList<string>> because Dictionary<TKey, TValue> implements IReadOnlyDictionary<TKey, TValue>. BTW, you can’t do that because you want the List<string> values as IReadOnlyList<string>. So you need something like this: var readOnlyDict = (IReadOnlyDictionary<string, IReadOnlyList<string>>)dict .ToDictionary(pair => pair.Key, pair => pair.Value.AsReadOnly()); Immutable dictionaries This is just … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)