Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/test/type/MatchLocationTest.java72
-rw-r--r--plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/MatchLocation.java (renamed from plugins/org.eclipse.osee.framework.search.engine/src/org/eclipse/osee/framework/search/engine/MatchLocation.java)38
2 files changed, 109 insertions, 1 deletions
diff --git a/plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/test/type/MatchLocationTest.java b/plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/test/type/MatchLocationTest.java
new file mode 100644
index 00000000000..00b64fa4914
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/test/type/MatchLocationTest.java
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.jdk.core.test.type;
+
+import java.util.HashMap;
+import org.eclipse.osee.framework.jdk.core.type.MatchLocation;
+import org.junit.Assert;
+
+/**
+ * Test Case for {@link MatchLocation}
+ *
+ * @author Roberto E. Escobar
+ */
+public class MatchLocationTest {
+
+ private static int a = 144;
+ private static int b = 233;
+ private static MatchLocation mapToPi = new MatchLocation(a, b);
+ private static MatchLocation mapToE = new MatchLocation(b, a);
+ private static MatchLocation alsoMapToPi = new MatchLocation(a, b);
+ private static MatchLocation alsoMapToE = new MatchLocation(b, a);
+
+ @org.junit.Test
+ public void testConstructor() {
+ Assert.assertTrue(a == mapToPi.getStartPosition());
+ Assert.assertTrue(b == mapToPi.getEndPosition());
+ Assert.assertTrue(b != mapToPi.getStartPosition());
+ Assert.assertTrue(a != mapToPi.getEndPosition());
+ }
+
+ @org.junit.Test
+ public void testEquals() {
+ Assert.assertTrue(mapToPi.equals(mapToPi));
+ Assert.assertTrue(mapToPi.equals(alsoMapToPi));
+ Assert.assertFalse(mapToPi.equals(mapToE));
+ }
+
+ @org.junit.Test
+ public void testSetters() {
+ MatchLocation newLocation = new MatchLocation(0, 0);
+ newLocation.setStartPosition(a);
+ newLocation.setEndPosition(b);
+ Assert.assertTrue(a == newLocation.getStartPosition());
+ Assert.assertTrue(b == newLocation.getEndPosition());
+ Assert.assertTrue(b != newLocation.getStartPosition());
+ Assert.assertTrue(a != newLocation.getEndPosition());
+ Assert.assertTrue(newLocation.set(a, b).equals(newLocation));
+ }
+
+ @org.junit.Test
+ public void testHashCorrectness() {
+ HashMap<MatchLocation, Double> hash = new HashMap<MatchLocation, Double>();
+ hash.put(mapToPi, Math.PI);
+ hash.put(mapToE, Math.E);
+ Assert.assertTrue(hash.get(mapToPi).equals(Math.PI));
+ Assert.assertTrue(hash.get(mapToE).equals(Math.E));
+ Assert.assertTrue(hash.get(alsoMapToPi).equals(Math.PI));
+ Assert.assertTrue(hash.get(alsoMapToE).equals(Math.E));
+ Assert.assertFalse(hash.get(mapToPi).equals(Math.E));
+ Assert.assertFalse(hash.get(mapToE).equals(Math.PI));
+ Assert.assertFalse(mapToPi.equals(mapToE));
+ Assert.assertTrue(mapToPi.equals(mapToPi));
+ }
+}
diff --git a/plugins/org.eclipse.osee.framework.search.engine/src/org/eclipse/osee/framework/search/engine/MatchLocation.java b/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/MatchLocation.java
index b2e2cd37bd4..0bc6457536f 100644
--- a/plugins/org.eclipse.osee.framework.search.engine/src/org/eclipse/osee/framework/search/engine/MatchLocation.java
+++ b/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/MatchLocation.java
@@ -8,7 +8,7 @@
* Contributors:
* Boeing - initial API and implementation
*******************************************************************************/
-package org.eclipse.osee.framework.search.engine;
+package org.eclipse.osee.framework.jdk.core.type;
/**
* @author Roberto E. Escobar
@@ -69,4 +69,40 @@ public class MatchLocation {
this.endPosition = endPosition;
}
+ public MatchLocation set(int startPosition, int endPosition) {
+ this.startPosition = startPosition;
+ this.endPosition = endPosition;
+ return this;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + endPosition;
+ result = prime * result + startPosition;
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ MatchLocation other = (MatchLocation) obj;
+ if (endPosition != other.endPosition) {
+ return false;
+ }
+ if (startPosition != other.startPosition) {
+ return false;
+ }
+ return true;
+ }
+
}

Back to the top