final <K, V> void onNamespaceItemAddedAction(final ParserNamespace<K, V> type,
final ModelProcessingPhase phase, final NamespaceKeyCriterion<K> criterion,
final OnNamespaceItemAdded listener) {
- final Optional<Entry<K, V>> existing = getFromNamespace(type, criterion);
- if (existing.isPresent()) {
- final Entry<K, V> entry = existing.get();
+ final var entry = getFromNamespace(type, criterion);
+ if (entry != null) {
LOG.debug("Listener on {} criterion {} found a pre-existing match: {}", type, criterion, entry);
waitForPhase(entry.getValue(), type, phase, criterion, listener);
return;
final <K, V> void selectMatch(final ParserNamespace<K, V> type, final NamespaceKeyCriterion<K> criterion,
final OnNamespaceItemAdded listener) {
- final Optional<Entry<K, V>> optMatch = getFromNamespace(type, criterion);
- checkState(optMatch.isPresent(), "Failed to find a match for criterion %s in namespace %s node %s", criterion,
- type, this);
- final Entry<K, V> match = optMatch.get();
+ final var match = getFromNamespace(type, criterion);
+ if (match == null) {
+ throw new IllegalStateException(
+ "Failed to find a match for criterion %s in namespace %s node %s".formatted(criterion, type, this));
+ }
listener.namespaceItemAdded(StatementContextBase.this, type, match.getKey(), match.getValue());
}
- private <K, V> Optional<Entry<K, V>> getFromNamespace(final ParserNamespace<K, V> type,
+ private <K, V> @Nullable Entry<K, V> getFromNamespace(final ParserNamespace<K, V> type,
final NamespaceKeyCriterion<K> criterion) {
return getNamespaceBehaviour(type).getFrom(this, criterion);
}
*/
package org.opendaylight.yangtools.yang.parser.spi.meta;
+import static com.google.common.base.Verify.verify;
import static java.util.Objects.requireNonNull;
import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;
-import com.google.common.base.Verify;
import java.util.Map;
import java.util.Map.Entry;
-import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceStorage.StorageType;
/**
* @param criterion selection criterion
* @return Selected mapping, if available.
*/
- public final Optional<Entry<K, V>> getFrom(final NamespaceStorage storage,
+ public final @Nullable Entry<K, V> getFrom(final NamespaceStorage storage,
final NamespaceKeyCriterion<K> criterion) {
final var mappings = getAllFrom(storage);
if (mappings == null) {
- return Optional.empty();
+ return null;
}
Entry<K, V> match = null;
continue;
}
- Verify.verify(selected == key, "Criterion %s selected invalid key %s from candidates [%s %s]",
- selected, match.getKey(), key);
+ verify(selected == key, "Criterion %s selected invalid key %s from candidates [%s %s]", selected,
+ match.getKey(), key);
}
match = entry;
}
}
- return Optional.ofNullable(match);
+ return match;
}
/**