NAME="core" */
+ String NAME = "core";
+}
diff --git a/graphwalker-core/src/main/java/org/graphwalker/core/Machine.java b/graphwalker-core/src/main/java/org/graphwalker/core/Machine.java
new file mode 100644
index 00000000..249c9275
--- /dev/null
+++ b/graphwalker-core/src/main/java/org/graphwalker/core/Machine.java
@@ -0,0 +1,46 @@
+/*
+ * #%L
+ * GraphWalker Core
+ * %%
+ * Copyright (C) 2011 - 2013 GraphWalker
+ * %%
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ * #L%
+ */
+package org.graphwalker.core;
+
+import org.graphwalker.core.machine.ExecutionContext;
+import org.graphwalker.core.model.Element;
+import org.graphwalker.core.script.ScriptContext;
+
+import java.util.List;
+
+/**
+ * @author Nils Olsson
+ */
+public interface Machine {
+ Element getNextStep();
+ Element getCurrentStep();
+ Boolean hasNextStep();
+ ScriptContext getScriptContext();
+ void restart();
+ ExecutionContext getCurrentExecutionContext();
+ ListFULFILLMENT_LEVEL=0.999999 */
+ double FULFILLMENT_LEVEL = 0.999999;
+ /** Constant PERCENTAGE_SCALE=100 */
+ int PERCENTAGE_SCALE = 100;
+ /** Constant SECOND_SCALE=1000 */
+ int SECOND_SCALE = 1000;
+
+ boolean isFulfilled(ExecutionContext context);
+ double getFulfilment(ExecutionContext context);
+ String getValue();
+}
diff --git a/graphwalker-core/src/main/java/org/graphwalker/core/algorithm/AStar.java b/graphwalker-core/src/main/java/org/graphwalker/core/algorithm/AStar.java
new file mode 100644
index 00000000..a4c2d201
--- /dev/null
+++ b/graphwalker-core/src/main/java/org/graphwalker/core/algorithm/AStar.java
@@ -0,0 +1,154 @@
+/*
+ * #%L
+ * GraphWalker Core
+ * %%
+ * Copyright (C) 2011 - 2013 GraphWalker
+ * %%
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ * #L%
+ */
+package org.graphwalker.core.algorithm;
+
+import org.graphwalker.core.Model;
+import org.graphwalker.core.model.Element;
+import org.graphwalker.core.model.Path;
+
+import java.util.*;
+
+/**
+ * @author Nils Olsson
+ */
+public final class AStar implements Algorithm {
+
+ private final Model model;
+
+ public AStar(Model model) {
+ this.model = model;
+ }
+
+ public Pathscript.
+ * + * @return a {@link java.lang.String} object. + */ + String filter() default ""; + +} diff --git a/graphwalker-core/src/main/java/org/graphwalker/core/annotation/AfterExecution.java b/graphwalker-core/src/main/java/org/graphwalker/core/annotation/AfterExecution.java new file mode 100755 index 00000000..fdd92d6f --- /dev/null +++ b/graphwalker-core/src/main/java/org/graphwalker/core/annotation/AfterExecution.java @@ -0,0 +1,38 @@ +/* + * #%L + * GraphWalker Core + * %% + * Copyright (C) 2011 - 2012 GraphWalker + * %% + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * #L% + */ +package org.graphwalker.core.annotation; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * @author Nils Olsson + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(java.lang.annotation.ElementType.METHOD) +public @interface AfterExecution { +} diff --git a/graphwalker-core/src/main/java/org/graphwalker/core/annotation/BeforeElement.java b/graphwalker-core/src/main/java/org/graphwalker/core/annotation/BeforeElement.java new file mode 100755 index 00000000..70b2b7ee --- /dev/null +++ b/graphwalker-core/src/main/java/org/graphwalker/core/annotation/BeforeElement.java @@ -0,0 +1,46 @@ +/* + * #%L + * GraphWalker Core + * %% + * Copyright (C) 2011 - 2012 GraphWalker + * %% + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * #L% + */ +package org.graphwalker.core.annotation; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * @author Nils Olsson + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(java.lang.annotation.ElementType.METHOD) +public @interface BeforeElement { + + /** + *script.
+ * + * @return a {@link java.lang.String} object. + */ + String filter() default ""; + +} diff --git a/graphwalker-core/src/main/java/org/graphwalker/core/annotation/BeforeExecution.java b/graphwalker-core/src/main/java/org/graphwalker/core/annotation/BeforeExecution.java new file mode 100755 index 00000000..6f5bfe95 --- /dev/null +++ b/graphwalker-core/src/main/java/org/graphwalker/core/annotation/BeforeExecution.java @@ -0,0 +1,38 @@ +/* + * #%L + * GraphWalker Core + * %% + * Copyright (C) 2011 - 2012 GraphWalker + * %% + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * #L% + */ +package org.graphwalker.core.annotation; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * @author Nils Olsson + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(java.lang.annotation.ElementType.METHOD) +public @interface BeforeExecution { +} diff --git a/graphwalker-core/src/main/java/org/graphwalker/core/annotation/Edge.java b/graphwalker-core/src/main/java/org/graphwalker/core/annotation/Edge.java new file mode 100644 index 00000000..e218f296 --- /dev/null +++ b/graphwalker-core/src/main/java/org/graphwalker/core/annotation/Edge.java @@ -0,0 +1,44 @@ +/* + * #%L + * GraphWalker Core + * %% + * Copyright (C) 2011 - 2014 GraphWalker + * %% + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * #L% + */ +package org.graphwalker.core.annotation; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * @author Nils Olsson + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(java.lang.annotation.ElementType.METHOD) +public @interface Edge { + + String source() default ""; + + String target() default ""; + + String guard() default "true"; +} diff --git a/graphwalker-core/src/main/java/org/graphwalker/core/annotation/ExceptionHandler.java b/graphwalker-core/src/main/java/org/graphwalker/core/annotation/ExceptionHandler.java new file mode 100644 index 00000000..3d06c7c2 --- /dev/null +++ b/graphwalker-core/src/main/java/org/graphwalker/core/annotation/ExceptionHandler.java @@ -0,0 +1,38 @@ +/* + * #%L + * GraphWalker Core + * %% + * Copyright (C) 2011 - 2013 GraphWalker + * %% + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * #L% + */ +package org.graphwalker.core.annotation; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * @author Nils Olsson + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(java.lang.annotation.ElementType.METHOD) +public @interface ExceptionHandler { +} diff --git a/graphwalker-core/src/main/java/org/graphwalker/core/annotation/Execute.java b/graphwalker-core/src/main/java/org/graphwalker/core/annotation/Execute.java new file mode 100644 index 00000000..119677e5 --- /dev/null +++ b/graphwalker-core/src/main/java/org/graphwalker/core/annotation/Execute.java @@ -0,0 +1,79 @@ +/* + * #%L + * GraphWalker Core + * %% + * Copyright (C) 2011 - 2013 GraphWalker + * %% + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * #L% + */ +package org.graphwalker.core.annotation; + +import org.graphwalker.core.PathGenerator; +import org.graphwalker.core.StopCondition; +import org.graphwalker.core.condition.EdgeCoverage; +import org.graphwalker.core.generator.RandomPath; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * @author Nils Olsson + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface Execute { + + /** + *group.
+ * + * @return a {@link java.lang.String} object. + */ + String group() default "default"; + + /** + *pathGenerator.
+ * + * @return a {@link java.lang.Class} object. + */ + Class extends PathGenerator> pathGenerator() default RandomPath.class; + + /** + *stopCondition.
+ * + * @return a {@link java.lang.Class} object. + */ + Class extends StopCondition> stopCondition() default EdgeCoverage.class; + + /** + *stopConditionValue.
+ * + * @return a {@link java.lang.String} object. + */ + String stopConditionValue() default "100"; + + /** + *language.
+ * + * @return a {@link java.lang.String} object. + */ + String language() default "JavaScript"; +} diff --git a/graphwalker-core/src/main/java/org/graphwalker/core/annotation/GraphWalker.java b/graphwalker-core/src/main/java/org/graphwalker/core/annotation/GraphWalker.java new file mode 100755 index 00000000..5eb0ce02 --- /dev/null +++ b/graphwalker-core/src/main/java/org/graphwalker/core/annotation/GraphWalker.java @@ -0,0 +1,41 @@ +/* + * #%L + * GraphWalker Core + * %% + * Copyright (C) 2011 - 2012 GraphWalker + * %% + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * #L% + */ +package org.graphwalker.core.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * @author Nils Olsson + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface GraphWalker { + + Execute[] value() default {}; +} diff --git a/graphwalker-core/src/main/java/org/graphwalker/core/annotation/Model.java b/graphwalker-core/src/main/java/org/graphwalker/core/annotation/Model.java new file mode 100644 index 00000000..81a8375b --- /dev/null +++ b/graphwalker-core/src/main/java/org/graphwalker/core/annotation/Model.java @@ -0,0 +1,47 @@ +/* + * #%L + * GraphWalker Core + * %% + * Copyright (C) 2011 - 2013 GraphWalker + * %% + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * #L% + */ +package org.graphwalker.core.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * @author Nils Olsson + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface Model { + + /** + *file.
+ * + * @return a {@link java.lang.String} object. + */ + String file(); + +} diff --git a/graphwalker-core/src/main/java/org/graphwalker/core/annotation/Vertex.java b/graphwalker-core/src/main/java/org/graphwalker/core/annotation/Vertex.java new file mode 100644 index 00000000..109e155d --- /dev/null +++ b/graphwalker-core/src/main/java/org/graphwalker/core/annotation/Vertex.java @@ -0,0 +1,40 @@ +/* + * #%L + * GraphWalker Core + * %% + * Copyright (C) 2011 - 2014 GraphWalker + * %% + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * #L% + */ +package org.graphwalker.core.annotation; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * @author Nils Olsson + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(java.lang.annotation.ElementType.METHOD) +public @interface Vertex { + + boolean start() default false; +} diff --git a/graphwalker-core/src/main/java/org/graphwalker/core/common/Assert.java b/graphwalker-core/src/main/java/org/graphwalker/core/common/Assert.java new file mode 100644 index 00000000..e064ed02 --- /dev/null +++ b/graphwalker-core/src/main/java/org/graphwalker/core/common/Assert.java @@ -0,0 +1,975 @@ +/* + * #%L + * GraphWalker Core + * %% + * Copyright (C) 2011 - 2014 GraphWalker + * %% + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * #L% + */ +package org.graphwalker.core.common; + +import java.lang.reflect.Array; +import java.util.*; + +/** + * Repacked from testng 6.8.8 + * + * Assertion tool class. Presents assertion methods with a more natural parameter order. + * The order is always actualValue, expectedValue [, message]. + * + * @author Alexandru Popescu + */ +public class Assert { + + public static final Character OPENING_CHARACTER = '['; + public static final Character CLOSING_CHARACTER = ']'; + + public static final String ASSERT_LEFT = "expected " + OPENING_CHARACTER; + public static final String ASSERT_LEFT2 = "expected not same " + OPENING_CHARACTER; + public static final String ASSERT_MIDDLE = CLOSING_CHARACTER + " but found " + OPENING_CHARACTER; + public static final String ASSERT_RIGHT = Character.toString(CLOSING_CHARACTER); + + protected Assert() { + // hide constructor + } + + /** + * Asserts that a condition is true. If it isn't, + * an AssertionError, with the given message, is thrown. + * @param condition the condition to evaluate + * @param message the assertion error message + */ + public static void assertTrue(boolean condition, String message) { + if(!condition) { + failNotEquals(condition, Boolean.TRUE, message); + } + } + + /** + * Asserts that a condition is true. If it isn't, + * an AssertionError is thrown. + * @param condition the condition to evaluate + */ + public static void assertTrue(boolean condition) { + assertTrue(condition, null); + } + + /** + * Asserts that a condition is false. If it isn't, + * an AssertionError, with the given message, is thrown. + * @param condition the condition to evaluate + * @param message the assertion error message + */ + public static void assertFalse(boolean condition, String message) { + if(condition) { + failNotEquals(condition, Boolean.FALSE, message); // TESTNG-81 + } + } + + /** + * Asserts that a condition is false. If it isn't, + * an AssertionError is thrown. + * @param condition the condition to evaluate + */ + public static void assertFalse(boolean condition) { + assertFalse(condition, null); + } + + /** + * Fails a test with the given message and wrapping the original exception. + * + * @param message the assertion error message + * @param realCause the original exception + */ + public static void fail(String message, Throwable realCause) { + AssertionError ae = new AssertionError(message); + ae.initCause(realCause); + + throw ae; + } + + /** + * Fails a test with the given message. + * @param message the assertion error message + */ + public static void fail(String message) { + throw new AssertionError(message); + } + + /** + * Fails a test with no message. + */ + public static void fail() { + fail(null); + } + + /** + * Asserts that two objects are equal. If they are not, + * an AssertionError, with the given message, is thrown. + * @param actual the actual value + * @param expected the expected value + * @param message the assertion error message + */ + public static void assertEquals(Object actual, Object expected, String message) { + assertObjectEquals(actual, expected, message); + } + + private static void assertObjectEquals(Object actual, Object expected, String message) { + if((expected == null) && (actual == null)) { + return; + } + if(expected != null) { + if (expected.getClass().isArray()) { + assertArrayEquals(actual, expected, message); + return; + } else if (expected.equals(actual)) { + return; + } + } + failNotEquals(actual, expected, message); + } + + /** + * Asserts that two objects are equal. It they are not, an AssertionError, + * with given message, is thrown. + * @param actual the actual value + * @param expected the expected value (should be an non-null array value) + * @param message the assertion error message + */ + private static void assertArrayEquals(Object actual, Object expected, String message) { + //is called only when expected is an array + if (actual.getClass().isArray()) { + int expectedLength = Array.getLength(expected); + if (expectedLength == Array.getLength(actual)) { + for (int i = 0 ; i < expectedLength ; i++) { + Object _actual = Array.get(actual, i); + Object _expected = Array.get(expected, i); + try { + assertEquals(_actual, _expected); + } catch (AssertionError ae) { + failNotEquals(actual, expected, message == null ? "" : message + + " (values at index " + i + " are not the same)"); + } + } + //array values matched + return; + } else { + failNotEquals(Array.getLength(actual), expectedLength, message == null ? "" : message + + " (Array lengths are not the same)"); + } + } + failNotEquals(actual, expected, message); + } + + /** + * Asserts that two objects are equal. If they are not, + * an AssertionError is thrown. + * @param actual the actual value + * @param expected the expected value + */ + public static void assertEquals(Object actual, Object expected) { + assertEquals(actual, expected, null); + } + + /** + * Asserts that two Strings are equal. If they are not, + * an AssertionError, with the given message, is thrown. + * @param actual the actual value + * @param expected the expected value + * @param message the assertion error message + */ + public static void assertEquals(String actual, String expected, String message) { + assertObjectEquals(actual, expected, message); + } + + /** + * Asserts that two Strings are equal. If they are not, + * an AssertionError is thrown. + * @param actual the actual value + * @param expected the expected value + */ + public static void assertEquals(String actual, String expected) { + assertEquals(actual, expected, null); + } + + /** + * Asserts that two doubles are equal concerning a delta. If they are not, + * an AssertionError, with the given message, is thrown. If the expected + * value is infinity then the delta value is ignored. + * @param actual the actual value + * @param expected the expected value + * @param delta the absolute tolerable difference between the actual and expected values + * @param message the assertion error message + */ + public static void assertEquals(double actual, double expected, double delta, String message) { + // handle infinity specially since subtracting to infinite values gives NaN and the + // the following test fails + if(Double.isInfinite(expected)) { + if(!(expected == actual)) { + failNotEquals(actual, expected, message); + } + } + else if(!(Math.abs(expected - actual) <= delta)) { // Because comparison with NaN always returns false + failNotEquals(actual, expected, message); + } + } + + /** + * Asserts that two doubles are equal concerning a delta. If they are not, + * an AssertionError is thrown. If the expected value is infinity then the + * delta value is ignored. + * @param actual the actual value + * @param expected the expected value + * @param delta the absolute tolerable difference between the actual and expected values + */ + public static void assertEquals(double actual, double expected, double delta) { + assertEquals(actual, expected, delta, null); + } + + /** + * Asserts that two floats are equal concerning a delta. If they are not, + * an AssertionError, with the given message, is thrown. If the expected + * value is infinity then the delta value is ignored. + * @param actual the actual value + * @param expected the expected value + * @param delta the absolute tolerable difference between the actual and expected values + * @param message the assertion error message + */ + public static void assertEquals(float actual, float expected, float delta, String message) { + // handle infinity specially since subtracting to infinite values gives NaN and the + // the following test fails + if(Float.isInfinite(expected)) { + if(!(expected == actual)) { + failNotEquals(actual, expected, message); + } + } + else if(!(Math.abs(expected - actual) <= delta)) { + failNotEquals(actual, expected, message); + } + } + + /** + * Asserts that two floats are equal concerning a delta. If they are not, + * an AssertionError is thrown. If the expected + * value is infinity then the delta value is ignored. + * @param actual the actual value + * @param expected the expected value + * @param delta the absolute tolerable difference between the actual and expected values + */ + public static void assertEquals(float actual, float expected, float delta) { + assertEquals(actual, expected, delta, null); + } + + /** + * Asserts that two longs are equal. If they are not, + * an AssertionError, with the given message, is thrown. + * @param actual the actual value + * @param expected the expected value + * @param message the assertion error message + */ + public static void assertEquals(long actual, long expected, String message) { + assertEquals(Long.valueOf(actual), Long.valueOf(expected), message); + } + + /** + * Asserts that two longs are equal. If they are not, + * an AssertionError is thrown. + * @param actual the actual value + * @param expected the expected value + */ + public static void assertEquals(long actual, long expected) { + assertEquals(actual, expected, null); + } + + /** + * Asserts that two booleans are equal. If they are not, + * an AssertionError, with the given message, is thrown. + * @param actual the actual value + * @param expected the expected value + * @param message the assertion error message + */ + public static void assertEquals(boolean actual, boolean expected, String message) { + assertEquals( Boolean.valueOf(actual), Boolean.valueOf(expected), message); + } + + /** + * Asserts that two booleans are equal. If they are not, + * an AssertionError is thrown. + * @param actual the actual value + * @param expected the expected value + */ + public static void assertEquals(boolean actual, boolean expected) { + assertEquals(actual, expected, null); + } + + /** + * Asserts that two bytes are equal. If they are not, + * an AssertionError, with the given message, is thrown. + * @param actual the actual value + * @param expected the expected value + * @param message the assertion error message + */ + public static void assertEquals(byte actual, byte expected, String message) { + assertEquals(Byte.valueOf(actual), Byte.valueOf(expected), message); + } + + /** + * Asserts that two bytes are equal. If they are not, + * an AssertionError is thrown. + * @param actual the actual value + * @param expected the expected value + */ + public static void assertEquals(byte actual, byte expected) { + assertEquals(actual, expected, null); + } + + /** + * Asserts that two chars are equal. If they are not, + * an AssertionFailedError, with the given message, is thrown. + * @param actual the actual value + * @param expected the expected value + * @param message the assertion error message + */ + public static void assertEquals(char actual, char expected, String message) { + assertEquals(Character.valueOf(actual), Character.valueOf(expected), message); + } + + /** + * Asserts that two chars are equal. If they are not, + * an AssertionError is thrown. + * @param actual the actual value + * @param expected the expected value + */ + public static void assertEquals(char actual, char expected) { + assertEquals(actual, expected, null); + } + + /** + * Asserts that two shorts are equal. If they are not, + * an AssertionFailedError, with the given message, is thrown. + * @param actual the actual value + * @param expected the expected value + * @param message the assertion error message + */ + public static void assertEquals(short actual, short expected, String message) { + assertEquals(Short.valueOf(actual), Short.valueOf(expected), message); + } + + /** + * Asserts that two shorts are equal. If they are not, + * an AssertionError is thrown. + * @param actual the actual value + * @param expected the expected value + */ + public static void assertEquals(short actual, short expected) { + assertEquals(actual, expected, null); + } + + /** + * Asserts that two integers are equal. If they are not, + * an AssertionFailedError, with the given message, is thrown. + * @param actual the actual value + * @param expected the expected value + * @param message the assertion error message + */ + public static void assertEquals(int actual, int expected, String message) { + assertEquals(Integer.valueOf(actual), Integer.valueOf(expected), message); + } + + /** + * Asserts that two integers are equal. If they are not, + * an AssertionError is thrown. + * @param actual the actual value + * @param expected the expected value + */ + public static void assertEquals(int actual, int expected) { + assertEquals(actual, expected, null); + } + + /** + * Asserts that an object isn't null. If it is, + * an AssertionError is thrown. + * @param object the assertion object + */ + public static void assertNotNull(Object object) { + assertNotNull(object, null); + } + + /** + * Asserts that an object isn't null. If it is, + * an AssertionFailedError, with the given message, is thrown. + * @param object the assertion object + * @param message the assertion error message + */ + public static void assertNotNull(Object object, String message) { + if (object == null) { + String formatted = ""; + if(message != null) { + formatted = message + " "; + } + fail(formatted + "expected object to not be null"); + } + assertTrue(object != null, message); + } + + /** + * Asserts that an object is null. If it is not, + * an AssertionError, with the given message, is thrown. + * @param object the assertion object + */ + public static void assertNull(Object object) { + assertNull(object, null); + } + + /** + * Asserts that an object is null. If it is not, + * an AssertionFailedError, with the given message, is thrown. + * @param object the assertion object + * @param message the assertion error message + */ + public static void assertNull(Object object, String message) { + if (object != null) { + failNotSame(object, null, message); + } + } + + /** + * Asserts that two objects refer to the same object. If they do not, + * an AssertionFailedError, with the given message, is thrown. + * @param actual the actual value + * @param expected the expected value + * @param message the assertion error message + */ + public static void assertSame(Object actual, Object expected, String message) { + if(expected == actual) { + return; + } + failNotSame(actual, expected, message); + } + + /** + * Asserts that two objects refer to the same object. If they do not, + * an AssertionError is thrown. + * @param actual the actual value + * @param expected the expected value + */ + public static void assertSame(Object actual, Object expected) { + assertSame(actual, expected, null); + } + + /** + * Asserts that two objects do not refer to the same objects. If they do, + * an AssertionError, with the given message, is thrown. + * @param actual the actual value + * @param expected the expected value + * @param message the assertion error message + */ + public static void assertNotSame(Object actual, Object expected, String message) { + if(expected == actual) { + failSame(actual, expected, message); + } + } + + /** + * Asserts that two objects do not refer to the same object. If they do, + * an AssertionError is thrown. + * @param actual the actual value + * @param expected the expected value + */ + public static void assertNotSame(Object actual, Object expected) { + assertNotSame(actual, expected, null); + } + + private static void failSame(Object actual, Object expected, String message) { + String formatted = ""; + if(message != null) { + formatted = message + " "; + } + fail(formatted + ASSERT_LEFT2 + expected + ASSERT_MIDDLE + actual + ASSERT_RIGHT); + } + + private static void failNotSame(Object actual, Object expected, String message) { + String formatted = ""; + if(message != null) { + formatted = message + " "; + } + fail(formatted + ASSERT_LEFT + expected + ASSERT_MIDDLE + actual + ASSERT_RIGHT); + } + + private static void failNotEquals(Object actual, Object expected, String message) { + fail(format(actual, expected, message)); + } + + static String format(Object actual, Object expected, String message) { + String formatted = ""; + if (null != message) { + formatted = message + " "; + } + + return formatted + ASSERT_LEFT + expected + ASSERT_MIDDLE + actual + ASSERT_RIGHT; + } + + /** + * Asserts that two collections contain the same elements in the same order. If they do not, + * an AssertionError is thrown. + * + * @param actual the actual value + * @param expected the expected value + */ + public static void assertEquals(Collection> actual, Collection> expected) { + assertEquals(actual, expected, null); + } + + /** + * Asserts that two collections contain the same elements in the same order. If they do not, + * an AssertionError, with the given message, is thrown. + * @param actual the actual value + * @param expected the expected value + * @param message the assertion error message + */ + public static void assertEquals(Collection> actual, Collection> expected, String message) { + if(actual == expected) { + return; + } + + if (actual == null || expected == null) { + if (message != null) { + fail(message); + } else { + fail("Collections not equal: expected: " + expected + " and actual: " + actual); + } + } + + assertEquals(actual.size(), expected.size(), message + ": lists don't have the same size"); + + Iterator> actIt = actual.iterator(); + Iterator> expIt = expected.iterator(); + int i = -1; + while(actIt.hasNext() && expIt.hasNext()) { + i++; + Object e = expIt.next(); + Object a = actIt.next(); + String explanation = "Lists differ at element [" + i + "]: " + e + " != " + a; + String errorMessage = message == null ? explanation : message + ": " + explanation; + + assertEquals(a, e, errorMessage); + } + } + + /** Asserts that two iterators return the same elements in the same order. If they do not, + * an AssertionError is thrown. + * Please note that this assert iterates over the elements and modifies the state of the iterators. + * @param actual the actual value + * @param expected the expected value + */ + public static void assertEquals(Iterator> actual, Iterator> expected) { + assertEquals(actual, expected, null); + } + + /** Asserts that two iterators return the same elements in the same order. If they do not, + * an AssertionError, with the given message, is thrown. + * Please note that this assert iterates over the elements and modifies the state of the iterators. + * @param actual the actual value + * @param expected the expected value + * @param message the assertion error message + */ + public static void assertEquals(Iterator> actual, Iterator> expected, String message) { + if(actual == expected) { + return; + } + + if(actual == null || expected == null) { + if(message != null) { + fail(message); + } else { + fail("Iterators not equal: expected: " + expected + " and actual: " + actual); + } + } + + int i = -1; + while(actual.hasNext() && expected.hasNext()) { + + i++; + Object e = expected.next(); + Object a = actual.next(); + String explanation = "Iterators differ at element [" + i + "]: " + e + " != " + a; + String errorMessage = message == null ? explanation : message + ": " + explanation; + + assertEquals(a, e, errorMessage); + + } + + if(actual.hasNext()) { + + String explanation = "Actual iterator returned more elements than the expected iterator."; + String errorMessage = message == null ? explanation : message + ": " + explanation; + fail(errorMessage); + + } else if(expected.hasNext()) { + + String explanation = "Expected iterator returned more elements than the actual iterator."; + String errorMessage = message == null ? explanation : message + ": " + explanation; + fail(errorMessage); + + } + + } + + /** Asserts that two iterables return iterators with the same elements in the same order. If they do not, + * an AssertionError is thrown. + * @param actual the actual value + * @param expected the expected value + */ + public static void assertEquals(Iterable> actual, Iterable> expected) { + assertEquals(actual, expected, null); + } + + /** Asserts that two iterables return iterators with the same elements in the same order. If they do not, + * an AssertionError, with the given message, is thrown. + * @param actual the actual value + * @param expected the expected value + * @param message the assertion error message + */ + public static void assertEquals(Iterable> actual, Iterable> expected, String message) { + if(actual == expected) { + return; + } + + if(actual == null || expected == null) { + if(message != null) { + fail(message); + } else { + fail("Iterables not equal: expected: " + expected + " and actual: " + actual); + } + } + + Iterator> actIt = actual.iterator(); + Iterator> expIt = expected.iterator(); + + assertEquals(actIt, expIt, message); + } + + + + + /** + * Asserts that two arrays contain the same elements in the same order. If they do not, + * an AssertionError, with the given message, is thrown. + * @param actual the actual value + * @param expected the expected value + * @param message the assertion error message + */ + public static void assertEquals(Object[] actual, Object[] expected, String message) { + if(actual == expected) { + return; + } + + if ((actual == null && expected != null) || (actual != null && expected == null)) { + if (message != null) { + fail(message); + } else { + fail("Arrays not equal: " + Arrays.toString(expected) + " and " + Arrays.toString(actual)); + } + } + assertEquals(Arrays.asList(actual), Arrays.asList(expected), message); + } + + /** + * Asserts that two arrays contain the same elements in no particular order. If they do not, + * an AssertionError, with the given message, is thrown. + * @param actual the actual value + * @param expected the expected value + * @param message the assertion error message + */ + public static void assertEqualsNoOrder(Object[] actual, Object[] expected, String message) { + if(actual == expected) { + return; + } + + if ((actual == null && expected != null) || (actual != null && expected == null)) { + failAssertNoEqual( + "Arrays not equal: " + Arrays.toString(expected) + " and " + Arrays.toString(actual), + message); + } + + if (actual.length != expected.length) { + failAssertNoEqual( + "Arrays do not have the same size:" + actual.length + " != " + expected.length, + message); + } + + List