FileDocCategorySizeDatePackage
ZoneField.javaAPI DocphoneME MR2 API (J2ME)5991Wed May 02 18:00:42 BST 2007gov.nist.javax.sdp.fields

ZoneField

public class ZoneField extends SDPField
Zone SDP field.
version
JSR141-PUBLIC-REVIEW (subject to change). This code is in the public domain.

Fields Summary
protected SDPObjectList
zoneAdjustments
Zone adjustments.
Constructors Summary
public ZoneField()
Default onstructor.

	super(ZONE_FIELD);
	zoneAdjustments = new SDPObjectList();
    
Methods Summary
public voidaddZoneAdjustment(ZoneAdjustment za)
Adds an element to the zone adjustment list.

param
za zone adjustment to add.

	zoneAdjustments.addElement(za);
    
public java.lang.Objectclone()
Copies the current instance.

return
the copy of this object

	ZoneField retval = new ZoneField();
	retval.zoneAdjustments = 
	    (SDPObjectList) this.zoneAdjustments.clone();
	return retval;
    
public java.lang.Stringencode()
Encodes this structure into a canonical form.

return
encoded string of object contents

	StringBuffer retval = new StringBuffer(ZONE_FIELD);
	for (int i = 0; i < zoneAdjustments.size(); i++) {
	    ZoneAdjustment za = (ZoneAdjustment)
		zoneAdjustments.elementAt(i);
	    if (i > 0) retval.append(Separators.SP);
	    retval.append(za.encode());
	}
	retval.append(Separators.NEWLINE);
	return retval.toString();
    
public booleangetTypedTime()
Returns whether the field will be output as a typed time or a integer value. Typed time is formatted as an integer followed by a unit character. The unit indicates an appropriate multiplier for the integer. The following unit types are allowed.
d - days (86400 seconds)
h - hours (3600 seconds)
m - minutes (60 seconds)
s - seconds ( 1 seconds)

return
true, if the field will be output as a typed time; false, if as an integer value.

	return false;
    
public SDPObjectListgetZoneAdjustments()
Gets the zone adjustment list.

return
the list of zone adjustments.

	return zoneAdjustments;
    
public java.util.HashtablegetZoneAdjustments(boolean create)
Returns a Hashtable of adjustment times, where: key = Date. This is the equivalent of the decimal NTP time value. value = Int Adjustment. This is a relative time value in seconds.

param
create to set
throws
SdpParseException if a parsing error occurs
return
create when true, an empty Hashtable is created, if it is null.

	Hashtable result = new Hashtable();
	SDPObjectList zoneAdjustments = getZoneAdjustments();
	ZoneAdjustment zone;
	if (zoneAdjustments == null)
	    if (create)
		return new Hashtable();
	    else return null;
	else {
	    for (int i = 0; i < zoneAdjustments.size(); i++) {
		zone = (ZoneAdjustment) zoneAdjustments.elementAt(i);
		Long l = new Long(zone.getTime());
		Integer time = new Integer((int) l.longValue());
		Date date = new Date(zone.getTime());
		result.put(date, time);
	    }
	    return result;
	}
    
public voidsetTypedTime(boolean typedTime)
Sets whether the field will be output as a typed time or a integer value. Typed time is formatted as an integer followed by a unit character. The unit indicates an appropriate multiplier for the integer. The following unit types are allowed.
d - days (86400 seconds)
h - hours (3600 seconds)
m - minutes (60 seconds)
s - seconds ( 1 seconds)

param
typedTime typedTime - if set true, the start and stop times will be output in an optimal typed time format; if false, the times will be output as integers.

	// Dummy -- feature not implemented.
    
public voidsetZoneAdjustments(java.util.Hashtable map)
Sets the Hashtable of adjustment times, where: key = Date. This is the equivalent of the decimal NTP time value. value = Int Adjustment. This is a relative time value in seconds.

param
map Hashtable to set
throws
SdpException if the parameter is null

	if (map == null) 
	    throw new SdpException("The map is null");
	else {
	    SDPObjectList zoneAdjustments = getZoneAdjustments();
	    for (Enumeration e = map.keys(); e.hasMoreElements(); ) {
		Object o = e.nextElement();
		if (o instanceof Date) {
		    Date date = (Date)o;
		    ZoneAdjustment zone = new ZoneAdjustment();
		    zone.setTime(date.getTime());
		    addZoneAdjustment(zone);
		} else
		    throw new SdpException("The map is not well-formated ");
	    }
	}