Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package bLO3dTree;
- import threeDPoint.ThreeDPoint;
- public class BLO3dTreeLeafNode extends BLO3dTreeNode {
- private ThreeDPoint[] points = new ThreeDPoint[4];
- private String[] labels = new String[4];
- private int size = 0;
- /** ** * * ** ** * ** * * ** ** * ** * ** * ** * * ** * ** * ** ** * *
- * @return the label associated to aPoint (using fuzzy tests for float equality)
- * or return null if aPoint not present
- * @param aPoint the point whose label is wanted
- */
- public String labelPoint(ThreeDPoint aPoint) {
- if (aPoint == null) {
- return null;
- }
- int index = findIndex(aPoint);
- if (index == -1) {
- return null;
- }
- return labels[index];
- }
- /** ** * * ** ** * ** * * ** ** * ** * ** * ** * * ** * ** * ** ** * *
- * insert aPoint into the leaf with aLabel as label,
- * do so provided the leaf is not full
- * @param aPoint the point to insert
- * @param aLabel the label to associate to the point
- * @throws NullPointException when aPoint is null
- * @throws NullLabelException when aLabel is null
- * @throws DuplicatePointException when aPoint already occurs
- * @throws LeafFullException when the leaf already has 4 points
- */
- public void addPoint(ThreeDPoint aPoint, String aLabel) throws NullPointException, NullLabelException, DuplicatePointException, LeafFullException {
- if (aPoint == null) {
- throw new NullPointException();
- }
- if (aLabel == null) {
- throw new NullLabelException();
- }
- if (this.labelPoint(aPoint) != null) {
- throw new DuplicatePointException("Duplicate of point"+ aPoint.toString());
- }
- if (size==4) {
- throw new LeafFullException();
- }
- size++;
- points[size] = aPoint;
- labels[size] = aLabel;
- }
- /** ** * * ** ** * ** * * ** ** * ** * ** * ** * * ** * ** * ** ** * *
- * remove a point and its corresponding label
- * @return true if the point was present, false otherwise
- * @param aPoint the point to be removed
- */
- public Boolean removePoint(ThreeDPoint aPoint) {
- int index = findIndex(aPoint);
- if (index == -1) {
- return false;
- }
- for (int i = index+1; i<size; i++) {
- points[i-1] = points[i];
- labels[i-1] = labels[i];
- }
- size--;
- return true;
- }
- /** ** * * ** ** * ** * * ** ** * ** * ** * ** * * ** * ** * ** ** * *
- * @return the index where aPoint occurs, or -1 otherwise
- * (using fuzzy tests for float equality)
- * @param aPoint the point whose index is wanted
- * @require aPoint not null
- */
- private int findIndex(ThreeDPoint aPoint) {
- for (int i = 0; i < size; i++) {
- ThreeDPoint point = points[i];
- if (point.fuzzyEquals(aPoint)) {
- return i;
- }
- }
- return -1;
- }
- /**
- * @return an array with points
- */
- public ThreeDPoint[] getPoints() {
- ThreeDPoint[] result = new ThreeDPoint[size];
- for (int i = 0; i < size; i++) {
- result[i] = points[i];
- }
- return result;
- }
- /**
- * @return an array with labels
- */
- public String[] getLabels() {
- String[] result = new String[size];
- for (int i = 0; i < size; i++) {
- result[i] = labels[i];
- }
- return result;
- }
- /**
- * @return the size
- */
- public int getSize() {
- return size;
- }
- /**
- * check if the leaf already contains 4 points
- * @return true when the leaf is already full
- */
- public Boolean isFull() {
- return (size == 4);
- }
- public BLO3dTreeLeafNode(int aLevel) {
- super(aLevel);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement