Skip to content

Simplify EdgeIteratorState #2691

Open
Open

Description

@otbutz

The number of methods needed to implement the interface is quite high. Most of them are EncodedValue setters/getters.

We have 5 methods per subclass:

public interface EdgeIteratorState {

    // ....

    int get(IntEncodedValue property);

    EdgeIteratorState set(IntEncodedValue property, int value);

    int getReverse(IntEncodedValue property);

    EdgeIteratorState setReverse(IntEncodedValue property, int value);

    EdgeIteratorState set(IntEncodedValue property, int fwd, int bwd);

    // ....
}

The last one seems to be an optimization which is mainly used in unittests and could be implemented as a default method instead:

    default EdgeIteratorState set(IntEncodedValue property, int fwd, int bwd) {
        return set(property, fwd).setReverse(property, bwd);
    }

With default methods we could also improve handling of directions:

public interface EdgeIteratorState {

    enum Direction { FWD, BWD };

    // ....

    default int get(IntEncodedValue property) {
        return get(property, FWD);
    }

    default int getReverse(IntEncodedValue property) {
        return get(property, BWD);
    }

    int get(IntEncodedValue property, Direction direction);

    default EdgeIteratorState set(IntEncodedValue property, int value) {
        return set(property, FWD, value);
    }

    default EdgeIteratorState setReverse(IntEncodedValue property, int value) {
        return set(property, BWD, value);
    }

    EdgeIteratorState set(IntEncodedValue property, Direction direction, int value);

    // ....
}

As a result implementations would only need to implement two methods per EV instead of 5.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions