From 8522c65857e75cad7142957fb8dfb299dc94c6f4 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Thu, 24 Aug 2017 14:04:04 +0200 Subject: [PATCH] Use Guava's Interner instead of ObjectCache Guava's Interner does pretty much the same thing, no need to use ObjectCache. Change-Id: I4ee79155aeac465bfd59392656f555c3509459fd Signed-off-by: Robert Varga --- yang/yang-model-api/pom.xml | 4 --- .../model/repo/spi/PotentialSchemaSource.java | 30 ++++++------------- 2 files changed, 9 insertions(+), 25 deletions(-) diff --git a/yang/yang-model-api/pom.xml b/yang/yang-model-api/pom.xml index 63abe1b60f..5a82dbce13 100644 --- a/yang/yang-model-api/pom.xml +++ b/yang/yang-model-api/pom.xml @@ -37,10 +37,6 @@ - - ${project.groupId} - object-cache-api - ${project.groupId} util diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/spi/PotentialSchemaSource.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/spi/PotentialSchemaSource.java index 80d23a94ff..3652fd4279 100644 --- a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/spi/PotentialSchemaSource.java +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/spi/PotentialSchemaSource.java @@ -9,9 +9,9 @@ package org.opendaylight.yangtools.yang.model.repo.spi; import com.google.common.annotations.Beta; import com.google.common.base.Preconditions; - -import org.opendaylight.yangtools.objcache.ObjectCache; -import org.opendaylight.yangtools.objcache.ObjectCacheFactory; +import com.google.common.collect.Interner; +import com.google.common.collect.Interners; +import java.util.Objects; import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation; import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier; @@ -64,7 +64,7 @@ public final class PotentialSchemaSource { } } - private static final ObjectCache CACHE = ObjectCacheFactory.getObjectCache(PotentialSchemaSource.class); + private static final Interner> INTERNER = Interners.newWeakInterner(); private final Class representation; private final SourceIdentifier sourceIdentifier; private final int cost; @@ -87,8 +87,9 @@ public final class PotentialSchemaSource { * * @return A potentially shared reference, not guaranteed to be unique. */ + @SuppressWarnings("unchecked") public PotentialSchemaSource cachedReference() { - return CACHE.getReference(this); + return (PotentialSchemaSource) INTERNER.intern(this); } public SourceIdentifier getSourceIdentifier() { @@ -105,12 +106,7 @@ public final class PotentialSchemaSource { @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + cost; - result = prime * result + representation.hashCode(); - result = prime * result + sourceIdentifier.hashCode(); - return result; + return Objects.hash(cost, representation, sourceIdentifier); } @Override @@ -122,15 +118,7 @@ public final class PotentialSchemaSource { return false; } final PotentialSchemaSource other = (PotentialSchemaSource) obj; - if (cost != other.cost) { - return false; - } - if (!representation.equals(other.representation)) { - return false; - } - if (!sourceIdentifier.equals(other.sourceIdentifier)) { - return false; - } - return true; + return cost == other.cost && representation.equals(other.representation) + && sourceIdentifier.equals(other.sourceIdentifier); } } -- 2.36.6