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 |
---|
void | addCategory(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.String | asString()
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 boolean | equals(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 AddressInfo | getAddressInfo()
return addressInfo;
|
java.lang.String[] | getCategories()
return categories;
|
public java.lang.String | getDescription()
return description;
|
public java.lang.String | getName()
return name;
|
public QualifiedCoordinates | getQualifiedCoordinates()
return coordinates;
|
int | getRecordId()
return recordId;
|
java.lang.String | getStoreName()
return storeName;
|
boolean | isInCategory(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;
|
void | removeCategories()
categories = new String[0];
|
void | removeCategory(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 void | setAddressInfo(AddressInfo addressInfo)
this.addressInfo = addressInfo;
|
public void | setDescription(java.lang.String description)
this.description = description;
|
public void | setName(java.lang.String name)
if (name == null) {
throw new NullPointerException();
}
this.name = name;
|
public void | setQualifiedCoordinates(QualifiedCoordinates coordinates)
this.coordinates = coordinates;
|
void | setRecordId(int recordId)
this.recordId = recordId;
|
void | setStoreName(java.lang.String storeName)
this.storeName = storeName;
|
private void | writePossiblyNull(java.io.DataOutputStream data, java.lang.String value)
if (value == null) {
data.writeBoolean(false);
} else {
data.writeBoolean(true);
data.writeUTF(value);
}
|