Interface Relation<W>

Type Parameters:
W - Type of the weights.
All Known Subinterfaces:
AutoRelation<W>
All Known Implementing Classes:
FastUnweightedAutoRelation, FastUnweightedPairwiseRelation, FastUnweightedRelation, FastWeightedAutoRelation, FastWeightedPairwiseRelation, FastWeightedRelation

public interface Relation<W>
A relation between two different sets of objects.
  • Method Summary

    Modifier and Type Method Description
    boolean addFirstItem​(int firstIdx)
    Adds a new item to the relation (if it does not previously exist).
    boolean addRelation​(int firstIdx, int secondIdx, W weight)
    Adds a new relation (if it does not previously exist)
    boolean addSecondItem​(int secondIdx)
    Adds a new second item to the relation (if it does not previously exist).
    boolean containsPair​(int firstIdx, int secondIdx)
    Returns whether there is a relation between two objects.
    java.util.stream.IntStream firstsWithSeconds()
    Obtains the elements in first set with relations to the ones in the second.
    java.util.stream.Stream<java.lang.Integer> getAllFirst()
    Gets all the elements of the first type.
    java.util.stream.Stream<java.lang.Integer> getAllSecond()
    Gets all the elements of the second type.
    java.util.stream.Stream<IdxValue<W>> getIdsFirst​(int secondIdx)
    Gets all the identifiers of items related to a second identifier.
    java.util.stream.Stream<IdxValue<W>> getIdsSecond​(int firstdIdx)
    Gets all the identifiers of items related to a first identifier.
    java.util.stream.IntStream getIsolatedFirsts()
    Get the set of elements in the first set without relations with elements.
    java.util.stream.IntStream getIsolatedSeconds()
    Get the set of elements in the second set without relations with elements.
    W getValue​(int firstIdx, int secondIdx)
    Obtains the weight of a relation.
    boolean hasFirsts​(int secondIdx)
    Checks whether the second element has relations with some first element.
    boolean hasSeconds​(int firstIdx)
    Checks whether the first element has relations with some second element.
    int numFirst()
    Gets the total number of elements of the first item in the relation.
    int numFirst​(int secondIdx)
    Gets the total number of elements of the first item related to a second item.
    int numSecond()
    Gets the total number of elements of the second item in the relation.
    int numSecond​(int firstIdx)
    Gets the total number of elements of the second item related to a first item.
    boolean removePair​(int firstIdx, int secondIdx)
    Removes a pair.
    java.util.stream.IntStream secondsWithFirsts()
    Obtains the elements in second set with relations to the ones in the first.
    default boolean updatePair​(int firstIdx, int secondIdx, W weight)
    Updates the weight of a pair.
    boolean updatePair​(int firstIdx, int secondIdx, W weight, boolean createRelation)
    Updates the weight of a pair.
  • Method Details

    • numFirst

      int numFirst()
      Gets the total number of elements of the first item in the relation.
      Returns:
      the number of different elements of the first item in the relation.
    • numFirst

      int numFirst​(int secondIdx)
      Gets the total number of elements of the first item related to a second item.
      Parameters:
      secondIdx - Identifier of the second item.
      Returns:
      the first item count.
    • numSecond

      int numSecond()
      Gets the total number of elements of the second item in the relation.
      Returns:
      the number of different elements of the second item in the relation.
    • numSecond

      int numSecond​(int firstIdx)
      Gets the total number of elements of the second item related to a first item.
      Parameters:
      firstIdx - Identifier of the first item.
      Returns:
      the second item count.
    • getAllFirst

      java.util.stream.Stream<java.lang.Integer> getAllFirst()
      Gets all the elements of the first type.
      Returns:
      A stream containing all the elements.
    • getAllSecond

      java.util.stream.Stream<java.lang.Integer> getAllSecond()
      Gets all the elements of the second type.
      Returns:
      A stream containing all the elements.
    • getIdsFirst

      java.util.stream.Stream<IdxValue<W>> getIdsFirst​(int secondIdx)
      Gets all the identifiers of items related to a second identifier.
      Parameters:
      secondIdx - Identifier of the second object.
      Returns:
      A stream containing all the weights of the first items.
    • getIdsSecond

      java.util.stream.Stream<IdxValue<W>> getIdsSecond​(int firstdIdx)
      Gets all the identifiers of items related to a first identifier.
      Parameters:
      firstdIdx - Identifier of the first object.
      Returns:
      A stream containing all the weights of the second items.
    • addFirstItem

      boolean addFirstItem​(int firstIdx)
      Adds a new item to the relation (if it does not previously exist).
      Parameters:
      firstIdx - Identifier of the first item.
      Returns:
      true if everything went OK, false if it did previously exist, or something went wrong.
    • addSecondItem

      boolean addSecondItem​(int secondIdx)
      Adds a new second item to the relation (if it does not previously exist).
      Parameters:
      secondIdx - Identifier of the second item.
      Returns:
      true if everything went OK, false if it did previously exist, or something went wrong.
    • addRelation

      boolean addRelation​(int firstIdx, int secondIdx, W weight)
      Adds a new relation (if it does not previously exist)
      Parameters:
      firstIdx - Identifier of the first object.
      secondIdx - Identifier of the second object.
      weight - Weight of the relation.
      Returns:
      true if everything went OK, false if it did previously exist, or something went wrong.
    • getValue

      W getValue​(int firstIdx, int secondIdx)
      Obtains the weight of a relation.
      Parameters:
      firstIdx - Identifier of the first object.
      secondIdx - Identifier of the second object.
      Returns:
      the weight if it exists, NaN if not.
    • containsPair

      boolean containsPair​(int firstIdx, int secondIdx)
      Returns whether there is a relation between two objects.
      Parameters:
      firstIdx - Identifier of the first object.
      secondIdx - Identifier of the second object
      Returns:
      true if it exists, false otherwise.
    • updatePair

      default boolean updatePair​(int firstIdx, int secondIdx, W weight)
      Updates the weight of a pair. If the relation does not previously exist, then it fails.
      Parameters:
      firstIdx - Index of the first element.
      secondIdx - Index of the second element.
      weight - Weight of the link.
      Returns:
      true if everything went ok, false if not.
    • updatePair

      boolean updatePair​(int firstIdx, int secondIdx, W weight, boolean createRelation)
      Updates the weight of a pair.
      Parameters:
      firstIdx - Index of the first element.
      secondIdx - Index of the second element.
      weight - New weight for the element.
      createRelation - If true, adds the new relation.
      Returns:
      true if everything went ok, false if not.
    • removePair

      boolean removePair​(int firstIdx, int secondIdx)
      Removes a pair.
      Parameters:
      firstIdx - Index of the first element.
      secondIdx - Index of the second element.
      Returns:
      true if everything went ok, false if not.
    • firstsWithSeconds

      java.util.stream.IntStream firstsWithSeconds()
      Obtains the elements in first set with relations to the ones in the second.
      Returns:
      the elements in first set with relations to the ones in the second.
    • secondsWithFirsts

      java.util.stream.IntStream secondsWithFirsts()
      Obtains the elements in second set with relations to the ones in the first.
      Returns:
      the elements in second set with relations to the ones in the first.
    • hasSeconds

      boolean hasSeconds​(int firstIdx)
      Checks whether the first element has relations with some second element.
      Parameters:
      firstIdx - the index of the first element.
      Returns:
      true if it has, false otherwise.
    • hasFirsts

      boolean hasFirsts​(int secondIdx)
      Checks whether the second element has relations with some first element.
      Parameters:
      secondIdx - The index of the second element.
      Returns:
      true if it has, false otherwise.
    • getIsolatedFirsts

      java.util.stream.IntStream getIsolatedFirsts()
      Get the set of elements in the first set without relations with elements. in the second.
      Returns:
      the elements in the first set without relations with elements. in the second.
    • getIsolatedSeconds

      java.util.stream.IntStream getIsolatedSeconds()
      Get the set of elements in the second set without relations with elements. in the first.
      Returns:
      the elements in the second set without relations with elements. in the first.