001 /* 002 * Created on Jan 22, 2011 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 005 * the License. You may obtain a copy of the License at 006 * 007 * http://www.apache.org/licenses/LICENSE-2.0 008 * 009 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 010 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 011 * specific language governing permissions and limitations under the License. 012 * 013 * Copyright @2011 the original author or authors. 014 */ 015 package org.fest.assertions.data; 016 017 import static org.fest.util.Objects.HASH_CODE_PRIME; 018 019 /** 020 * Represents a location in (x, y) coordinate space, specified in integer precision. 021 * 022 * @author Yvonne Wang 023 */ 024 public class Point { 025 026 /** 027 * Creates a new </code>{@link Point}</code>. 028 * @param x the x coordinate. 029 * @param y the y coordinate. 030 * @return the created {@code Point}. 031 */ 032 public static Point atPoint(int x, int y) { 033 return new Point(x, y); 034 } 035 036 /** The x coordinate. */ 037 public final int x; 038 039 /** The y coordinate. */ 040 public final int y; 041 042 private Point(int x, int y) { 043 this.x = x; 044 this.y = y; 045 } 046 047 @Override public boolean equals(Object obj) { 048 if (this == obj) return true; 049 if (obj == null) return false; 050 if (getClass() != obj.getClass()) return false; 051 Point other = (Point) obj; 052 if (x != other.x) return false; 053 return y == other.y; 054 } 055 056 @Override public int hashCode() { 057 int result = 1; 058 result = HASH_CODE_PRIME * result + x; 059 result = HASH_CODE_PRIME * result + y; 060 return result; 061 } 062 063 @Override public String toString() { 064 return String.format("[%d, %d]", x, y); 065 } 066 }