Class Communities<U>

java.lang.Object
es.uam.eps.ir.relison.sna.community.Communities<U>
Type Parameters:
U - type of the nodes.

public class Communities<U>
extends java.lang.Object
Class that relates the nodes of a graph with communities.
  • Field Summary

    Fields 
    Modifier and Type Field Description
    private java.util.List<java.util.List<U>> commUsers
    Indicates the list of users of the communities.
    private it.unimi.dsi.fastutil.objects.Object2IntMap<U> userComm
    Indicates the community the user belongs to.
  • Constructor Summary

    Constructors 
    Constructor Description
    Communities()
    Constructor.
  • Method Summary

    Modifier and Type Method Description
    boolean add​(U user, int comm)
    Adds a pair user/community.
    void addCommunity()
    Adds a new community to the list.
    java.util.stream.IntStream getCommunities()
    Obtains the different communities of the graph.
    int getCommunity​(U user)
    Gets the community a given user belongs to.
    int getCommunitySize​(int community)
    Obtains the size of a community.
    int getNumCommunities()
    Obtains the number of communities.
    java.util.stream.Stream<U> getUsers​(int community)
    Gets the users inside a community.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • userComm

      private final it.unimi.dsi.fastutil.objects.Object2IntMap<U> userComm
      Indicates the community the user belongs to.
    • commUsers

      private final java.util.List<java.util.List<U>> commUsers
      Indicates the list of users of the communities.
  • Constructor Details

  • Method Details

    • getNumCommunities

      public int getNumCommunities()
      Obtains the number of communities.
      Returns:
      The number of communities.
    • getCommunities

      public java.util.stream.IntStream getCommunities()
      Obtains the different communities of the graph.
      Returns:
      an int stream containing the diferent communities of the graph.
    • getCommunity

      public int getCommunity​(U user)
      Gets the community a given user belongs to.
      Parameters:
      user - The user.
      Returns:
      The community if the user exists, -1 if it does not exist.
    • getUsers

      public java.util.stream.Stream<U> getUsers​(int community)
      Gets the users inside a community.
      Parameters:
      community - The community.
      Returns:
      a stream containing the users in the community if exists, an empty stream if not.
    • addCommunity

      public void addCommunity()
      Adds a new community to the list.
    • add

      public boolean add​(U user, int comm)
      Adds a pair user/community.
      Parameters:
      user - The new user. It must not be already in the object.
      comm - The associated community. The community has to previously exist.
      Returns:
      true if everything goes OK, false if not.
    • getCommunitySize

      public int getCommunitySize​(int community)
      Obtains the size of a community.
      Parameters:
      community - The community whose size we want to obtain.
      Returns:
      the size of the community if it exists, 0 if it does not.