You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2018/03/05 09:19:37 UTC

[isis] branch master updated (ab44c5c -> 5d73658)

This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git.


 discard ab44c5c  ISIS-1897 suppress deprecation warnings on JUnit test cases
     new 0eb38f4  ISIS-1897 _Exceptions: add 'not implemented' idiom
     new 5d73658  ISIS-1897 implement ObjectContracts

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (ab44c5c)
            \
             N -- N -- N   refs/heads/master (5d73658)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../applib/internal/exceptions/_Exceptions.java    | 22 +++++++
 .../isis/applib/util/ObjectContract_Impl.java      | 68 ++++++++++++++++++++++
 .../isis/applib/util/ObjectContract_Parser.java}   | 41 +++++++------
 .../apache/isis/applib/util/ObjectContracts.java   | 54 +++++++++++------
 4 files changed, 147 insertions(+), 38 deletions(-)
 create mode 100644 core/applib/src/main/java/org/apache/isis/applib/util/ObjectContract_Impl.java
 copy core/applib/src/{test/java/org/apache/isis/applib/util/TitleTestObject.java => main/java/org/apache/isis/applib/util/ObjectContract_Parser.java} (61%)

-- 
To stop receiving notification emails like this one, please contact
ahuber@apache.org.

[isis] 02/02: ISIS-1897 implement ObjectContracts

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git

commit 5d736584e24c14006cc9882112317e818c887cd9
Author: Andi Huber <ah...@apache.org>
AuthorDate: Mon Mar 5 10:18:19 2018 +0100

    ISIS-1897 implement ObjectContracts
---
 .../isis/applib/util/ObjectContract_Impl.java      | 68 ++++++++++++++++++++++
 .../isis/applib/util/ObjectContract_Parser.java    | 44 ++++++++++++++
 .../apache/isis/applib/util/ObjectContracts.java   | 54 +++++++++++------
 3 files changed, 149 insertions(+), 17 deletions(-)

diff --git a/core/applib/src/main/java/org/apache/isis/applib/util/ObjectContract_Impl.java b/core/applib/src/main/java/org/apache/isis/applib/util/ObjectContract_Impl.java
new file mode 100644
index 0000000..db6391f
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/util/ObjectContract_Impl.java
@@ -0,0 +1,68 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.isis.applib.util;
+
+import org.apache.isis.applib.internal.exceptions._Exceptions;
+import org.apache.isis.applib.util.ObjectContracts.ObjectContract;
+import org.apache.isis.applib.util.ObjectContracts.ToStringEvaluator;
+
+/**
+ * Package private default implementation for ObjectContract.
+ *  
+ * @since 2.0.0
+ */
+class ObjectContract_Impl<T> implements ObjectContract<T> {
+
+	@Override
+	public int compare(Object obj, Object other) {
+		// TODO Auto-generated method stub
+		_Exceptions.throwNotImplemented();
+		return 0;
+	}
+
+	@Override
+	public boolean equals(Object obj, Object other) {
+		// TODO Auto-generated method stub
+		_Exceptions.throwNotImplemented();
+		return false;
+	}
+
+	@Override
+	public int hashCode(Object obj) {
+		// TODO Auto-generated method stub
+		_Exceptions.throwNotImplemented();
+		return 0;
+	}
+
+	@Override
+	public String toString(Object obj) {
+		// TODO Auto-generated method stub
+		_Exceptions.throwNotImplemented();
+		return null;
+	}
+
+	@Override
+	public ObjectContract<T> withToStringEvaluators(ToStringEvaluator... evaluators) {
+		// TODO Auto-generated method stub
+		_Exceptions.throwNotImplemented();
+		return null;
+	}
+
+}
diff --git a/core/applib/src/main/java/org/apache/isis/applib/util/ObjectContract_Parser.java b/core/applib/src/main/java/org/apache/isis/applib/util/ObjectContract_Parser.java
new file mode 100644
index 0000000..d9555c4
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/util/ObjectContract_Parser.java
@@ -0,0 +1,44 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.isis.applib.util;
+
+import org.apache.isis.applib.internal.exceptions._Exceptions;
+import org.apache.isis.applib.util.ObjectContracts.ObjectContract;
+
+/**
+ * Package private parser for ObjectContract.<br/><br/>
+ *  
+ * Not public API! Use ObjectContracts.parse(String) instead.
+ * 
+ * 
+ * @since 2.0.0
+ */
+class ObjectContract_Parser<T> {
+
+	public static <T> ObjectContract<T> parse(Class<T> target, String propertyNames) {
+		final ObjectContract_Impl<T> contract = new ObjectContract_Impl<>();
+		
+		//TODO
+		_Exceptions.throwNotImplemented();
+		
+		return contract;
+	}
+
+}
diff --git a/core/applib/src/main/java/org/apache/isis/applib/util/ObjectContracts.java b/core/applib/src/main/java/org/apache/isis/applib/util/ObjectContracts.java
index 2f95aa0..aa588f3 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/util/ObjectContracts.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/util/ObjectContracts.java
@@ -18,9 +18,10 @@
  */
 package org.apache.isis.applib.util;
 
