Use representation class for casting
[yangtools.git] / yang / yang-model-util / src / main / java / org / opendaylight / yangtools / yang / model / repo / util / AbstractSchemaSourceCache.java
index b665f43c58d0c86fdd832444a561beeb5df4bdfc..f7bc8f73c9471e77f8c7a05e55e922d1196771eb 100644 (file)
@@ -7,7 +7,7 @@
  */
 package org.opendaylight.yangtools.yang.model.repo.util;
 
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
 
 import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
@@ -26,15 +26,17 @@ import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry;
  *
  * @param <T> Cached schema source type.
  */
-public abstract class AbstractSchemaSourceCache<T extends SchemaSourceRepresentation> implements SchemaSourceListener, SchemaSourceProvider<T> {
+public abstract class AbstractSchemaSourceCache<T extends SchemaSourceRepresentation>
+        implements SchemaSourceListener, SchemaSourceProvider<T> {
     private final SchemaSourceRegistry consumer;
     private final Class<T> representation;
     private final Costs cost;
 
-    protected AbstractSchemaSourceCache(final SchemaSourceRegistry consumer, final Class<T> representation, final Costs cost) {
-        this.consumer = Preconditions.checkNotNull(consumer);
-        this.representation = Preconditions.checkNotNull(representation);
-        this.cost = Preconditions.checkNotNull(cost);
+    protected AbstractSchemaSourceCache(final SchemaSourceRegistry consumer, final Class<T> representation,
+            final Costs cost) {
+        this.consumer = requireNonNull(consumer);
+        this.representation = requireNonNull(representation);
+        this.cost = requireNonNull(cost);
     }
 
     /**
@@ -58,16 +60,15 @@ public abstract class AbstractSchemaSourceCache<T extends SchemaSourceRepresenta
      *         from the cache.
      */
     protected final SchemaSourceRegistration<T> register(final SourceIdentifier sourceIdentifier) {
-        final PotentialSchemaSource<T> src = PotentialSchemaSource.create(sourceIdentifier, representation, cost.getValue());
+        final PotentialSchemaSource<T> src = PotentialSchemaSource.create(sourceIdentifier, representation,
+                cost.getValue());
         return consumer.registerSchemaSource(this, src);
     }
 
     @Override
     public void schemaSourceEncountered(final SchemaSourceRepresentation source) {
         if (representation.isAssignableFrom(source.getType())) {
-            @SuppressWarnings("unchecked")
-            final T src = (T)source;
-            offer(src);
+            offer(representation.cast(source));
         }
     }