Use pattern matching on instanceof to simplify our code.
Change-Id: I1399f78a5b25558b6437434e1c316790cfc50e23
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
@Override
public boolean equals(final Object obj) {
- if (this == obj) {
- return true;
- }
- if (!(obj instanceof SchemaContextFactoryConfiguration)) {
- return false;
- }
- final SchemaContextFactoryConfiguration other = (SchemaContextFactoryConfiguration) obj;
- return filter.equals(other.filter) && statementParserMode.equals(other.statementParserMode)
- && Objects.equals(supportedFeatures, other.supportedFeatures)
- && Objects.equals(modulesDeviatedByModules, other.modulesDeviatedByModules);
+ return this == obj || obj instanceof SchemaContextFactoryConfiguration other && filter.equals(other.filter)
+ && statementParserMode.equals(other.statementParserMode)
+ && Objects.equals(supportedFeatures, other.supportedFeatures)
+ && Objects.equals(modulesDeviatedByModules, other.modulesDeviatedByModules);
}
@Override
}
private static @Nullable YinDomSchemaSource castSchemaSource(final YinXmlSchemaSource xmlSchemaSource) {
- if (xmlSchemaSource instanceof YinDomSchemaSource) {
- return (YinDomSchemaSource) xmlSchemaSource;
+ if (xmlSchemaSource instanceof YinDomSchemaSource yinDom) {
+ return yinDom;
}
final Source source = xmlSchemaSource.getSource();
- if (source instanceof DOMSource) {
- return create(xmlSchemaSource.getIdentifier(), (DOMSource) source,
- xmlSchemaSource.getSymbolicName().orElse(null));
+ if (source instanceof DOMSource dom) {
+ return create(xmlSchemaSource.getIdentifier(), dom, xmlSchemaSource.getSymbolicName().orElse(null));
}
-
return null;
}
@Override
public boolean equals(final Object obj) {
- if (this == obj) {
- return true;
- }
- if (!(obj instanceof PotentialSchemaSource)) {
- return false;
- }
- final PotentialSchemaSource<?> other = (PotentialSchemaSource<?>) obj;
- return cost == other.cost && representation.equals(other.representation)
- && sourceIdentifier.equals(other.sourceIdentifier);
+ return this == obj || obj instanceof PotentialSchemaSource<?> other && cost == other.cost
+ && representation.equals(other.representation) && sourceIdentifier.equals(other.sourceIdentifier);
}
}