+import java.util.Objects;
 import java.util.function.Function;
 
-import org.apache.isis.applib.internal.exceptions._Exceptions;
+import org.apache.isis.applib.internal.base._Casts;
 
 /**
  * Provides fluent composition for Objects' equals, hashCode and toString.
@@ -86,6 +87,13 @@ public final class ObjectContracts {
         String evaluate(Object o);
     }
 	
+    /**
+     * WARNING Possible misuse because of forgetting respectively the last method 
+     * argument with {@code equals}, [@code hashCode} and {@code toString}!
+     *  
+     * @since 2.0.0
+     * @param <T>
+     */
 	public static interface ObjectContract<T> {
 
 		public int compare(T obj, T other);
@@ -98,40 +106,52 @@ public final class ObjectContracts {
 		
 	    // -- TO STRING EVALUATION
 
+		/**
+		 * True 'wither' (each call returns a new instance of ObjectContract)!
+		 * @param evaluators
+		 * @return contract with ToStringEvaluator(s) to apply to properties when 
+		 * processing the toString algorithm.
+		 */
 		public ObjectContract<T> withToStringEvaluators(ToStringEvaluator ... evaluators);
 		
 	}
 	
 	public static <T> ObjectContract<T> parse(Class<T> target, String propertyNames) {
-		// TODO Auto-generated method stub
-		throw _Exceptions.notImplemented();
+		return ObjectContract_Parser.parse(target, propertyNames);
 	}
 
 	// -- BACKWARDS COMPATIBILITY
 	
-	@Deprecated
-	public static String toString(Object obj, String propertyNames) {
+	@Deprecated // uses reflection on each call
+	public static <T> String toString(T obj, String propertyNames) {
+		Objects.requireNonNull(obj, "obj required, otherwise undecidable");
 		
-		// TODO Auto-generated method stub
-		throw _Exceptions.notImplemented();
+		return parse(_Casts.uncheckedCast(obj.getClass()), propertyNames)
+				.toString(obj);
 	}
 	
-	@Deprecated
-	public static boolean equals(Object obj, Object other, String propertyNames) {
-		// TODO Auto-generated method stub
-		throw _Exceptions.notImplemented();
+	@Deprecated // uses reflection on each call
+	public static <T> boolean equals(T obj, Object other, String propertyNames) {
+		Objects.requireNonNull(obj, "obj required, otherwise undecidable"); 
+		
+		return parse(_Casts.uncheckedCast(obj.getClass()), propertyNames)
+				.equals(obj, other);
 	}
 	
-	@Deprecated
+	@Deprecated // uses reflection on each call
 	public static int hashCode(Object obj, String propertyNames) {
-		// TODO Auto-generated method stub
-		throw _Exceptions.notImplemented();
+		Objects.requireNonNull(obj, "obj required, otherwise undecidable");
+
+		return parse(_Casts.uncheckedCast(obj.getClass()), propertyNames)
+				.hashCode(obj);
 	}
 
-	@Deprecated
+	@Deprecated // uses reflection on each call
 	public static <T> int compare(T obj, T other, String propertyNames) {
-		// TODO Auto-generated method stub
-		throw _Exceptions.notImplemented();
+		Objects.requireNonNull(obj, "obj required, otherwise undecidable");
+
+		return parse(_Casts.uncheckedCast(obj.getClass()), propertyNames)
+				.compare(obj, other);
 	}
 
 	

-- 
To stop receiving notification emails like this one, please contact
ahuber@apache.org.

[isis] 01/02: ISIS-1897 _Exceptions: add 'not implemented' idiom

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git

commit 0eb38f4f8e0964196e05103ff211c7f5cd9c8bf3
Author: Andi Huber <ah...@apache.org>
AuthorDate: Mon Mar 5 09:33:38 2018 +0100

    ISIS-1897 _Exceptions: add 'not implemented' idiom
---
 .../applib/internal/exceptions/_Exceptions.java    | 22 ++++++++++++++++++++++
 .../java/org/apache/isis/applib/util/Invoice.java  |  4 ++--
 .../org/apache/isis/applib/util/InvoiceItem.java   |  2 +-
 .../applib/util/ObjectContractsTest_equals.java    |  1 +
 .../ObjectContractsTest_equals_and_hashCode.java   |  2 ++
 .../applib/util/ObjectContractsTest_toString.java  |  3 +++
 6 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/core/applib/src/main/java/org/apache/isis/applib/internal/exceptions/_Exceptions.java b/core/applib/src/main/java/org/apache/isis/applib/internal/exceptions/_Exceptions.java
index 12e06ca..b4a7312 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/internal/exceptions/_Exceptions.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/internal/exceptions/_Exceptions.java
@@ -75,6 +75,28 @@ public final class _Exceptions {
 		return new IllegalStateException("internal error: code was reached, that is not implemented yet");
 	}
 	
+	/**
+	 * Used, to hide from the compiler the fact, that this call always throws.
+	 * 
+	 * <pre>{
+	 *    throw notImplemented();
+	 *    return 0; // won't compile: unreachable code
+	 *}</pre>
+	 *
+	 * hence ...
+	 * 
+	 * <pre>{
+	 *    throwNotImplemented();
+	 *    return 0;    
+	 *}</pre>
+	 * 
+	 * @return
+	 */
+	public static IllegalStateException throwNotImplemented() {
+		throw notImplemented();
+	}
+	
+	
 	// -- STACKTRACE UTILITITIES
 	
 	public static final Stream<String> streamStacktraceLines(@Nullable Throwable ex, int maxLines) {
diff --git a/core/applib/src/test/java/org/apache/isis/applib/util/Invoice.java b/core/applib/src/test/java/org/apache/isis/applib/util/Invoice.java
index edcafc9..96139f8 100644
--- a/core/applib/src/test/java/org/apache/isis/applib/util/Invoice.java
+++ b/core/applib/src/test/java/org/apache/isis/applib/util/Invoice.java
@@ -16,7 +16,7 @@
  */
 package org.apache.isis.applib.util;
 
-
+@SuppressWarnings("deprecation")
 class Invoice implements Comparable<Invoice>{
     private static final String KEY_PROPERTIES = "number";
     
@@ -27,7 +27,7 @@ class Invoice implements Comparable<Invoice>{
     public void setNumber(String number) {
         this.number = number;
     }
-    @Override
+	@Override
     public String toString() {
         return ObjectContracts.toString(this, KEY_PROPERTIES);
     }
diff --git a/core/applib/src/test/java/org/apache/isis/applib/util/InvoiceItem.java b/core/applib/src/test/java/org/apache/isis/applib/util/InvoiceItem.java
index ce981d1..372bef9 100644
--- a/core/applib/src/test/java/org/apache/isis/applib/util/InvoiceItem.java
+++ b/core/applib/src/test/java/org/apache/isis/applib/util/InvoiceItem.java
@@ -16,7 +16,7 @@
  */
 package org.apache.isis.applib.util;
 
-
+@SuppressWarnings("deprecation")
 class InvoiceItem implements Comparable<InvoiceItem> {
 
     static InvoiceItem newInvoiceItem(Invoice invoice, String productCode, Integer quantity, Boolean rush) {
diff --git a/core/applib/src/test/java/org/apache/isis/applib/util/ObjectContractsTest_equals.java b/core/applib/src/test/java/org/apache/isis/applib/util/ObjectContractsTest_equals.java
index 5526e4f..ccab753 100644
--- a/core/applib/src/test/java/org/apache/isis/applib/util/ObjectContractsTest_equals.java
+++ b/core/applib/src/test/java/org/apache/isis/applib/util/ObjectContractsTest_equals.java
@@ -22,6 +22,7 @@ import org.junit.Test;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
+@SuppressWarnings("deprecation")
 public class ObjectContractsTest_equals {
 
     static class Invoice4 {
diff --git a/core/applib/src/test/java/org/apache/isis/applib/util/ObjectContractsTest_equals_and_hashCode.java b/core/applib/src/test/java/org/apache/isis/applib/util/ObjectContractsTest_equals_and_hashCode.java
index 89dee00..b40c630 100644
--- a/core/applib/src/test/java/org/apache/isis/applib/util/ObjectContractsTest_equals_and_hashCode.java
+++ b/core/applib/src/test/java/org/apache/isis/applib/util/ObjectContractsTest_equals_and_hashCode.java
@@ -56,6 +56,7 @@ public class ObjectContractsTest_equals_and_hashCode extends ValueTypeContractTe
     }
 }
 
+@SuppressWarnings("deprecation")
 class Invoice3 {
     private static final String KEY_PROPERTIES = "number";
     
@@ -77,6 +78,7 @@ class Invoice3 {
     
 }
 
+@SuppressWarnings("deprecation")
 class InvoiceItem3 {
 
     static InvoiceItem3 newInvoiceItem(Invoice3 invoice, String productCode, Integer quantity) {
diff --git a/core/applib/src/test/java/org/apache/isis/applib/util/ObjectContractsTest_toString.java b/core/applib/src/test/java/org/apache/isis/applib/util/ObjectContractsTest_toString.java
index 19274bb..26ee357 100644
--- a/core/applib/src/test/java/org/apache/isis/applib/util/ObjectContractsTest_toString.java
+++ b/core/applib/src/test/java/org/apache/isis/applib/util/ObjectContractsTest_toString.java
@@ -57,6 +57,7 @@ public class ObjectContractsTest_toString {
 
 }
 
+@SuppressWarnings("deprecation")
 class Invoice2 implements Comparable<Invoice2>, Numbered {
     private static final String KEY_PROPERTIES = "number";
     
@@ -76,6 +77,8 @@ class Invoice2 implements Comparable<Invoice2>, Numbered {
         return ObjectContracts.compare(this, o, KEY_PROPERTIES);
     }
 }
+
+@SuppressWarnings("deprecation")
 class InvoiceItem2 implements Comparable<InvoiceItem2> {
 
     static InvoiceItem2 newInvoiceItem(Invoice2 invoice, String productCode, Integer quantity, Boolean rush) {

-- 
To stop receiving notification emails like this one, please contact
ahuber@apache.org.