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/09/10 14:56:07 UTC
[isis] 01/08: ISIS-1976: remove TypedOid;
Oids: make cached hashes final and fix object contracts
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch ISIS-1976-rethink-object-adapters
in repository https://gitbox.apache.org/repos/asf/isis.git
commit a95d2e90608145acabc5d17763ebc2a3655a0fcf
Author: Andi Huber <ah...@apache.org>
AuthorDate: Mon Sep 10 07:28:47 2018 +0200
ISIS-1976: remove TypedOid; Oids: make cached hashes final and fix
object contracts
Task-Url: https://issues.apache.org/jira/browse/ISIS-1976
---
.../adapter/oid/ParentedCollectionOid.java | 21 ++++------
.../isis/core/metamodel/adapter/oid/RootOid.java | 49 +++++++---------------
.../isis/core/metamodel/adapter/oid/TypedOid.java | 30 -------------
3 files changed, 22 insertions(+), 78 deletions(-)
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/adapter/oid/ParentedCollectionOid.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/adapter/oid/ParentedCollectionOid.java
index 765b034..9f463f6 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/adapter/oid/ParentedCollectionOid.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/adapter/oid/ParentedCollectionOid.java
@@ -21,8 +21,7 @@ package org.apache.isis.core.metamodel.adapter.oid;
import java.io.IOException;
import java.io.Serializable;
-
-import com.google.common.base.Objects;
+import java.util.Objects;
import org.apache.isis.core.commons.encoding.DataInputExtended;
import org.apache.isis.core.commons.encoding.DataOutputExtended;
@@ -40,7 +39,7 @@ public final class ParentedCollectionOid implements Serializable, Oid {
private final static OidMarshaller OID_MARSHALLER = OidMarshaller.INSTANCE;
private final String name;
- private int cachedHashCode;
+ private final int hashCode;
private final RootOid parentOid;
@@ -56,7 +55,7 @@ public final class ParentedCollectionOid implements Serializable, Oid {
Assert.assertNotNull("rootOid required", rootOid);
this.parentOid = rootOid;
this.name = name;
- cacheState();
+ this.hashCode = calculateHash();
}
@@ -122,6 +121,7 @@ public final class ParentedCollectionOid implements Serializable, Oid {
private ParentedCollectionOid(ParentedCollectionOid oid) throws IOException {
this.parentOid = oid.getRootOid();
this.name = oid.name;
+ this.hashCode = calculateHash();
}
@@ -169,25 +169,20 @@ public final class ParentedCollectionOid implements Serializable, Oid {
}
public boolean equals(final ParentedCollectionOid other) {
- return Objects.equal(other.getRootOid(), getRootOid()) && Objects.equal(other.name, name);
+ return Objects.equals(other.getRootOid(), getRootOid()) && Objects.equals(other.name, name);
}
@Override
public int hashCode() {
- cacheState();
- return cachedHashCode;
+ return hashCode;
}
- private void cacheState() {
- int hashCode = 17;
- hashCode = 37 * hashCode + getRootOid().hashCode();
- hashCode = 37 * hashCode + name.hashCode();
- cachedHashCode = hashCode;
+ private int calculateHash() {
+ return Objects.hash(getRootOid(), name);
}
-
// /////////////////////////////////////////////////////////
// asPersistent
// /////////////////////////////////////////////////////////
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/adapter/oid/RootOid.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/adapter/oid/RootOid.java
index 7cbb26d..3836542 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/adapter/oid/RootOid.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/adapter/oid/RootOid.java
@@ -21,11 +21,7 @@ package org.apache.isis.core.metamodel.adapter.oid;
import java.io.IOException;
import java.io.Serializable;
-
-import com.google.common.base.Objects;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import java.util.Objects;
import org.apache.isis.applib.services.bookmark.Bookmark;
import org.apache.isis.core.commons.encoding.DataInputExtended;
@@ -36,25 +32,20 @@ import org.apache.isis.core.metamodel.spec.ObjectSpecId;
import org.apache.isis.schema.common.v1.BookmarkObjectState;
import org.apache.isis.schema.common.v1.OidDto;
-public class RootOid implements TypedOid, Serializable {
+public class RootOid implements Oid, Serializable {
// -- fields
- private final static Logger LOG = LoggerFactory.getLogger(RootOid.class);
-
- private static final long serialVersionUID = 1L;
-
+ private final static long serialVersionUID = 1L;
private final static OidMarshaller OID_MARSHALLER = OidMarshaller.INSTANCE;
private final ObjectSpecId objectSpecId;
private final String identifier;
private final State state;
-
+ private final int hashCode;
// not part of equality check
private Version version;
- private int cachedHashCode;
-
// -- Constructor, factory methods
public static RootOid createTransient(final ObjectSpecId objectSpecId, final String identifier) {
@@ -130,15 +121,9 @@ public class RootOid implements TypedOid, Serializable {
this.identifier = identifier;
this.state = state;
this.version = version;
- initialized();
- }
-
- private void initialized() {
- cacheState();
+ this.hashCode = calculateHash();
}
-
-
// -- Encodeable
public RootOid(final DataInputExtended input) throws IOException {
final String oidStr = input.readUTF();
@@ -147,7 +132,7 @@ public class RootOid implements TypedOid, Serializable {
this.identifier = oid.identifier;
this.state = oid.state;
this.version = oid.version;
- cacheState();
+ this.hashCode = calculateHash();
}
@Override
@@ -155,9 +140,6 @@ public class RootOid implements TypedOid, Serializable {
output.writeUTF(enString());
}
-
-
-
// -- deString'able, enString
public static RootOid deStringEncoded(final String urlEncodedOidStr) {
final String oidStr = UrlDecoderUtil.urlDecode(urlEncodedOidStr);
@@ -180,7 +162,6 @@ public class RootOid implements TypedOid, Serializable {
// -- Properties
- @Override
public ObjectSpecId getObjectSpecId() {
return objectSpecId;
}
@@ -244,11 +225,8 @@ public class RootOid implements TypedOid, Serializable {
// -- equals, hashCode
- private void cacheState() {
- cachedHashCode = 17;
- cachedHashCode = 37 * cachedHashCode + objectSpecId.hashCode();
- cachedHashCode = 37 * cachedHashCode + identifier.hashCode();
- cachedHashCode = 37 * cachedHashCode + (isTransient() ? 0 : 1);
+ private int calculateHash() {
+ return Objects.hash(objectSpecId, identifier, state);
}
@Override
@@ -266,12 +244,14 @@ public class RootOid implements TypedOid, Serializable {
}
public boolean equals(final RootOid other) {
- return Objects.equal(objectSpecId, other.getObjectSpecId()) && Objects.equal(identifier, other.getIdentifier()) && Objects.equal(isTransient(), other.isTransient());
+ return Objects.equals(objectSpecId, other.getObjectSpecId()) &&
+ Objects.equals(identifier, other.getIdentifier()) &&
+ Objects.equals(state, other.state);
}
@Override
public int hashCode() {
- return cachedHashCode;
+ return hashCode;
}
@@ -284,11 +264,10 @@ public class RootOid implements TypedOid, Serializable {
// -- ROOT-ID SUPPORT FOR VALUE
- private RootOid() { identifier=null; objectSpecId=null; state=null; };
+ private RootOid() { identifier=null; objectSpecId=null; state=null; hashCode=0;};
private static final RootOid VALUE_OID = new RootOid() {
- private static final long serialVersionUID = 1L;
-
+ private static final long serialVersionUID = 2L;
@Override
public boolean isValue() {
return true;
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/adapter/oid/TypedOid.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/adapter/oid/TypedOid.java
deleted file mode 100644
index 141466e..0000000
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/adapter/oid/TypedOid.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * 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.core.metamodel.adapter.oid;
-
-import org.apache.isis.core.metamodel.spec.ObjectSpecId;
-
-/**
- * @deprecated - for backward compatibility with addons.
- */
-@Deprecated
-public interface TypedOid extends Oid {
- ObjectSpecId getObjectSpecId();
-}