/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
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;
*
* @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);
}
/**
*
* @param sourceIdentifier Source identifier
* @return schema source registration, which the subclass needs to
- * {@link SchemaSourceRegistration#close() once it expunges the source
+ * {@link SchemaSourceRegistration#close()} once it expunges the source
* 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));
}
}