groovy/groovy-core — pull request #482 by yukoba (2014-07-12 04:33:20+00:00)
Title: Add immutable collections

Add immutable collections.
Immutable collections are convenient for backtracking algorithms.

The implementation is based on Blackdrag's PCollections.
http://pcollections.org/

As the license of PCollections is MIT license,
it can be merged to Groovy, which is Apache license.

I modified API, and wrote unit tests, and fixed bugs.

What I changed.
1. All the public class names start with `Immutable`.
2. All the implementation classes are package scope and marked Serializable.
3. `Empty` class is renamed to `ImmutableCollections`.
4. `ImmutableCollections` can create not only empty collections, but also convert from a `Iterable` to a immutable collection. HashTreePBag, HashTreePMap and HashTreePSet, which are static convenience classes, are removed.
5. `PVector` is renamed to `ImmutableList`.
6. `POrderedSet` is renamed to `ImmutableListSet`. The name `ListSet` comes from Scala. I didn't use the name `OrderedSet` because it does not have a comparator.
7. `minus()` of PCollections can remove an element and also can remove a specified position element, but this API creates bugs on using `ImmutableList`. Therefore I changed one to `minusAt()`. For consistency, I also renamed to `plusAt()`. And `with()` is renamed to `replaceAt()`.
8. Removed `PSequence` interface. `ImmutableStack` extends `ImmutableList` like `Stack` extends `List`.
9. A new instance can be created by `[] as ImmutableList`.
10. `Iterator` of `ImmutableList` and `ImmutableStack` are same as the original, but `ListIterator` is backed by `Object[]`. I think this is faster than the original.
11. Added `getAt()` to `ImmutableList`, `ImmutableStack` and `ImmutaleListSet`.
12. `DefaultGroovyMethods.plus()` , `minus()`, `multiply()` can handle `ImmutableCollections`.
13. `minus(no argument)` of `ImmutableQueue` is renamed to `tail()`.
14. Renamed `Collection.asImmutable()` to `Collection.asUnmodifiable()`, and deprecated the original method.
15. Implemented `Object[] as Queue` and `Object[] as Stack`.