www.pudn.com > GMapViewer-src.zip > MapPin.java



package org.sreid.j2me.gmapviewer;

import org.sreid.j2me.util.Util;

class MapPin {
	final int x, y;
	String text = "";
	int rmsID = -1;
	boolean isPermanent = true; // false for search results

	MapPin(int x, int y) {
		this.x = x;
		this.y = y;
	}

	MapPin(byte[] data, int off, int len) {
		this.x = Util.bytesToInt(data, off+0);
		this.y = Util.bytesToInt(data, off+4);
		this.text = new String(data, off+8, len-8);
	}

	int toBytes(byte[] data, int off) {
		Util.intToBytes(x, data, off+0);
		Util.intToBytes(y, data, off+4);
		byte[] tmp = text.getBytes();
		System.arraycopy(tmp, 0, data, off+8, tmp.length);
		return 8 + tmp.length;
	}

	public String toString() {
		return "MapPin[" + x + "x" + y + ": " + text + "]";
	}

	public boolean equals(Object o) {
		if (o == this) return true;
		if (o == null || !(o instanceof MapPin)) return false;
		MapPin mp = (MapPin)o;
		return mp.x == x && mp.y == y && mp.text.equals(text);
	}
}