Package org.eclipse.jgit.lib
Class PersonIdent
- java.lang.Object
-
- org.eclipse.jgit.lib.PersonIdent
-
- All Implemented Interfaces:
Serializable
public class PersonIdent extends Object implements 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 Constructor Description PersonIdent(String aName, String aEmailAddress)
Construct a newPersonIdent
with current time.PersonIdent(String aName, String aEmailAddress, long aWhen, int aTZ)
Construct aPersonIdent
.PersonIdent(String aName, String aEmailAddress, Instant aWhen, ZoneId zoneId)
Construct a PersonIdent from simple dataPersonIdent(String aName, String aEmailAddress, Date aWhen, TimeZone aTZ)
Construct a PersonIdent from simple dataPersonIdent(String aName, String aEmailAddress, ProposedTimestamp when)
Construct a newPersonIdent
with current time.PersonIdent(PersonIdent pi)
Copy aPersonIdent
.PersonIdent(PersonIdent pi, long aWhen, int aTZ)
Copy a PersonIdent, but alter the clone's time stampPersonIdent(PersonIdent pi, Instant aWhen)
Copy aPersonIdent
, but alter the clone's time stampPersonIdent(PersonIdent pi, Date aWhen)
Copy aPersonIdent
, but alter the clone's time stampPersonIdent(PersonIdent pi, Date when, TimeZone tz)
Copy a PersonIdent, but alter the clone's time stampPersonIdent(Repository repo)
Creates new PersonIdent from config info in repository, with current time.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
appendSanitized(StringBuilder r, String str)
Sanitize the given string for use in an identity and append to output.static void
appendTimezone(StringBuilder r, int offset)
Format a timezone offset.boolean
equals(Object o)
String
getEmailAddress()
Get email address of personString
getName()
Get name of personTimeZone
getTimeZone()
Get this person's declared time zonestatic 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.Date
getWhen()
Get timestampInstant
getWhenAsInstant()
Get when attribute as instantZoneId
getZoneId()
Get the time zone idint
hashCode()
String
toExternalString()
Format for Git storage.String
toString()
-
-
-
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
- aRepository
object.
-
PersonIdent
public PersonIdent(PersonIdent pi)
Copy aPersonIdent
.- Parameters:
pi
- OriginalPersonIdent
-
PersonIdent
public PersonIdent(String aName, String aEmailAddress)
Construct a newPersonIdent
with current time.
-
PersonIdent
public PersonIdent(String aName, String aEmailAddress, ProposedTimestamp when)
Construct a newPersonIdent
with current time.- Parameters:
aName
- aString
object.aEmailAddress
- aString
object.when
- aProposedTimestamp
object.- Since:
- 4.6
-
PersonIdent
public PersonIdent(PersonIdent pi, Date when, TimeZone tz)
Copy a PersonIdent, but alter the clone's time stamp- Parameters:
pi
- originalPersonIdent
when
- local timetz
- time zone
-
PersonIdent
public PersonIdent(PersonIdent pi, Date aWhen)
Copy aPersonIdent
, but alter the clone's time stamp- Parameters:
pi
- originalPersonIdent
aWhen
- local time
-
PersonIdent
public PersonIdent(PersonIdent pi, Instant aWhen)
Copy aPersonIdent
, but alter the clone's time stamp- Parameters:
pi
- originalPersonIdent
aWhen
- local time as Instant- Since:
- 6.1
-
PersonIdent
public PersonIdent(String aName, String aEmailAddress, Date aWhen, TimeZone aTZ)
Construct a PersonIdent from simple data
-
PersonIdent
public PersonIdent(String aName, String aEmailAddress, Instant aWhen, ZoneId zoneId)
Construct a PersonIdent from simple data
-
PersonIdent
public PersonIdent(PersonIdent pi, long aWhen, int aTZ)
Copy a PersonIdent, but alter the clone's time stamp- Parameters:
pi
- originalPersonIdent
aWhen
- local time stampaTZ
- time zone
-
PersonIdent
public PersonIdent(String aName, String aEmailAddress, long aWhen, int aTZ)
Construct aPersonIdent
.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 oftoExternalString()
may not return an equivalent instance.
-
-
Method Detail
-
getTimeZone
public static TimeZone getTimeZone(int tzOffset)
Get timezone object for the given offset.- Parameters:
tzOffset
- timezone offset as ingetTimeZoneOffset()
.- Returns:
- time zone object for the given offset.
- Since:
- 4.1
-
appendTimezone
public static void appendTimezone(StringBuilder r, int offset)
Format a timezone offset.- Parameters:
r
- string builder to append to.offset
- timezone offset as ingetTimeZoneOffset()
.- Since:
- 4.1
-
appendSanitized
public static void appendSanitized(StringBuilder r, 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 functionstrbuf_addstr_without_crud
.- Parameters:
r
- string builder to append to.str
- input string.- Since:
- 4.4
-
getName
public String getName()
Get name of person- Returns:
- Name of person
-
getEmailAddress
public String getEmailAddress()
Get email address of person- Returns:
- email address of person
-
getWhen
public Date getWhen()
Get timestamp- Returns:
- timestamp
-
getWhenAsInstant
public Instant getWhenAsInstant()
Get when attribute as instant- Returns:
- timestamp
- Since:
- 6.1
-
getTimeZone
public TimeZone getTimeZone()
Get this person's declared time zone- Returns:
- this person's declared time zone; null if time zone is unknown.
-
getZoneId
public 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.
-
toExternalString
public String toExternalString()
Format for Git storage.- Returns:
- a string in the git author format
-
-