[Mulgara-svn] r1127 - trunk/src/jar/util/java/org/mulgara/util

pag at mulgara.org pag at mulgara.org
Sun Aug 10 02:04:03 UTC 2008


Author: pag
Date: 2008-08-09 19:04:03 -0700 (Sat, 09 Aug 2008)
New Revision: 1127

Added:
   trunk/src/jar/util/java/org/mulgara/util/Fn.java
   trunk/src/jar/util/java/org/mulgara/util/Fn2.java
   trunk/src/jar/util/java/org/mulgara/util/Fn2E.java
   trunk/src/jar/util/java/org/mulgara/util/FnE.java
Log:
Some standard interfaces to make functors easier to write. The versions with an 'E' suffix indicate that the class is expected to throw an exception in its methods.

Added: trunk/src/jar/util/java/org/mulgara/util/Fn.java
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/Fn.java	                        (rev 0)
+++ trunk/src/jar/util/java/org/mulgara/util/Fn.java	2008-08-10 02:04:03 UTC (rev 1127)
@@ -0,0 +1,26 @@
+/*
+ * The contents of this file are subject to the Open Software License
+ * Version 3.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.opensource.org/licenses/osl-3.0.txt
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ */
+
+package org.mulgara.util;
+
+/**
+ * Functor template for a function that takes one type and returns another without
+ * throwing an exception.
+ *
+ * @created Aug 4, 2008
+ * @author Paul Gearon
+ * @copyright &copy; 2008 <a href="http://www.topazproject.org/">The Topaz Project</a>
+ * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
+ */
+public interface Fn<T1,T2> extends FnE<T1,T2,RuntimeException> {
+
+}

Added: trunk/src/jar/util/java/org/mulgara/util/Fn2.java
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/Fn2.java	                        (rev 0)
+++ trunk/src/jar/util/java/org/mulgara/util/Fn2.java	2008-08-10 02:04:03 UTC (rev 1127)
@@ -0,0 +1,26 @@
+/*
+ * The contents of this file are subject to the Open Software License
+ * Version 3.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.opensource.org/licenses/osl-3.0.txt
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ */
+
+package org.mulgara.util;
+
+/**
+ * Functor template for a function that takes arguments of two different types
+ * and returns a value of a third type, without throwing an exception.
+ *
+ * @created Aug 4, 2008
+ * @author Paul Gearon
+ * @copyright &copy; 2008 <a href="http://www.topazproject.org/">The Topaz Project</a>
+ * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
+ */
+public interface Fn2<T1,T2,T3> extends Fn2E<T1,T2,T3,RuntimeException>{
+
+}

Added: trunk/src/jar/util/java/org/mulgara/util/Fn2E.java
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/Fn2E.java	                        (rev 0)
+++ trunk/src/jar/util/java/org/mulgara/util/Fn2E.java	2008-08-10 02:04:03 UTC (rev 1127)
@@ -0,0 +1,35 @@
+/*
+ * The contents of this file are subject to the Open Software License
+ * Version 3.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.opensource.org/licenses/osl-3.0.txt
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ */
+
+package org.mulgara.util;
+
+/**
+ * Functor template for a function that takes arguments of two different types
+ * and returns a value of a third type, possibly throwing an exception.
+ *
+ * @created Aug 4, 2008
+ * @author Paul Gearon
+ * @copyright &copy; 2008 <a href="http://www.topazproject.org/">The Topaz Project</a>
+ * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
+ */
+public interface Fn2E<T1,T2,T3,E extends Exception> {
+
+  /**
+   * Declares a function template that takes two arguments and returns a value of
+   * another type.
+   * @param arg1 The first argument.
+   * @param arg2 The first argument.
+   * @return A value based on arg1 and arg2.
+   * @throws E An exception that may be thrown from this method.
+   */
+  T3 fn(T1 arg1, T2 arg2) throws E;
+}

Added: trunk/src/jar/util/java/org/mulgara/util/FnE.java
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/FnE.java	                        (rev 0)
+++ trunk/src/jar/util/java/org/mulgara/util/FnE.java	2008-08-10 02:04:03 UTC (rev 1127)
@@ -0,0 +1,34 @@
+/*
+ * The contents of this file are subject to the Open Software License
+ * Version 3.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.opensource.org/licenses/osl-3.0.txt
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ */
+
+package org.mulgara.util;
+
+/**
+ * Functor template for a function that takes one type and returns another.
+ * An exception may be thrown.
+ *
+ * @created Aug 4, 2008
+ * @author Paul Gearon
+ * @copyright &copy; 2008 <a href="http://www.topazproject.org/">The Topaz Project</a>
+ * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
+ */
+public interface FnE<T1,T2,E extends Exception> {
+
+  /**
+   * Declares a function template that takes one argument and returns a value of
+   * another type.
+   * @param arg The single argument.
+   * @return A value based on arg.
+   * @throws E Can throw an exception of this type.
+   */
+  T2 fn(T1 arg) throws E;
+}




More information about the Mulgara-svn mailing list