Make List interface more Collection-like

Issue #139 new
Görel Hedin created an issue

Add operations like:

aList.addAll(collection)
if (aList.isEmpty()) ...

Remove the recently added List constructor new List(aCollection). It is better to use addAll.

Comments (3)

  1. Görel Hedin reporter

    Added List.addAll(Collection) in ef4f345

    The addAll operation adds the children one by one, using addChild. It would be possible to optimize this by changing the internal children array directly to be the appropriate size. However, this would involve creating a new internal operation similar to setChild (but that can add many children). This is a complex operation with many hooks for incremental evaluation. So this seems like a too complex thing to do, and that would result in complex partly duplicated code in the jastadd code generator, and that would be difficult to maintain. So for this reason, I decided to not optimize this operation.

  2. Jesper Mattsson

    When adding methods from Collection, you might want to consider actually letting List implement Collection. That would be useful in many situations.

  3. Ismail Badawi

    Having switched to Java 8 recently, I did something like this:

    aspect Stream {
      public Stream<T> ASTNode.stream() {
        return StreamSupport.stream(spliterator(), false);
      }
    } 
    

    This works since ASTNode implements Iterable, and makes it so you can write node.stream() and use the java.util.stream APIs. I think this addresses most of the frustrations I've had when dealing with Lists instead of java.util.Lists.

  4. Log in to comment