Idea: Combined TCollection interface

Issue #33 new
Andre Bogus created an issue

Defining parts of the Collection interfaces for each component type despite the fact that they have nothing to do with the component type seems wasteful. Also if someone wanted to have multiple implementations of a class using a T*Collection and abstract out the collection type, they need to wrap all the used methods into abstract methods.

Thus, having a parent interface with the methods not burdened with the component type could be helpful and remove duplication (javadoc omitted):

interface TCollection {
    boolean isEmpty();
    int size();
    boolean equals(Object o);
    int hashCode;
    void clear();
    void reverse();
    void sort();
    void sort(int from, int until);
    void shuffle(Random random);
}

Comments (3)

  1. Rob Eden

    We could do:

    interface TCollection {
        boolean isEmpty();
        int size();
        void clear();
    }
    
    interface TList {
        void reverse();
        void sort();
        void sort(int from, int to);
        void shuffle(Random random);
    }
    
  2. Andre Bogus reporter

    You're right, TCollections are unordered and thus should not be reversible/sortable/shuffleable. Looks good.

  3. Andre Bogus reporter

    I just wanted to add that T*Maps could also implement TCollection, as they don't have any other methods that aren't key- or value-related.

  4. Log in to comment