FileDocCategorySizeDatePackage
LandmarkImpl.javaAPI DocphoneME MR2 API (J2ME)10201Wed May 02 18:00:40 BST 2007com.sun.j2me.location

LandmarkImpl

public class LandmarkImpl extends Object
This class is an implementation of the Landmark class defined by the JSR-179 specification.

Fields Summary
String[]
categories
int
recordId
String
storeName
String
name
String
description
QualifiedCoordinates
coordinates
AddressInfo
addressInfo
Constructors Summary
public LandmarkImpl(String name, String description, QualifiedCoordinates coordinates, AddressInfo addressInfo)


    // JAVADOC COMMENT ELIDED
         
		     
		      
        setName(name);
        this.description = description;
        this.coordinates = coordinates;
        this.addressInfo = addressInfo;
    
LandmarkImpl(LandmarkImpl lm)

        this(lm.serialize(), lm.recordId, lm.storeName);
    
LandmarkImpl(byte[] serializedForm, int recordId, String storeName)

        try {
            this.recordId = recordId;
            this.storeName = storeName;
            DataInputStream stream = new 
		DataInputStream(new ByteArrayInputStream(serializedForm));
            if (stream.readBoolean()) {
                int field;
                addressInfo = new AddressInfo();
                while ((field = stream.readInt()) != 0) {
                    addressInfo.setField(field, stream.readUTF());
                }
            }
            if (stream.readBoolean()) {
                float verticalAccuracy = stream.readFloat();
                float horizontalAccuracy = stream.readFloat();
                float altitude = stream.readFloat();
                double longitude = stream.readDouble();
                double latitude = stream.readDouble();
                coordinates = new QualifiedCoordinates(latitude, longitude,
						       altitude,
						       horizontalAccuracy,
						       verticalAccuracy);
            }
            if (stream.readBoolean()) {
                description = stream.readUTF();
            }
            if (stream.readBoolean()) {
                name = stream.readUTF();
            }
            int categoryCount = stream.readInt();
            categories = new String[categoryCount];
            for (int iter = 0; iter < categoryCount; iter++) {
                if (stream.readBoolean()) {
                    categories[iter] = stream.readUTF();
                }
            }
            stream.close();
        } catch (IOException err) {
            // this should never occur
            err.printStackTrace();
        }
    
Methods Summary
voidaddCategory(java.lang.String category)

        String[] categories = new String[this.categories.length + 1];
        System.arraycopy(this.categories, 0, categories, 0, 
			 this.categories.length);
        this.categories = categories;
        categories[categories.length - 1] = category;
    
java.lang.StringasString()

        StringBuffer buf = new StringBuffer();
        for (int i = 0; i < categories.length; i++) {
            if (i > 0) buf.append("; ");
            buf.append(categories[i]);
        }
        String coordinates;
        if (this.coordinates != null) {
            coordinates = "Lat: " + this.coordinates.getLatitude() +
		" Lon: " + this.coordinates.getLongitude();
        } else {
            coordinates = "null";
        }
        return "Landmark: { storeName = " + storeName +
	    " recordId = " + recordId +
	    " name = " + name +
	    " description = " + description +
	    " coordinates = " + coordinates +
	    " addressInfo = " + addressInfo +
            " categories = " + buf.toString() + " }";
    
public booleanequals(java.lang.Object o)

        if (!(o instanceof LandmarkImpl)) {
            return false;
        }
        if (this == o) {
            return true;
        }
        LandmarkImpl lm = (LandmarkImpl)o;
        boolean idEquals = recordId == lm.recordId;
        boolean storeEquals = (storeName == lm.storeName) ||
	    ((storeName != null) && storeName.equals(lm.storeName));
        return idEquals && storeEquals;
    
public AddressInfogetAddressInfo()

        return addressInfo;
    
java.lang.String[]getCategories()

        return categories;
    
public java.lang.StringgetDescription()

        return description;
    
public java.lang.StringgetName()

        return name;
    
public QualifiedCoordinatesgetQualifiedCoordinates()

        return coordinates;
    
intgetRecordId()

        return recordId;
    
java.lang.StringgetStoreName()

        return storeName;
    
booleanisInCategory(java.lang.String category)

        if (category == null) {
            category = "";
        }
        for (int iter = 0; iter < categories.length; iter++) {
            if (category.equals(categories[iter])) {
                return true;
            }
        }
        return false;
    
voidremoveCategories()

	categories = new String[0];
    
voidremoveCategory(java.lang.String category)

        if (category == null) {
            category = "";
        }
        String[] categories = new String[this.categories.length - 1];
        int count = 0;
        for (int iter = 0; iter < this.categories.length; iter++) {
            if (!category.equals(this.categories[iter])) {
                if (count == categories.length) {
                    // the category to remove is not within the array
                    return;
                }
                categories[count] = this.categories[iter];
                count++;
            }
        }
        this.categories = categories;
    
byte[]serialize()

        try {
            ByteArrayOutputStream stream = new ByteArrayOutputStream(100);
            DataOutputStream data = new DataOutputStream(stream);
            if (addressInfo != null) {
                data.writeBoolean(true);
                for (int i = AddressInfo.EXTENSION; 
                    i <= AddressInfo.PHONE_NUMBER; i++) {
                    String info = addressInfo.getField(i);
                    if (info != null) {
                        data.writeInt(i);
                        data.writeUTF(info);
                    }
                }
                data.writeInt(0);
            } else {
                data.writeBoolean(false);
            }
            if (coordinates == null) {
                data.writeBoolean(false);
            } else {
                data.writeBoolean(true);
                data.writeFloat(coordinates.getVerticalAccuracy());
                data.writeFloat(coordinates.getHorizontalAccuracy());
                data.writeFloat(coordinates.getAltitude());
                data.writeDouble(coordinates.getLongitude());
                data.writeDouble(coordinates.getLatitude());
            }
            writePossiblyNull(data, description);
            writePossiblyNull(data, name);
            data.writeInt(categories.length);
            for (int iter = 0; iter < categories.length; iter++) {
                writePossiblyNull(data, categories[iter]);
            }
            byte[] returnVal = stream.toByteArray();
            data.close();
            return returnVal;
        } catch (IOException err) {
            // this should never occur
            err.printStackTrace();
            return null;
        }
    
public voidsetAddressInfo(AddressInfo addressInfo)

        this.addressInfo = addressInfo;
    
public voidsetDescription(java.lang.String description)

        this.description = description;
    
public voidsetName(java.lang.String name)

        if (name == null) {
            throw new NullPointerException();
        }
        this.name = name;
    
public voidsetQualifiedCoordinates(QualifiedCoordinates coordinates)

        this.coordinates = coordinates;
    
voidsetRecordId(int recordId)

        this.recordId = recordId;
    
voidsetStoreName(java.lang.String storeName)

        this.storeName = storeName;
    
private voidwritePossiblyNull(java.io.DataOutputStream data, java.lang.String value)

            if (value == null) {
                data.writeBoolean(false);
            } else {
                data.writeBoolean(true);
                data.writeUTF(value);
            }