1 /*** 2 * Redistribution and use in source and binary forms, with or without 3 * modification, are permitted provided that the following conditions are 4 * met : 5 * 6 * . Redistributions of source code must retain the above copyright 7 * notice, this list of conditions and the following disclaimer. 8 * 9 * . Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * . The name of the author may not be used to endorse or promote products 14 * derived from this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 25 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 * 28 * $Id: Direction.java,v 1.7 2005/09/10 11:23:52 mat007 Exp $ 29 */ 30 31 package jtge.util.grid.direction; 32 33 /*** 34 * Provides direction common behaviours. 35 * 36 * @author Jean-Laurent Fabre de Morlhon 37 * @version $Id: Direction.java,v 1.7 2005/09/10 11:23:52 mat007 Exp $ 38 */ 39 public abstract class Direction implements IDirection 40 { 41 /*** 42 * The north direction. 43 */ 44 public static final Direction NORTH = new North(); 45 /*** 46 * The north east direction. 47 */ 48 public static final Direction NORTH_EAST = new NorthEast(); 49 /*** 50 * The east direction. 51 */ 52 public static final Direction EAST = new East(); 53 /*** 54 * The south east direction. 55 */ 56 public static final Direction SOUTH_EAST = new SouthEast(); 57 /*** 58 * The south direction. 59 */ 60 public static final Direction SOUTH = new South(); 61 /*** 62 * The south west direction. 63 */ 64 public static final Direction SOUTH_WEST = new SouthWest(); 65 /*** 66 * The west direction. 67 */ 68 public static final Direction WEST = new West(); 69 /*** 70 * The north west direction. 71 */ 72 public static final Direction NORTH_WEST = new NorthWest(); 73 private final String name; 74 private final String shortName; 75 76 /*** 77 * Create a direction. 78 * 79 * @param name the name 80 * @param shortName the short name 81 */ 82 public Direction( final String name, final String shortName ) 83 { 84 this.name = name; 85 this.shortName = shortName; 86 } 87 88 /*** 89 * {@inheritDoc} 90 */ 91 public final String getName() 92 { 93 return name; 94 } 95 96 /*** 97 * {@inheritDoc} 98 */ 99 public final String getShortName() 100 { 101 return shortName; 102 } 103 104 /*** 105 * {@inheritDoc} 106 */ 107 public final int hashCode() 108 { 109 return shortName.hashCode(); 110 } 111 112 /*** 113 * {@inheritDoc} 114 */ 115 public final boolean equals( final Object object ) 116 { 117 if( object == null ) 118 return false; 119 if( !(object instanceof Direction) ) 120 return false; 121 return ((Direction)object).shortName.equals( shortName ); 122 } 123 124 /*** 125 * {@inheritDoc} 126 */ 127 public final String toString() 128 { 129 return name; 130 } 131 }