Interface IdBuilder<K>

  • All Known Subinterfaces:
    IdBuilderInt
    Functional Interface:
    This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

    @FunctionalInterface
    public interface IdBuilder<K>
    Builder for unique identifiers of vertices or edges in a graph.

    A Graph allows adding vertices by either providing an identifier (Graph.addVertex(Object)) or without (Graph.addVertex()). If no identifier is provided, the graph will generate one using an instance of this interface. The same is true for edges, see Graph.addEdge(Object, Object, Object) and Graph.addEdge(Object, Object). The graph expose its vertex and edge builders using Graph.vertexBuilder() and Graph.edgeBuilder(), which may return null. The identifiers returned by this interface must be unique in the graph.

    This interface is shared for both vertices and edges, but an instance of this interface is used only for one of them at a time.

    Author:
    Barak Ugav
    • Method Detail

      • build

        K build​(Set<K> existing)
        Builds a unique identifier for a vertex or an edge.
        Parameters:
        existing - the identifiers of the vertices or edges already in the graph
        Returns:
        a unique identifier
      • defaultBuilder

        static <K> IdBuilder<K> defaultBuilder​(Class<K> idType)
        Get an default builder for identifiers of the given type.

        A default builder existing for the following types:

        For the latter case, the builder will create a new instance using the constructor, and the newly created instance must no be equal to any of the existing identifiers. This is most suitable for types that do not override the default Object.equals(Object) method.

        The returned builder may be passed to GraphFactory.setVertexBuilder(IdBuilder).

        Type Parameters:
        K - the type of the identifiers
        Parameters:
        idType - the id type class
        Returns:
        a default builder for identifiers of idType
        Throws:
        IllegalArgumentException - if the type is not supported
      • defaultFactory

        static <K> Supplier<IdBuilder<K>> defaultFactory​(Class<K> idType)
        Get an default factory for identifiers of the given type.

        A default factory existing for the following types:

        For the latter case, the factory will create a new instance using the constructor, and the newly created instance must no be equal to any of the existing identifiers. This is most suitable for types that do not override the default Object.equals(Object) method.

        The returned factory may be passed to GraphFactory.setVertexFactory(Supplier).

        Type Parameters:
        K - the type of the identifiers
        Parameters:
        idType - the id type class
        Returns:
        a default factory for identifiers of idType
        Throws:
        IllegalArgumentException - if the type is not supported