Package com.dd.plist
Class NSDate
- java.lang.Object
-
- com.dd.plist.NSObject
-
- com.dd.plist.NSDate
-
- All Implemented Interfaces:
java.lang.Cloneable,java.lang.Comparable<NSObject>
public class NSDate extends NSObject
The NSDate class wraps a date.- See Also:
- Foundation NSDate documentation
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Datedateprivate static longEPOCHprivate static java.text.SimpleDateFormatsdfDefaultprivate static java.text.SimpleDateFormatsdfGnuStep-
Fields inherited from class com.dd.plist.NSObject
ASCII_LINE_LENGTH, NEWLINE
-
-
Constructor Summary
Constructors Constructor Description NSDate(byte[] bytes)Creates new NSDate instance from its binary representation.NSDate(byte[] bytes, int startIndex, int endIndex)Creates a new NSDate instance from its binary representation.NSDate(java.lang.String textRepresentation)Creates a new NSDate instance from is textual representation.NSDate(java.util.Date d)Creates a new NSDate instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description NSDateclone()Creates and returns a deep copy of this instance.intcompareTo(NSObject o)booleanequals(java.lang.Object obj)java.util.DategetDate()Gets the date.inthashCode()private static java.lang.StringmakeDateString(java.util.Date date)Generates a string representation of a Java Date object.private static java.lang.StringmakeDateStringGnuStep(java.util.Date date)Generates a string representation of a Java Date object.private static java.util.DateparseDateString(java.lang.String textRepresentation)Parses a date string and creates a Java Date object from it.protected voidtoASCII(java.lang.StringBuilder ascii, int level)Generates the ASCII representation of this object.protected voidtoASCIIGnuStep(java.lang.StringBuilder ascii, int level)Generates the ASCII representation of this object in the GnuStep format.(package private) voidtoBinary(BinaryPropertyListWriter out)Generates the binary representation of the object.java.lang.ObjecttoJavaObject()Converts this NSObject into an equivalent object of the Java Runtime Environment.java.lang.StringtoString()Generates a string representation of the date.(package private) voidtoXML(java.lang.StringBuilder xml, int level)Generates the XML representation of the object (without XML headers or enclosing plist-tags).-
Methods inherited from class com.dd.plist.NSObject
assignIDs, fromJavaObject, indent, toJavaObject, toXMLPropertyList
-
-
-
-
Field Detail
-
date
private final java.util.Date date
-
EPOCH
private static final long EPOCH
- See Also:
- Constant Field Values
-
sdfDefault
private static final java.text.SimpleDateFormat sdfDefault
-
sdfGnuStep
private static final java.text.SimpleDateFormat sdfGnuStep
-
-
Constructor Detail
-
NSDate
public NSDate(byte[] bytes)
Creates new NSDate instance from its binary representation.- Parameters:
bytes- The binary date representation.
-
NSDate
public NSDate(byte[] bytes, int startIndex, int endIndex)Creates a new NSDate instance from its binary representation.- Parameters:
bytes- The byte array containing the date data.startIndex- The index within the array at which the date data begins.endIndex- The index within the array at which the data date ends.
-
NSDate
public NSDate(java.lang.String textRepresentation) throws java.text.ParseExceptionCreates a new NSDate instance from is textual representation. The textual representation must adhere to one of the following patterns. For XML property lists:yyyy-MM-dd'T'HH:mm:ss'Z'For ASCII property lists:yyyy-MM-dd HH:mm:ss Z- Parameters:
textRepresentation- The textual representation of the date.- Throws:
java.text.ParseException- If the date could not be parsed, i.e. it does not match the expected pattern.
-
NSDate
public NSDate(java.util.Date d)
Creates a new NSDate instance.- Parameters:
d- The date.
-
-
Method Detail
-
parseDateString
private static java.util.Date parseDateString(java.lang.String textRepresentation) throws java.text.ParseExceptionParses a date string and creates a Java Date object from it. This function is synchronized because the underlying SimpleDateFormat instances are not thread-safe.- Parameters:
textRepresentation- The date string as found in an ASCII or XML property list- Returns:
- The parsed Date
- Throws:
java.text.ParseException- If the given string cannot be parsed.- See Also:
DateFormat.parse(java.lang.String)
-
makeDateString
private static java.lang.String makeDateString(java.util.Date date)
Generates a string representation of a Java Date object. The string is formatted according to the specification for XML property list dates.- Parameters:
date- The date which should be represented.- Returns:
- The string representation of the date.
-
makeDateStringGnuStep
private static java.lang.String makeDateStringGnuStep(java.util.Date date)
Generates a string representation of a Java Date object. The string is formatted according to the specification for GnuStep ASCII property list dates.- Parameters:
date- The date which should be represented.- Returns:
- The string representation of the date.
-
getDate
public java.util.Date getDate()
Gets the date.- Returns:
- The date.
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
clone
public NSDate clone()
Description copied from class:NSObjectCreates and returns a deep copy of this instance.
-
toXML
void toXML(java.lang.StringBuilder xml, int level)Description copied from class:NSObjectGenerates the XML representation of the object (without XML headers or enclosing plist-tags).
-
toBinary
void toBinary(BinaryPropertyListWriter out) throws java.io.IOException
Description copied from class:NSObjectGenerates the binary representation of the object.
-
toString
public java.lang.String toString()
Generates a string representation of the date.- Overrides:
toStringin classjava.lang.Object- Returns:
- A string representation of the date.
- See Also:
Date.toString()
-
toJavaObject
public java.lang.Object toJavaObject()
Description copied from class:NSObjectConverts this NSObject into an equivalent object of the Java Runtime Environment.NSArrayobjects are converted to arrays.NSDictionaryobjects are converted to objects extending theMapclass.NSSetobjects are converted to objects extending theSetclass.NSNumberobjects are converted to primitive number values (int, long, double or boolean).NSStringobjects are converted toStringobjects.NSDataobjects are converted to byte arrays.NSDateobjects are converted toDateobjects.UIDobjects are converted to byte arrays.
- Specified by:
toJavaObjectin classNSObject- Returns:
- A native java object representing this NSObject's value.
-
compareTo
public int compareTo(NSObject o)
-
toASCII
protected void toASCII(java.lang.StringBuilder ascii, int level)Description copied from class:NSObjectGenerates the ASCII representation of this object. The generated ASCII representation does not end with a newline. Complies with the Old-Style ASCII Property Lists definition.
-
toASCIIGnuStep
protected void toASCIIGnuStep(java.lang.StringBuilder ascii, int level)Description copied from class:NSObjectGenerates the ASCII representation of this object in the GnuStep format. The generated ASCII representation does not end with a newline.- Specified by:
toASCIIGnuStepin classNSObject- Parameters:
ascii- TheStringBuilderonto which the ASCII representation is appended.level- The indentation level of the object.
-
-