Class PersonIdent

  • All Implemented Interfaces:
    java.io.Serializable

    public class PersonIdent
    extends java.lang.Object
    implements java.io.Serializable
    A combination of a person identity and time in Git. Git combines Name + email + time + time zone to specify who wrote or committed something.
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
        PersonIdent​(java.lang.String aName, java.lang.String aEmailAddress)
      Construct a new PersonIdent with current time.
      private PersonIdent​(java.lang.String aName, java.lang.String aEmailAddress, long when)  
        PersonIdent​(java.lang.String aName, java.lang.String aEmailAddress, long aWhen, int aTZ)
      Construct a PersonIdent.
        PersonIdent​(java.lang.String aName, java.lang.String aEmailAddress, java.time.Instant aWhen, java.time.ZoneId zoneId)
      Construct a PersonIdent from simple data
        PersonIdent​(java.lang.String aName, java.lang.String aEmailAddress, java.util.Date aWhen, java.util.TimeZone aTZ)
      Construct a PersonIdent from simple data
        PersonIdent​(java.lang.String aName, java.lang.String aEmailAddress, ProposedTimestamp when)
      Construct a new PersonIdent with current time.
        PersonIdent​(PersonIdent pi)
      Copy a PersonIdent.
        PersonIdent​(PersonIdent pi, long aWhen, int aTZ)
      Copy a PersonIdent, but alter the clone's time stamp
        PersonIdent​(PersonIdent pi, java.time.Instant aWhen)
      Copy a PersonIdent, but alter the clone's time stamp
        PersonIdent​(PersonIdent pi, java.util.Date aWhen)
      Copy a PersonIdent, but alter the clone's time stamp
        PersonIdent​(PersonIdent pi, java.util.Date when, java.util.TimeZone tz)
      Copy a PersonIdent, but alter the clone's time stamp
        PersonIdent​(Repository repo)
      Creates new PersonIdent from config info in repository, with current time.
      private PersonIdent​(UserConfig config)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static void appendSanitized​(java.lang.StringBuilder r, java.lang.String str)
      Sanitize the given string for use in an identity and append to output.
      static void appendTimezone​(java.lang.StringBuilder r, int offset)
      Format a timezone offset.
      boolean equals​(java.lang.Object o)
      java.lang.String getEmailAddress()
      Get email address of person
      java.lang.String getName()
      Get name of person
      java.util.TimeZone getTimeZone()
      Get this person's declared time zone
      static java.util.TimeZone getTimeZone​(int tzOffset)
      Get timezone object for the given offset.
      int getTimeZoneOffset()
      Get this person's declared time zone as minutes east of UTC.
      java.util.Date getWhen()
      Get timestamp
      java.time.Instant getWhenAsInstant()
      Get when attribute as instant
      java.time.ZoneId getZoneId()
      Get the time zone id
      int hashCode()
      java.lang.String toExternalString()
      Format for Git storage.
      java.lang.String toString()
      • Methods inherited from class java.lang.Object

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

      • name

        private final java.lang.String name
      • emailAddress

        private final java.lang.String emailAddress
      • when

        private final long when
      • tzOffset

        private final int tzOffset
    • Constructor Detail

      • PersonIdent

        public PersonIdent​(Repository repo)
        Creates new PersonIdent from config info in repository, with current time. This new PersonIdent gets the info from the default committer as available from the configuration.
        Parameters:
        repo - a Repository object.
      • PersonIdent

        public PersonIdent​(java.lang.String aName,
                           java.lang.String aEmailAddress)
        Construct a new PersonIdent with current time.
        Parameters:
        aName - a String object.
        aEmailAddress - a String object.
      • PersonIdent

        public PersonIdent​(java.lang.String aName,
                           java.lang.String aEmailAddress,
                           ProposedTimestamp when)
        Construct a new PersonIdent with current time.
        Parameters:
        aName - a String object.
        aEmailAddress - a String object.
        when - a ProposedTimestamp object.
        Since:
        4.6
      • PersonIdent

        public PersonIdent​(PersonIdent pi,
                           java.util.Date when,
                           java.util.TimeZone tz)
        Copy a PersonIdent, but alter the clone's time stamp
        Parameters:
        pi - original PersonIdent
        when - local time
        tz - time zone
      • PersonIdent

        public PersonIdent​(PersonIdent pi,
                           java.util.Date aWhen)
        Copy a PersonIdent, but alter the clone's time stamp
        Parameters:
        pi - original PersonIdent
        aWhen - local time
      • PersonIdent

        public PersonIdent​(PersonIdent pi,
                           java.time.Instant aWhen)
        Copy a PersonIdent, but alter the clone's time stamp
        Parameters:
        pi - original PersonIdent
        aWhen - local time as Instant
        Since:
        6.1
      • PersonIdent

        public PersonIdent​(java.lang.String aName,
                           java.lang.String aEmailAddress,
                           java.util.Date aWhen,
                           java.util.TimeZone aTZ)
        Construct a PersonIdent from simple data
        Parameters:
        aName - a String object.
        aEmailAddress - a String object.
        aWhen - local time stamp
        aTZ - time zone
      • PersonIdent

        public PersonIdent​(java.lang.String aName,
                           java.lang.String aEmailAddress,
                           java.time.Instant aWhen,
                           java.time.ZoneId zoneId)
        Construct a PersonIdent from simple data
        Parameters:
        aName - a String object.
        aEmailAddress - a String object.
        aWhen - local time stamp
        zoneId - time zone id
        Since:
        6.1
      • PersonIdent

        public PersonIdent​(PersonIdent pi,
                           long aWhen,
                           int aTZ)
        Copy a PersonIdent, but alter the clone's time stamp
        Parameters:
        pi - original PersonIdent
        aWhen - local time stamp
        aTZ - time zone
      • PersonIdent

        private PersonIdent​(java.lang.String aName,
                            java.lang.String aEmailAddress,
                            long when)
      • PersonIdent

        private PersonIdent​(UserConfig config)
      • PersonIdent

        public PersonIdent​(java.lang.String aName,
                           java.lang.String aEmailAddress,
                           long aWhen,
                           int aTZ)
        Construct a PersonIdent.

        Whitespace in the name and email is preserved for the lifetime of this object, but are trimmed by toExternalString(). This means that parsing the result of toExternalString() may not return an equivalent instance.

        Parameters:
        aName - a String object.
        aEmailAddress - a String object.
        aWhen - local time stamp
        aTZ - time zone
    • Method Detail

      • getTimeZone

        public static java.util.TimeZone getTimeZone​(int tzOffset)
        Get timezone object for the given offset.
        Parameters:
        tzOffset - timezone offset as in getTimeZoneOffset().
        Returns:
        time zone object for the given offset.
        Since:
        4.1
      • appendTimezone

        public static void appendTimezone​(java.lang.StringBuilder r,
                                          int offset)
        Format a timezone offset.
        Parameters:
        r - string builder to append to.
        offset - timezone offset as in getTimeZoneOffset().
        Since:
        4.1
      • appendSanitized

        public static void appendSanitized​(java.lang.StringBuilder r,
                                           java.lang.String str)
        Sanitize the given string for use in an identity and append to output.

        Trims whitespace from both ends and special characters \n < > that interfere with parsing; appends all other characters to the output. Analogous to the C git function strbuf_addstr_without_crud.

        Parameters:
        r - string builder to append to.
        str - input string.
        Since:
        4.4
      • getName

        public java.lang.String getName()
        Get name of person
        Returns:
        Name of person
      • getEmailAddress

        public java.lang.String getEmailAddress()
        Get email address of person
        Returns:
        email address of person
      • getWhen

        public java.util.Date getWhen()
        Get timestamp
        Returns:
        timestamp
      • getWhenAsInstant

        public java.time.Instant getWhenAsInstant()
        Get when attribute as instant
        Returns:
        timestamp
        Since:
        6.1
      • getTimeZone

        public java.util.TimeZone getTimeZone()
        Get this person's declared time zone
        Returns:
        this person's declared time zone; null if time zone is unknown.
      • getZoneId

        public java.time.ZoneId getZoneId()
        Get the time zone id
        Returns:
        the time zone id
        Since:
        6.1
      • getTimeZoneOffset

        public int getTimeZoneOffset()
        Get this person's declared time zone as minutes east of UTC.
        Returns:
        this person's declared time zone as minutes east of UTC. If the timezone is to the west of UTC it is negative.
      • hashCode

        public int hashCode()

        Hashcode is based only on the email address and timestamp.

        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • toExternalString

        public java.lang.String toExternalString()
        Format for Git storage.
        Returns:
        a string in the git author format
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object