Record Class Jid

java.lang.Object
java.lang.Record
it.auties.whatsapp.model.jid.Jid
All Implemented Interfaces:
JidProvider

public record Jid(String user, JidServer server, int device, int agent) extends Record implements JidProvider
A model class that represents a jid. This class is only a model, this means that changing its values will have no real effect on WhatsappWeb's servers.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final int
    The field for the agent record component.
    private final int
    The field for the device record component.
    private final JidServer
    The field for the server record component.
    private final String
    The field for the user record component.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Jid(String user, JidServer server, int device, int agent)
    Default constructor
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns the value of the agent record component.
    int
    Returns the value of the device record component.
    final boolean
    Indicates whether some other object is "equal to" this one.
    boolean
    Returns whether this jid specifies an agent
    boolean
    Returns whether this jid specifies a device
    int
    Returns a hash code value for this object.
    boolean
    Returns whether this jid ends with the provided server
    boolean
    Returns whether this jid is associated with a companion device
    boolean
    Returns whether this jid is a server jid
    static Jid
    of(long jid)
    Constructs a new ContactId for a user from a jid
    static Jid
    of(String jid)
    Constructs a new ContactId for a user from a jid
    static Jid
    of(String jid, JidServer server)
    Constructs a new ContactId for a user from a jid and a custom server
    static Jid
    ofDevice(String jid, int device)
    Constructs a new ContactId for a device
    static Jid
    ofDevice(String jid, int device, int agent)
    Constructs a new ContactId for a device
    static Jid
     
    static Jid
    Constructs a new ContactId that represents a server
    Returns the value of the server record component.
    Returns this object as a jid
    Converts this jid to a non-formatted phone number
     
    Converts this jid to a signal address
    Converts this jid to a String
    private static int
     
    Returns the type of this jid
    Returns the value of the user record component.
    Converts this jid to a user jid
    static String
    Parses a nullable jid to the Whatsapp Jid Format
    Returns a new jid using with a different server

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • user

      private final String user
      The field for the user record component.
    • server

      private final JidServer server
      The field for the server record component.
    • device

      private final int device
      The field for the device record component.
    • agent

      private final int agent
      The field for the agent record component.
  • Constructor Details

    • Jid

      public Jid(String user, JidServer server, int device, int agent)
      Default constructor
  • Method Details

    • ofServer

      public static Jid ofServer(JidServer server)
      Constructs a new ContactId that represents a server
      Parameters:
      server - the non-null custom server
      Returns:
      a non-null contact jid
    • ofProtobuf

      public static Jid ofProtobuf(String input)
    • of

      public static Jid of(String jid, JidServer server)
      Constructs a new ContactId for a user from a jid and a custom server
      Parameters:
      jid - the nullable jid of the user
      server - the non-null custom server
      Returns:
      a non-null contact jid
    • withoutServer

      public static String withoutServer(String jid)
      Parses a nullable jid to the Whatsapp Jid Format
      Parameters:
      jid - the nullable jid to parse
      Returns:
      null if jid == null, otherwise a non-null string
    • tryParseAgent

      private static int tryParseAgent(String string)
    • ofDevice

      public static Jid ofDevice(String jid, int device, int agent)
      Constructs a new ContactId for a device
      Parameters:
      jid - the nullable jid of the user
      device - the device jid
      agent - the agent jid
      Returns:
      a non-null contact jid
    • ofDevice

      public static Jid ofDevice(String jid, int device)
      Constructs a new ContactId for a device
      Parameters:
      jid - the nullable jid of the user
      device - the device jid
      Returns:
      a non-null contact jid
    • toProtobufValue

      public String toProtobufValue()
    • of

      public static Jid of(String jid)
      Constructs a new ContactId for a user from a jid
      Parameters:
      jid - the non-null jid of the user
      Returns:
      a non-null contact jid
    • of

      public static Jid of(long jid)
      Constructs a new ContactId for a user from a jid
      Parameters:
      jid - the non-null jid of the user
      Returns:
      a non-null contact jid
    • type

      public JidType type()
      Returns the type of this jid
      Returns:
      a non null type
    • isCompanion

      public boolean isCompanion()
      Returns whether this jid is associated with a companion device
      Returns:
      true if this jid is a companion
    • hasServer

      public boolean hasServer(JidServer server)
      Returns whether this jid ends with the provided server
      Parameters:
      server - the server to check against
      Returns:
      a boolean
    • isServerJid

      public boolean isServerJid(JidServer server)
      Returns whether this jid is a server jid
      Parameters:
      server - the server to check against
      Returns:
      a boolean
    • withServer

      public Jid withServer(JidServer server)
      Returns a new jid using with a different server
      Parameters:
      server - the new server
      Returns:
      a non-null jid
    • withoutDevice

      public Jid withoutDevice()
      Converts this jid to a user jid
      Returns:
      a non-null jid
    • toPhoneNumber

      public String toPhoneNumber()
      Converts this jid to a non-formatted phone number
      Returns:
      a non-null String
    • toString

      public String toString()
      Converts this jid to a String
      Specified by:
      toString in class Record
      Returns:
      a non-null String
    • toSignalAddress

      public SessionAddress toSignalAddress()
      Converts this jid to a signal address
      Returns:
      a non-null SessionAddress
    • toJid

      public Jid toJid()
      Returns this object as a jid
      Specified by:
      toJid in interface JidProvider
      Returns:
      a non-null jid
    • hasDevice

      public boolean hasDevice()
      Returns whether this jid specifies a device
      Returns:
      a boolean
    • hasAgent

      public boolean hasAgent()
      Returns whether this jid specifies an agent
      Returns:
      a boolean
    • hashCode

      public int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • user

      public String user()
      Returns the value of the user record component.
      Returns:
      the value of the user record component
    • server

      public JidServer server()
      Returns the value of the server record component.
      Returns:
      the value of the server record component
    • device

      public int device()
      Returns the value of the device record component.
      Returns:
      the value of the device record component
    • agent

      public int agent()
      Returns the value of the agent record component.
      Returns:
      the value of the agent record component