Use representation class for casting
[yangtools.git] / yang / yang-model-util / src / main / java / org / opendaylight / yangtools / yang / model / repo / util / AbstractSchemaSourceCache.java
index 4816e8f28a82118bb715b263c8456854294817c0..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;
@@ -34,9 +34,9 @@ public abstract class AbstractSchemaSourceCache<T extends SchemaSourceRepresenta
 
     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);
+        this.consumer = requireNonNull(consumer);
+        this.representation = requireNonNull(representation);
+        this.cost = requireNonNull(cost);
     }
 
     /**
@@ -68,9 +68,7 @@ public abstract class AbstractSchemaSourceCache<T extends SchemaSourceRepresenta
     @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));
         }
     }