KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jscience > geography > coordinates > CompoundCoordinates


1 /*
2  * JScience - Java(TM) Tools and Libraries for the Advancement of Sciences.
3  * Copyright (C) 2006 - JScience (http://jscience.org/)
4  * All rights reserved.
5  *
6  * Permission to use, copy, modify, and distribute this software is
7  * freely granted, provided that this notice is preserved.
8  */

9 package org.jscience.geography.coordinates;
10
11 import org.jscience.geography.coordinates.crs.CompoundCRS;
12
13 /**
14  * This class represents a coordinates made up by combining
15  * two coordinates objects together.
16  *
17  * @author <a HREF="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
18  * @version 3.0, February 13, 2006
19  */

20 public class CompoundCoordinates<C1 extends Coordinates, C2 extends Coordinates>
21     extends Coordinates<CompoundCRS<C1, C2>> {
22
23     /**
24      * Holds the first coordinates.
25      */

26     private final C1 _first;
27     
28     /**
29      * Holds the next coordinates.
30      */

31     private final C2 _next;
32     
33     /**
34      * Creates a compound coordinates made up of the specified coordinates.
35      *
36      * @param first the first coordinates.
37      * @param next the next coordinates.
38      */

39     public CompoundCoordinates(C1 first, C2 next) {
40        _first = first;
41        _next = next;
42     }
43     
44     /**
45      * Returns the first coordinates.
46      *
47      * @return the first coordinates.
48      */

49     public C1 getFirst() {
50         return _first;
51     }
52     
53     /**
54      * Returns the next coordinates.
55      *
56      * @return the next coordinates.
57      */

58     public C2 getNext() {
59         return _next;
60     }
61
62     @SuppressWarnings JavaDoc("unchecked")
63     @Override JavaDoc
64     public CompoundCRS<C1, C2> getCoordinateReferenceSystem() {
65         return new CompoundCRS<C1, C2>(_first.getCoordinateReferenceSystem(),
66                 _next.getCoordinateReferenceSystem());
67     }
68
69     // OpenGIS Interface.
70
public int getDimension() {
71         return _first.getDimension() + _next.getDimension();
72     }
73
74     // OpenGIS Interface.
75
public double getOrdinate(int dimension) throws IndexOutOfBoundsException JavaDoc {
76         final int firstDimension = _first.getDimension();
77         if (dimension < firstDimension) {
78             return _first.getOrdinate(dimension);
79         } else {
80             return _next.getOrdinate(dimension - firstDimension);
81         }
82     }
83         
84 }
Popular Tags