Use Optional.orElseThrow() instanced.
Change-Id: I6ffee0b3e92ddca92a659d0f67d0fda128c02258
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
dataBased = domChildNode.getDataBefore();
}
if (dataBased.isPresent()) {
- return from(dataBased.get());
+ return from(dataBased.orElseThrow());
}
return from(domChildNode.getIdentifier());
}
};
BindingDOMDataBrokerAdapter bindingDOMDataBrokerAdapter =
- (BindingDOMDataBrokerAdapter) bindingDOMAdapterLoader.load(DataBroker.class).get();
+ (BindingDOMDataBrokerAdapter) bindingDOMAdapterLoader.load(DataBroker.class).orElseThrow();
bindingDOMTransactionChainAdapter =
(BindingDOMTransactionChainAdapter) type.apply(bindingDOMDataBrokerAdapter, transactionChainListener);
assertNotNull(bindingDOMTransactionChainAdapter.getDelegate());
assertTrue(tinyIntContainerNode.isPresent());
- TinyIntContainer tinyIntContainer = tinyIntContainerNode.get();
+ TinyIntContainer tinyIntContainer = tinyIntContainerNode.orElseThrow();
assertEquals(-18, tinyIntContainer.getTinyIntLeaf().getValue().byteValue());
assertEquals(-18, tinyIntContainer.getTinyIntLeaf2().getValue().byteValue());
assertEquals(-15, tinyIntContainer.getTinyIntLeaf3().getValue().byteValue());
assertTrue(smallIntContainerNode.isPresent());
- SmallIntContainer smallIntContainer = smallIntContainerNode.get();
+ SmallIntContainer smallIntContainer = smallIntContainerNode.orElseThrow();
assertEquals(-20000, smallIntContainer.getSmallIntLeaf().getValue().shortValue());
assertEquals(-20000, smallIntContainer.getSmallIntLeaf2().getValue().shortValue());
assertEquals(-15000, smallIntContainer.getSmallIntLeaf3().getValue().shortValue());
assertTrue(normalIntContainerNode.isPresent());
- NormalIntContainer normalIntContainer = normalIntContainerNode.get();
+ NormalIntContainer normalIntContainer = normalIntContainerNode.orElseThrow();
assertEquals(-200000, normalIntContainer.getNormalIntLeaf().getValue().intValue());
assertEquals(-200000, normalIntContainer.getNormalIntLeaf2().getValue().intValue());
assertEquals(-130000, normalIntContainer.getNormalIntLeaf3().getValue().intValue());
assertTrue(bigIntContainerNode.isPresent());
- BigIntContainer bigIntContainer = bigIntContainerNode.get();
+ BigIntContainer bigIntContainer = bigIntContainerNode.orElseThrow();
assertEquals(-3300000000L, bigIntContainer.getBigIntLeaf().getValue().longValue());
assertEquals(-3300000000L, bigIntContainer.getBigIntLeaf2().getValue().longValue());
assertEquals(-2800000000L, bigIntContainer.getBigIntLeaf3().getValue().longValue());
assertTrue(tinyUintContainerNode.isPresent());
- TinyUintContainer tinyUintContainer = tinyUintContainerNode.get();
+ TinyUintContainer tinyUintContainer = tinyUintContainerNode.orElseThrow();
assertEquals(150, tinyUintContainer.getTinyUintLeaf().getValue().shortValue());
assertEquals(150, tinyUintContainer.getTinyUintLeaf2().getValue().shortValue());
assertEquals(170, tinyUintContainer.getTinyUintLeaf3().getValue().shortValue());
assertTrue(smallUintContainerNode.isPresent());
- SmallUintContainer smallUintContainer = smallUintContainerNode.get();
+ SmallUintContainer smallUintContainer = smallUintContainerNode.orElseThrow();
assertEquals(35000, smallUintContainer.getSmallUintLeaf().getValue().intValue());
assertEquals(35000, smallUintContainer.getSmallUintLeaf2().getValue().intValue());
assertEquals(45000, smallUintContainer.getSmallUintLeaf3().getValue().intValue());
assertTrue(normalUintContainerNode.isPresent());
- NormalUintContainer normalUintContainer = normalUintContainerNode.get();
+ NormalUintContainer normalUintContainer = normalUintContainerNode.orElseThrow();
assertEquals(100000, normalUintContainer.getNormalUintLeaf().getValue().longValue());
assertEquals(100000, normalUintContainer.getNormalUintLeaf2().getValue().longValue());
assertEquals(250000, normalUintContainer.getNormalUintLeaf3().getValue().longValue());
assertTrue(bigUintContainerNode.isPresent());
- BigUintContainer bigUintContainer = bigUintContainerNode.get();
+ BigUintContainer bigUintContainer = bigUintContainerNode.orElseThrow();
assertEquals(5000000000L, bigUintContainer.getBigUintLeaf().getValue().longValue());
assertEquals(5000000000L, bigUintContainer.getBigUintLeaf2().getValue().longValue());
assertEquals(5800000000L, bigUintContainer.getBigUintLeaf3().getValue().longValue());
assertTrue(decimalContainerNode.isPresent());
- DecimalContainer decimalCont = decimalContainerNode.get();
+ DecimalContainer decimalCont = decimalContainerNode.orElseThrow();
assertEquals(66.66, decimalCont.getDecimalLeaf().getValue().doubleValue(), 0.001);
assertEquals(66.66, decimalCont.getDecimalLeaf2().getValue().doubleValue(), 0.001);
assertEquals(99.99, decimalCont.getDecimalLeaf3().getValue().doubleValue(), 0.001);
assertTrue(stringContainerNode.isPresent());
- StringContainer stringCont = stringContainerNode.get();
+ StringContainer stringCont = stringContainerNode.orElseThrow();
assertEquals("unspecified string", stringCont.getStringLeaf().getValue());
assertEquals("unspecified string", stringCont.getStringLeaf2().getValue());
assertEquals("unknown", stringCont.getStringLeaf3().getValue());
assertTrue(booleanContainerNode.isPresent());
- BooleanContainer boolCont = booleanContainerNode.get();
+ BooleanContainer boolCont = booleanContainerNode.orElseThrow();
assertTrue(boolCont.getBooleanLeaf());
assertNull(boolCont.getBooleanLeaf2());
}
assertTrue(enumContainerNode.isPresent());
- EnumContainer enumCont = enumContainerNode.get();
+ EnumContainer enumCont = enumContainerNode.orElseThrow();
assertEquals("Second", enumCont.getEnumLeaf().name());
assertEquals(2, enumCont.getEnumLeaf().getIntValue());
}
assertTrue(bitsContainerNode.isPresent());
- BitsContainer bitsCont = bitsContainerNode.get();
+ BitsContainer bitsCont = bitsContainerNode.orElseThrow();
assertFalse(bitsCont.getBitsLeaf().getBitZero());
assertTrue(bitsCont.getBitsLeaf().getBitOne());
assertFalse(bitsCont.getBitsLeaf().getBitTwo());
assertTrue(binaryContainerNode.isPresent());
- BinaryContainer binCont = binaryContainerNode.get();
+ BinaryContainer binCont = binaryContainerNode.orElseThrow();
byte [] expectedBytes = {104, 101, 108, 108, 111};
byte [] actualBytes = binCont.getBinaryLeaf();
assertTrue(identityrefContainerNode.isPresent());
- IdentityrefContainer idrefCont = identityrefContainerNode.get();
+ IdentityrefContainer idrefCont = identityrefContainerNode.orElseThrow();
assertNull(idrefCont.getIdentityrefLeaf());
assertSame(MyDerivedIdentity.VALUE, idrefCont.getIdentityrefLeaf2());
assertSame(MyDerivedIdentity.VALUE, idrefCont.getIdentityrefLeaf3());
final Optional<DataContainerCodecContext<?, ?>> optAugCtx = codecContext().possibleStreamChild(
(Class) augmentationType);
if (optAugCtx.isPresent()) {
- final DataContainerCodecContext<?, ?> augCtx = optAugCtx.get();
+ final DataContainerCodecContext<?, ?> augCtx = optAugCtx.orElseThrow();
// Due to binding specification not representing grouping instantiations we can end up having the same
// augmentation applied to a grouping multiple times. While these augmentations have the same shape, they
// are still represented by distinct binding classes and therefore we need to make sure the result matches
checkState(optType.isPresent(), "Failed to find return type for %s", method);
final Class<?> valueType;
- final Type genericType = optType.get();
- if (genericType instanceof Class<?>) {
- valueType = (Class<?>) genericType;
- } else if (genericType instanceof ParameterizedType) {
- valueType = (Class<?>) ((ParameterizedType) genericType).getRawType();
+ final Type genericType = optType.orElseThrow();
+ if (genericType instanceof Class<?> clazz) {
+ valueType = clazz;
+ } else if (genericType instanceof ParameterizedType parameterized) {
+ valueType = (Class<?>) parameterized.getRawType();
} else if (genericType instanceof WildcardType) {
// FIXME: MDSAL-670: this is not right as we need to find a concrete type
valueType = Object.class;
Identifiable.class);
checkState(optIdentifier.isPresent(), "Failed to find identifier for %s", listClz);
- final Class<Identifier<?>> identifier = optIdentifier.get();
+ final Class<Identifier<?>> identifier = optIdentifier.orElseThrow();
final Map<QName, ValueContext> valueCtx = new HashMap<>();
for (final ValueNodeCodecContext leaf : getLeafNodes(identifier, type.statement()).values()) {
final QName name = leaf.getDomPathArgument().getNodeType();
for (Method method : type.getMethods()) {
Optional<Class<? extends DataContainer>> entity = getYangModeledReturnType(method, Naming.GETTER_PREFIX);
if (entity.isPresent()) {
- ret.add((Class<? extends DataObject>) entity.get());
+ ret.add((Class<? extends DataObject>) entity.orElseThrow());
}
}
return ret;
final DataContainerCodecContext<?, ?> caze;
if (caseType.isPresent()) {
// Non-ambiguous addressing this should not pose any problems
- caze = choice.streamChild(caseType.get());
+ caze = choice.streamChild(caseType.orElseThrow());
} else {
caze = choice.getCaseByChildClass(type);
}
import static java.util.Objects.requireNonNull;
-import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.mdsal.binding.dom.codec.api.BindingTypeObjectCodecTreeNode;
import org.opendaylight.yangtools.yang.binding.TypeObject;
private static Object createDefaultObject(final LeafSchemaNode schema, final ValueCodec<Object, Object> codec,
final EffectiveModelContext schemaContext) {
- Optional<? extends Object> defaultValue = schema.getType().getDefaultValue();
+ var optDefaultValue = schema.getType().getDefaultValue();
TypeDefinition<?> type = schema.getType();
- if (defaultValue.isPresent()) {
+ if (optDefaultValue.isPresent()) {
+ final var defaultValue = optDefaultValue.orElseThrow();
if (type instanceof IdentityrefTypeDefinition) {
- return qnameDomValueFromString(codec, schema, (String) defaultValue.get(), schemaContext);
+ return qnameDomValueFromString(codec, schema, (String) defaultValue, schemaContext);
}
- return domValueFromString(codec, type, defaultValue.get());
+ return domValueFromString(codec, type, defaultValue);
}
- while (type.getBaseType() != null && !type.getDefaultValue().isPresent()) {
+ while (type.getBaseType() != null && type.getDefaultValue().isEmpty()) {
type = type.getBaseType();
}
- defaultValue = type.getDefaultValue();
- if (defaultValue.isPresent()) {
+ optDefaultValue = type.getDefaultValue();
+ if (optDefaultValue.isPresent()) {
+ final var defaultValue = optDefaultValue.orElseThrow();
if (type instanceof IdentityrefTypeDefinition) {
- return qnameDomValueFromString(codec, schema, (String) defaultValue.get(), schemaContext);
+ return qnameDomValueFromString(codec, schema, (String) defaultValue, schemaContext);
}
return domValueFromString(codec, type, defaultValue);
}
if (prefixEndIndex != -1) {
String defaultValuePrefix = defaultValue.substring(0, prefixEndIndex);
- Module module = schemaContext.findModule(schema.getQName().getModule()).get();
+ Module module = schemaContext.findModule(schema.getQName().getModule()).orElseThrow();
if (module.getPrefix().equals(defaultValuePrefix)) {
qname = QName.create(module.getQNameModule(), defaultValue.substring(prefixEndIndex + 1));
return codec.deserialize(qname);
for (ModuleImport moduleImport : module.getImports()) {
if (moduleImport.getPrefix().equals(defaultValuePrefix)) {
Module importedModule = schemaContext.findModule(moduleImport.getModuleName().getLocalName(),
- moduleImport.getRevision()).get();
+ moduleImport.getRevision()).orElseThrow();
qname = QName.create(importedModule.getQNameModule(), defaultValue.substring(prefixEndIndex + 1));
return codec.deserialize(qname);
}
final Optional<ParameterizedType> optParamType = ClassLoaderUtils.findParameterizedType(action, actionType);
checkState(optParamType.isPresent(), "%s does not specialize %s", action, actionType);
- final ParameterizedType paramType = optParamType.get();
+ final ParameterizedType paramType = optParamType.orElseThrow();
final Type[] args = paramType.getActualTypeArguments();
checkArgument(args.length == expectedArgsLength, "Unexpected (%s) Action generatic arguments", args.length);
final ActionRuntimeType schema = factory().getRuntimeContext().getActionDefinition(action);
}
private static MapNode getListItems(final NormalizedNode top) {
- return (MapNode) ((DataContainerNode) top).findChildByArg(TOP_LEVEL_LIST_ARG).get();
+ return (MapNode) ((DataContainerNode) top).getChildByArg(TOP_LEVEL_LIST_ARG);
}
private static void verifyLeafItemSame(final NormalizedNode firstCont, final NormalizedNode secondCont) {
final NormalizedNode translatedNN = translated.getValue();
assertNotNull(translatedNN);
// verify the union leaf is present
- Optional<NormalizedNode> leafNodeOpt = NormalizedNodes.findNode(translatedNN,
- NodeIdentifier.create(UNION_LEAF_QNAME));
- assertTrue(leafNodeOpt.isPresent());
// verify the leaf is the correct identity
- assertEquals(identityQname, leafNodeOpt.get().body());
+ assertEquals(Optional.of(identityQname),
+ NormalizedNodes.findNode(translatedNN, NodeIdentifier.create(UNION_LEAF_QNAME)).map(NormalizedNode::body));
}
}
// The pattern can be inverted
final Optional<ModifierKind> optModifier = patternConstraint.getModifier();
if (optModifier.isPresent()) {
- regEx = applyModifier(optModifier.get(), regEx);
+ regEx = applyModifier(optModifier.orElseThrow(), regEx);
}
regExps.put(regEx, patternConstraint.getRegularExpressionString());
assertNotNull(restrictions);
assertEquals(Set.of(Range.closed(1, 2)),
- restrictions.getLengthConstraint().get().getAllowedRanges().asRanges());
+ restrictions.getLengthConstraint().orElseThrow().getAllowedRanges().asRanges());
assertFalse(restrictions.getRangeConstraint().isPresent());
assertEquals(1, restrictions.getPatternConstraints().size());
final Optional<GeneratedType> optType = types.stream().filter(t -> typeName.equals(t.getIdentifier()))
.findFirst();
assertTrue(optType.isPresent());
- final GeneratedType genType = optType.get();
+ final GeneratedType genType = optType.orElseThrow();
final Iterator<Type> it = genType.getImplements().iterator();
final Type first = it.next();
assertTrue(first instanceof ParameterizedType);
GeneratedTransferObject lfLeaf = lfLeafs.get(0);
assertEquals("Lf has incorrect package name.",
"org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev130626.ParentContainer",
- lfLeaf.getIdentifier().immediatelyEnclosingClass().get().toString());
+ lfLeaf.getIdentifier().immediatelyEnclosingClass().orElseThrow().toString());
assertEquals("Lf generated TO has incorrect number of properties", 2, lfLeaf.getProperties().size());
containsAttributes(lfLeaf, true, true, true, new NameTypePattern("string", "String"));
assertEquals("Lf$1", lf1Leaf.getName());
assertEquals("Lf$1 has incorrect package name.",
"org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev130626.ParentContainer.Lf",
- lf1Leaf.getIdentifier().immediatelyEnclosingClass().get().toString());
+ lf1Leaf.getIdentifier().immediatelyEnclosingClass().orElseThrow().toString());
assertThat(lf1Leaf, instanceOf(GeneratedTransferObject.class));
final GeneratedTransferObject lf1gto = (GeneratedTransferObject) lf1Leaf;
assertEquals("Lf$2", lf2Leaf.getName());
assertEquals("Lf$2 has incorrect package name.",
"org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev130626.ParentContainer.Lf.Lf$1",
- lf2Leaf.getIdentifier().immediatelyEnclosingClass().get().toString());
+ lf2Leaf.getIdentifier().immediatelyEnclosingClass().orElseThrow().toString());
assertThat(lf2Leaf, instanceOf(GeneratedTransferObject.class));
assertEquals("BitLeaf has incorrect package name.",
"org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev130626.ParentContainer",
- bitLeaf.getIdentifier().immediatelyEnclosingClass().get().toString());
+ bitLeaf.getIdentifier().immediatelyEnclosingClass().orElseThrow().toString());
assertEquals("UnionLeaf has incorrect package name.",
"org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev130626.ParentContainer",
- unionLeaf.getIdentifier().immediatelyEnclosingClass().get().toString());
+ unionLeaf.getIdentifier().immediatelyEnclosingClass().orElseThrow().toString());
List<GeneratedProperty> propertiesBitLeaf = bitLeaf.getProperties();
GeneratedProperty firstBitProperty = null;
assertThat(linkUpDownTrapEnable, instanceOf(Enumeration.class));
assertEquals(
"org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev121115.interfaces.Interface",
- linkUpDownTrapEnable.getIdentifier().immediatelyEnclosingClass().get().toString());
+ linkUpDownTrapEnable.getIdentifier().immediatelyEnclosingClass().orElseThrow().toString());
assertNotNull("Expected Referenced Enum OperStatus, but was NULL!", operStatus);
assertThat(operStatus, instanceOf(Enumeration.class));
assertEquals(
"org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev121115.interfaces.Interface",
- operStatus.getIdentifier().immediatelyEnclosingClass().get().toString());
+ operStatus.getIdentifier().immediatelyEnclosingClass().orElseThrow().toString());
}
}
.findFirst();
assertTrue("Type for " + className + " not found", optType.isPresent());
- final GeneratedType type = optType.get();
+ final GeneratedType type = optType.orElseThrow();
assertThat(type, instanceOf(GeneratedTransferObject.class));
final GeneratedTransferObject gto = (GeneratedTransferObject) type;
assertEquals(2, gto.getEqualsIdentifiers().size());
assertEquals(4, generateTypes.size());
final GeneratedType mplsLabelType = generateTypes.stream().filter(type -> type.getFullyQualifiedName()
- .equals("org.opendaylight.yang.gen.v1.mdsal269.rev180130.MplsLabel")).findFirst().get();
+ .equals("org.opendaylight.yang.gen.v1.mdsal269.rev180130.MplsLabel")).findFirst().orElseThrow();
assertTrue(mplsLabelType instanceof GeneratedTransferObject);
final GeneratedTransferObject gto = (GeneratedTransferObject) mplsLabelType;
assertEquals(2, generateTypes.size());
final GeneratedType foo = generateTypes.stream().filter(type -> type.getFullyQualifiedName()
- .equals("org.opendaylight.yang.gen.v1.urn.odl.yt320.norev.Foo")).findFirst().get();
+ .equals("org.opendaylight.yang.gen.v1.urn.odl.yt320.norev.Foo")).findFirst().orElseThrow();
final List<GeneratedType> fooTypes = foo.getEnclosedTypes();
assertEquals(1, fooTypes.size());
assertFalse(it.hasNext());
final GeneratedProperty bar1Prop = bar.getProperties().stream().filter(prop -> "bar$1".equals(prop.getName()))
- .findFirst().get();
+ .findFirst().orElseThrow();
final Type bar1PropRet = bar1Prop.getReturnType();
assertEquals(bar1, bar1PropRet);
}
assertNotNull(generateTypes);
final GeneratedType typedefType = generateTypes.stream().filter(type -> type.getFullyQualifiedName()
- .equals("org.opendaylight.yang.gen.v1.urn.opendaylight.test.rev131008.MyBinary")).findFirst().get();
+ .equals("org.opendaylight.yang.gen.v1.urn.opendaylight.test.rev131008.MyBinary")).findFirst()
+ .orElseThrow();
assertNotNull(typedefType.getImplements());
Type objectType = typedefType.getImplements().stream()
.filter(type -> type.getFullyQualifiedName()
- .equals("org.opendaylight.yangtools.yang.binding.ScalarTypeObject")).findAny().get();
+ .equals("org.opendaylight.yangtools.yang.binding.ScalarTypeObject")).findAny().orElseThrow();
assertEquals(BindingTypes.scalarTypeObject(Types.BYTE_ARRAY), objectType);
}
assertNotNull(generateTypes);
final GeneratedType typedefType = generateTypes.stream().filter(type -> type.getFullyQualifiedName()
- .equals("org.opendaylight.yang.gen.v1.urn.opendaylight.test.rev131008.MyBits")).findFirst().get();
+ .equals("org.opendaylight.yang.gen.v1.urn.opendaylight.test.rev131008.MyBits")).findFirst()
+ .orElseThrow();
assertNotNull(typedefType.getImplements());
Type objectType = typedefType.getImplements().stream()
.filter(type -> type.getFullyQualifiedName()
- .equals("org.opendaylight.yangtools.yang.binding.BitsTypeObject")).findAny().get();
+ .equals("org.opendaylight.yangtools.yang.binding.BitsTypeObject")).findAny().orElseThrow();
assertEquals(BITS_TYPE_OBJECT, objectType);
}
assertNotNull(generateTypes);
final GeneratedType typedefType = generateTypes.stream().filter(type -> type.getFullyQualifiedName()
- .equals("org.opendaylight.yang.gen.v1.urn.opendaylight.test.rev131008.MyUnion")).findFirst().get();
+ .equals("org.opendaylight.yang.gen.v1.urn.opendaylight.test.rev131008.MyUnion")).findFirst()
+ .orElseThrow();
assertNotNull(typedefType.getImplements());
Type objectType = typedefType.getImplements().stream()
.filter(type -> type.getFullyQualifiedName()
- .equals("org.opendaylight.yangtools.yang.binding.UnionTypeObject")).findAny().get();
+ .equals("org.opendaylight.yangtools.yang.binding.UnionTypeObject")).findAny().orElseThrow();
assertEquals(UNION_TYPE_OBJECT, objectType);
}
}
def protected generateCheckers(GeneratedProperty field, Restrictions restrictions, Type actualType) '''
«IF restrictions.rangeConstraint.present»
«AbstractRangeGenerator.forType(actualType).generateRangeChecker(field.name.toFirstUpper,
- restrictions.rangeConstraint.get, this)»
+ restrictions.rangeConstraint.orElseThrow, this)»
«ENDIF»
«IF restrictions.lengthConstraint.present»
- «LengthGenerator.generateLengthChecker(field.fieldName, actualType, restrictions.lengthConstraint.get, this)»
+ «LengthGenerator.generateLengthChecker(field.fieldName, actualType, restrictions.lengthConstraint.orElseThrow, this)»
«ENDIF»
'''
package def findGetter(String getterName) {
val ownGetter = getterByName(type.nonDefaultMethods, getterName);
if (ownGetter.isPresent) {
- return ownGetter.get;
+ return ownGetter.orElseThrow
}
for (ifc : type.implements) {
if (ifc instanceof GeneratedType) {
val getter = findGetter(ifc, getterName)
if (getter.isPresent) {
- return (getter.get)
+ return (getter.orElseThrow)
}
}
}
«IF restrictions !== null»
«IF restrictions.lengthConstraint.present»
«LengthGenerator.generateLengthChecker("_value", TypeUtils.encapsulatedValueType(genTO),
- restrictions.lengthConstraint.get, this)»
+ restrictions.lengthConstraint.orElseThrow, this)»
«ENDIF»
«IF restrictions.rangeConstraint.present»
- «rangeGenerator.generateRangeChecker("_value", restrictions.rangeConstraint.get, this)»
+ «rangeGenerator.generateRangeChecker("_value", restrictions.rangeConstraint.orElseThrow, this)»
«ENDIF»
«ENDIF»
// Exposed for BuilderTemplate
boolean isLocalInnerClass(final JavaTypeName name) {
- final Optional<JavaTypeName> optEnc = name.immediatelyEnclosingClass();
- return optEnc.isPresent() && type.getIdentifier().equals(optEnc.get());
+ final var optEnc = name.immediatelyEnclosingClass();
+ return optEnc.isPresent() && type.getIdentifier().equals(optEnc.orElseThrow());
}
final CharSequence generateInnerClass(final GeneratedType innerClass) {
final Deque<String> queue = new ArrayDeque<>();
queue.addFirst(type.simpleName());
while (optEnclosing.isPresent()) {
- final JavaTypeName enclosing = optEnclosing.get();
+ final JavaTypeName enclosing = optEnclosing.orElseThrow();
if (enclosing.equals(getName())) {
return ImmutableList.copyOf(queue);
}
@«JavaFileTemplate.GENERATED»("mdsal-binding-generator")
public final class «MODULE_INFO_CLASS_NAME» extends ResourceYangModuleInfo {
«val rev = module.revision»
- private static final @NonNull QName NAME = QName.create("«module.QNameModule.namespace.toString»", «IF rev.present»"«rev.get.toString»", «ENDIF»"«module.name»").intern();
+ private static final @NonNull QName NAME = QName.create("«module.QNameModule.namespace.toString»", «IF rev.present»"«rev.orElseThrow.toString»", «ENDIF»"«module.name»").intern();
private static final @NonNull YangModuleInfo INSTANCE = new «MODULE_INFO_CLASS_NAME»();
private final @NonNull ImmutableSet<YangModuleInfo> importedModules;
«FOR imp : m.imports»
«val name = imp.moduleName.localName»
«val rev = imp.revision»
- «IF !rev.present»
+ «IF rev.empty»
«val TreeMap<Optional<Revision>, Module> sorted = new TreeMap(REVISION_COMPARATOR)»
«FOR module : ctx.modules»
«IF name.equals(module.name)»
private def sourcePath(ModuleLike module) {
val opt = moduleFilePathResolver.apply(module)
Preconditions.checkState(opt.isPresent, "Module %s does not have a file path", module)
- return opt.get
+ return opt.orElseThrow
}
private def generateSubInfo(Set<Submodule> submodules) '''
private static final class «className»Info extends ResourceYangModuleInfo {
«val rev = submodule.revision»
private final @NonNull QName NAME = QName.create("«submodule.QNameModule.namespace.toString»", «
- IF rev.present»"«rev.get.toString»", «ENDIF»"«submodule.name»").intern();
+ IF rev.present»"«rev.orElseThrow.toString»", «ENDIF»"«submodule.name»").intern();
private static final @NonNull YangModuleInfo INSTANCE = new «className»Info();
private final @NonNull ImmutableSet<YangModuleInfo> importedModules;
TopLevelList data = newTestDataObject();
managedNewTransactionRunner.callWithNewWriteOnlyTransactionAndSubmit(OPERATIONAL,
tx -> tx.put(TEST_PATH, data)).get();
- assertEquals(data, managedNewTransactionRunner.applyWithNewReadOnlyTransactionAndClose(OPERATIONAL,
- tx -> tx.read(TEST_PATH)).get().get());
+ assertEquals(Optional.of(data), managedNewTransactionRunner.applyWithNewReadOnlyTransactionAndClose(OPERATIONAL,
+ tx -> tx.read(TEST_PATH)).get());
}
TopLevelList newTestDataObject() {
<T extends DataObject> T syncRead(final LogicalDatastoreType datastoreType, final InstanceIdentifier<T> path)
throws ExecutionException, InterruptedException {
- return syncReadOptional(datastoreType, path).get();
+ return syncReadOptional(datastoreType, path).orElseThrow();
}
}
import static org.junit.Assert.assertEquals;
import static org.opendaylight.mdsal.binding.util.Datastore.OPERATIONAL;
+import java.util.Optional;
import org.junit.Test;
import org.opendaylight.mdsal.binding.api.DataBroker;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
managedNewTransactionRunner.callWithNewReadWriteTransactionAndSubmit(OPERATIONAL,
tx -> {
tx.put(TEST_PATH, data);
- assertEquals(data, tx.read(TEST_PATH).get().get());
+ assertEquals(Optional.of(data), tx.read(TEST_PATH).get());
}).get();
assertEquals(data, syncRead(LogicalDatastoreType.OPERATIONAL, TEST_PATH));
}
OPERATIONAL,
tx -> {
tx.put(TEST_PATH, data);
- return tx.read(TEST_PATH).get().get();
+ return tx.read(TEST_PATH).get().orElseThrow();
}).get());
assertEquals(data, syncRead(LogicalDatastoreType.OPERATIONAL, TEST_PATH));
}
private <T extends DataObject> T syncRead(final LogicalDatastoreType datastoreType,
final InstanceIdentifier<T> path) throws ExecutionException, InterruptedException {
- return syncReadOptional(datastoreType, path).get();
+ return syncReadOptional(datastoreType, path).orElseThrow();
}
}
return arg.getCaseType().isPresent() ? -1 : 1;
}
final Optional<? extends Class<?>> argCaseType = getCaseType();
- return argCaseType.isPresent() ? compareClasses(caseType.get(), argCaseType.get()) : 1;
+ return argCaseType.isPresent() ? compareClasses(caseType.orElseThrow(), argCaseType.orElseThrow()) : 1;
}
private static int compareClasses(final Class<?> first, final Class<?> second) {
if (optRev.isPresent()) {
// Revision is in format 2017-10-26, we want the output to be 171026, which is a matter of picking the
// right characters.
- final String rev = optRev.get().toString();
+ final String rev = optRev.orElseThrow().toString();
checkArgument(rev.length() == 10, "Unsupported revision %s", rev);
packageNameBuilder.append("rev").append(rev, 2, 4).append(rev, 5, 7).append(rev.substring(8));
} else {
// Routing key is present, attempt to deliver as a routed RPC
if (maybeKey.isPresent()) {
- final NormalizedNode key = maybeKey.get();
+ final NormalizedNode key = maybeKey.orElseThrow();
final Object value = key.body();
if (value instanceof YangInstanceIdentifier iid) {
// Find a DOMRpcImplementation for a specific iid
writeTx.commit().get();
assertEquals(Boolean.TRUE, domBroker.newReadOnlyTransaction().exists(OPERATIONAL, TestModel.TEST_PATH).get());
assertEquals(Boolean.TRUE, domBroker.newReadOnlyTransaction().read(OPERATIONAL, TestModel.TEST_PATH).get()
- .get().toString().contains(testContainer.toString()));
+ .orElseThrow().toString().contains(testContainer.toString()));
readRx.read(OPERATIONAL, TestModel.TEST_PATH).get(); // init backing tx before close
readRx.close();
candidateRoot = candidate.getRootNode();
checkChange(TEST_CONTAINER, TEST_CONTAINER_2, ModificationType.SUBTREE_MODIFIED, candidateRoot);
final DataTreeCandidateNode modifiedChild = candidateRoot.getModifiedChild(
- new YangInstanceIdentifier.NodeIdentifier(TestModel.OUTER_LIST_QNAME)).get();
+ new YangInstanceIdentifier.NodeIdentifier(TestModel.OUTER_LIST_QNAME)).orElseThrow();
checkChange(OUTER_LIST, OUTER_LIST_2, ModificationType.WRITE, modifiedChild);
listenerReg.close();
}
assertNotNull(candidate);
candidateRoot = candidate.getRootNode();
checkChange(OUTER_LIST, listAfter, ModificationType.SUBTREE_MODIFIED, candidateRoot);
- final DataTreeCandidateNode entry1Canditate = candidateRoot.getModifiedChild(outerListEntryId1).get();
+ final DataTreeCandidateNode entry1Canditate = candidateRoot.getModifiedChild(outerListEntryId1).orElseThrow();
checkChange(outerListEntry1, null, ModificationType.DELETE, entry1Canditate);
- final DataTreeCandidateNode entry2Canditate = candidateRoot.getModifiedChild(outerListEntryId2).get();
+ final DataTreeCandidateNode entry2Canditate = candidateRoot.getModifiedChild(outerListEntryId2).orElseThrow();
checkChange(null, outerListEntry2, ModificationType.WRITE, entry2Canditate);
- final DataTreeCandidateNode entry3Canditate = candidateRoot.getModifiedChild(outerListEntryId3).get();
+ final DataTreeCandidateNode entry3Canditate = candidateRoot.getModifiedChild(outerListEntryId3).orElseThrow();
checkChange(null, outerListEntry3, ModificationType.WRITE, entry3Canditate);
listenerReg.close();
}
final ModificationType expectedMod, final DataTreeCandidateNode candidateNode) {
if (expectedBefore != null) {
assertTrue(candidateNode.getDataBefore().isPresent());
- assertEquals(expectedBefore, candidateNode.getDataBefore().get());
+ assertEquals(expectedBefore, candidateNode.getDataBefore().orElseThrow());
} else {
assertFalse(candidateNode.getDataBefore().isPresent());
}
if (expectedAfter != null) {
assertTrue(candidateNode.getDataAfter().isPresent());
- assertEquals(expectedAfter, candidateNode.getDataAfter().get());
+ assertEquals(expectedAfter, candidateNode.getDataAfter().orElseThrow());
} else {
assertFalse(candidateNode.getDataAfter().isPresent());
}
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
+import java.util.Optional;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.mdsal.dom.api.DOMMountPoint;
assertTrue(mountPointService.getMountPoint(PATH).isPresent());
// Verify mount point schema context and service
- final DOMMountPoint mountPoint = mountPointService.getMountPoint(PATH).get();
- assertTrue(mountPoint.getService(DOMRpcService.class).isPresent());
- assertEquals(rpcService, mountPoint.getService(DOMRpcService.class).get());
+ final DOMMountPoint mountPoint = mountPointService.getMountPoint(PATH).orElseThrow();
+ assertEquals(Optional.of(rpcService), mountPoint.getService(DOMRpcService.class));
}
@Test
return reg;
}
- final NormalizedNode data = preExistingData.get();
+ final NormalizedNode data = preExistingData.orElseThrow();
if (treeId.isEmpty()) {
checkState(data instanceof DataContainerNode, "Unexpected root node %s", data);
if (((DataContainerNode) data).isEmpty()) {
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
+import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors;
import java.util.Optional;
/**
* Reads /test from writeTx Read should return container.
*/
- ListenableFuture<Optional<NormalizedNode>> writeTxContainer = writeTx.read(TestModel.TEST_PATH);
- assertEquals("read: isPresent", true, writeTxContainer.get().isPresent());
- assertEquals("read: data", testNode, writeTxContainer.get().get());
+ assertEquals(Optional.of(testNode), Futures.getDone(writeTx.read(TestModel.TEST_PATH)));
/**
* Reads /test from readTx Read should return Absent.
*/
- ListenableFuture<Optional<NormalizedNode>> readTxContainer = readTx.read(TestModel.TEST_PATH);
- assertEquals("read: isPresent", false, readTxContainer.get().isPresent());
+ assertEquals(Optional.empty(), Futures.getDone(readTx.read(TestModel.TEST_PATH)));
}
@Test
/**
* Reads /test from writeTx Read should return container.
*/
- ListenableFuture<Optional<NormalizedNode>> writeTxContainer = writeTx.read(TestModel.TEST_PATH);
- assertEquals("read: isPresent", true, writeTxContainer.get().isPresent());
- assertEquals("read: data", testNode, writeTxContainer.get().get());
+ assertEquals(Optional.of(testNode), Futures.getDone(writeTx.read(TestModel.TEST_PATH)));
DOMStoreThreePhaseCommitCohort cohort = writeTx.ready();
assertThreePhaseCommit(cohort);
- Optional<NormalizedNode> afterCommitRead = domStore.newReadOnlyTransaction().read(TestModel.TEST_PATH).get();
- assertEquals("After commit read: isPresent", true, afterCommitRead.isPresent());
- assertEquals("After commit read: data", testNode, afterCommitRead.get());
+ assertEquals(Optional.of(testNode),
+ Futures.getDone(domStore.newReadOnlyTransaction().read(TestModel.TEST_PATH)));
}
@Test
assertThreePhaseCommit(writeTx.ready());
- Optional<NormalizedNode> afterCommitRead = domStore.newReadOnlyTransaction().read(TestModel.TEST_PATH).get();
- assertEquals("After commit read: isPresent", true, afterCommitRead.isPresent());
+ assertTrue(Futures.getDone(domStore.newReadOnlyTransaction().read(TestModel.TEST_PATH)).isPresent());
// Delete /test and verify
assertThreePhaseCommit(writeTx.ready());
- afterCommitRead = domStore.newReadOnlyTransaction().read(TestModel.TEST_PATH).get();
- assertEquals("After commit read: isPresent", false, afterCommitRead.isPresent());
+ assertEquals(Optional.empty(), Futures.getDone(domStore.newReadOnlyTransaction().read(TestModel.TEST_PATH)));
}
@Test
assertThreePhaseCommit(writeTx.ready());
- Optional<NormalizedNode> afterCommitRead =
- domStore.newReadOnlyTransaction().read(TestModel.TEST_PATH).get();
- assertEquals("After commit read: isPresent", true, afterCommitRead.isPresent());
- assertEquals("After commit read: data", containerNode, afterCommitRead.get());
+ assertEquals(Optional.of(containerNode),
+ Futures.getDone(domStore.newReadOnlyTransaction().read(TestModel.TEST_PATH)));
// Merge a new list entry node
assertThreePhaseCommit(writeTx.ready());
- afterCommitRead = domStore.newReadOnlyTransaction().read(TestModel.TEST_PATH).get();
- assertEquals("After commit read: isPresent", true, afterCommitRead.isPresent());
- assertEquals("After commit read: data", containerNode, afterCommitRead.get());
+ assertEquals(Optional.of(containerNode),
+ Futures.getDone(domStore.newReadOnlyTransaction().read(TestModel.TEST_PATH)));
}
@Test
writeTx.merge(TestModel.TEST_PATH, containerNode);
- ListenableFuture<Boolean> exists = writeTx.exists(TestModel.TEST_PATH);
-
- assertEquals(Boolean.TRUE, exists.get());
+ assertEquals(Boolean.TRUE, Futures.getDone(writeTx.exists(TestModel.TEST_PATH)));
DOMStoreThreePhaseCommitCohort ready = writeTx.ready();
DOMStoreReadTransaction readTx = domStore.newReadOnlyTransaction();
assertNotNull(readTx);
- exists = readTx.exists(TestModel.TEST_PATH);
-
- assertEquals(Boolean.TRUE, exists.get());
+ assertEquals(Boolean.TRUE, Futures.getDone(readTx.exists(TestModel.TEST_PATH)));
}
@Test
final Optional<EntityOwnershipState> state = service.getOwnershipState(FOO_FOO_ENTITY);
assertNotNull(state);
assertTrue(state.isPresent());
- assertEquals(EntityOwnershipState.IS_OWNER, state.get());
+ assertEquals(EntityOwnershipState.IS_OWNER, state.orElseThrow());
reg.close();
assertFalse(service.isCandidateRegistered(FOO_FOO_ENTITY));