TwoDRangeSearchList

TwoDRangeSearchList - public boolean...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
/* * TITLE: COMP202 PA4 * * @(#)TwoDRangeSearchList 2009/04/10 * @author Attila Gursoy * * Copyright (c) 2009 Attila Gursoy * All Rights Reserved. */ package pa4; import java.util.*; public class TwoDRangeSearchList<X extends Comparable<? super X>, Y extends Comparable<? super Y>> implements RangeSearch2D<X,Y> { private class LocalPair implements RangeSearch2D.Pair<X,Y> { private X x; private Y y; public LocalPair(X first, Y second) { x = first; y = second; } public X getX() { return x;} public Y getY() { return y;} public boolean equals(Object rhs) { if ( ! (rhs instanceof RangeSearch2D.Pair) ) return false; LocalPair p = (LocalPair) rhs; return (x.compareTo(p.x)== 0 & y.compareTo(p.y)==0); } public String toString() { return "(" + x + " " + y + ")"; } } public TwoDRangeSearchList() { head = new ArrayList<RangeSearch2D.Pair<X,Y>>(); size = 0; } private int size; private List<RangeSearch2D.Pair<X,Y>> head;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: public boolean insert(RangeSearch2D.Pair<X,Y> p) { head.add(p); return true; } public boolean contains(RangeSearch2D.Pair<X,Y> p) { return head.contains(p); } public List<RangeSearch2D.Pair<X,Y>> getRange(RangeSearch2D.Pair<X,Y> l,RangeSearch2D.Pair<X,Y> u) { List<RangeSearch2D.Pair<X,Y>> result = new ArrayList<RangeSearch2D.Pair<X,Y>>(); for (RangeSearch2D.Pair<X,Y> p: head){ if ( (p.getX().compareTo(l.getX()) >= 0 ) && (p.getX().compareTo(u.getX()) <= 0 ) && (p.getY().compareTo(l.getY()) >= 0 ) && (p.getY().compareTo(u.getY()) <= 0) ) { result.add(p); } } return result; } public RangeSearch2D.Pair<X,Y> makePair(X x, Y y) { return new LocalPair(x,y); } public int size() {return head.size();} public boolean isEmpty() { return (size==0); } public int height() { // not used for list implementation return size(); } }...
View Full Document

This note was uploaded on 04/13/2011 for the course ENGR 202 taught by Professor Yavuzyildirim during the Spring '11 term at Boğaziçi University.

Page1 / 2

TwoDRangeSearchList - public boolean...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online