Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Update syntax up to language level 21 #5652

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ public StringBuilder forApproachRadek(/*final BuilderState builderState*/) {
// final StringBuilder builder = builderState.builder;
final StringBuilder builder = new StringBuilder();

for (int i = 0; i < strings.size(); i++) {
builder.append(strings.get(i));
for (String string : strings) {
builder.append(string);
builder.append(", ");
}

Comment on lines 95 to 101
Copy link
Member

@reinhapa reinhapa Mar 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use a StringJoiner instead of StringBuilder here..

Copy link
Member Author

@dizzzz dizzzz Mar 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure, it is a benchmark (test) class. I guess it is/was used to test several options to join text parts. We should hunt these in the core code probably?

For now, i'd keep it.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1943,7 +1943,7 @@ private boolean processCommandLineActions() throws IOException {
} else if (options.xpath.isPresent() || !options.queryFiles.isEmpty()) {
String xpath = null;
if (!options.queryFiles.isEmpty()) {
try (final BufferedReader reader = Files.newBufferedReader(options.queryFiles.get(0))) {
try (final BufferedReader reader = Files.newBufferedReader(options.queryFiles.getFirst())) {
final StringBuilder buf = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
Expand Down Expand Up @@ -2090,7 +2090,7 @@ public boolean run() throws Exception {
printNotice();

// Fix "uri" property: Excalibur CLI can't parse dashes, so we need to URL encode them:
properties.setProperty(URI, URLDecoder.decode(properties.getProperty(URI), UTF_8.name()));
properties.setProperty(URI, URLDecoder.decode(properties.getProperty(URI), UTF_8));

final boolean interactive = isInteractive();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,44 +133,48 @@ protected void read(final DBBroker broker, final Document doc, final boolean che
for (int i = 0; i < childNodes.getLength(); i++) {
Node node = childNodes.item(i);
if (NAMESPACE.equals(node.getNamespaceURI())) {
if (TRIGGERS_ELEMENT.equals(node.getLocalName())) {
final NodeList triggers = node.getChildNodes();
for (int j = 0; j < triggers.getLength(); j++) {
node = triggers.item(j);
if (node.getNodeType() == Node.ELEMENT_NODE && node.getLocalName().equals(TRIGGER_ELEMENT)) {
configureTrigger(broker.getBrokerPool().getClassLoader(), (Element) node, srcCollectionURI, checkOnly);
switch (node.getLocalName()) {
case TRIGGERS_ELEMENT -> {
final NodeList triggers = node.getChildNodes();
for (int j = 0; j < triggers.getLength(); j++) {
node = triggers.item(j);
if (node.getNodeType() == Node.ELEMENT_NODE && node.getLocalName().equals(TRIGGER_ELEMENT)) {
configureTrigger(broker.getBrokerPool().getClassLoader(), (Element) node, srcCollectionURI, checkOnly);
}
}
}
} else if (INDEX_ELEMENT.equals(node.getLocalName())) {
final Element elem = (Element) node;
try {
if (indexSpec == null) {
indexSpec = new IndexSpec(broker, elem);
} else {
indexSpec.read(broker, elem);
case INDEX_ELEMENT -> {
final Element elem = (Element) node;
try {
if (indexSpec == null) {
indexSpec = new IndexSpec(broker, elem);
} else {
indexSpec.read(broker, elem);
}
} catch (final DatabaseConfigurationException e) {
if (checkOnly) {
throw new CollectionConfigurationException(e.getMessage(), e);
} else {
LOG.warn(e.getMessage(), e);
}
}
} catch (final DatabaseConfigurationException e) {
if (checkOnly) {
throw new CollectionConfigurationException(e.getMessage(), e);

}
case VALIDATION_ELEMENT -> {
final Element elem = (Element) node;
final String mode = elem.getAttribute(VALIDATION_MODE_ATTR);
if (mode == null) {
LOG.debug("Unable to determine validation mode in {}", srcCollectionURI);
validationMode = XMLReaderObjectFactory.VALIDATION_SETTING.UNKNOWN;
} else {
LOG.warn(e.getMessage(), e);
LOG.debug("{} : Validation mode={}", srcCollectionURI, mode);
validationMode = XMLReaderObjectFactory.VALIDATION_SETTING.fromOption(mode);
}
}

} else if (VALIDATION_ELEMENT.equals(node.getLocalName())) {
final Element elem = (Element) node;
final String mode = elem.getAttribute(VALIDATION_MODE_ATTR);
if (mode == null) {
LOG.debug("Unable to determine validation mode in {}", srcCollectionURI);
validationMode = XMLReaderObjectFactory.VALIDATION_SETTING.UNKNOWN;
} else {
LOG.debug("{} : Validation mode={}", srcCollectionURI, mode);
validationMode = XMLReaderObjectFactory.VALIDATION_SETTING.fromOption(mode);
}

} else {
throwOrLog("Ignored node '" + node.getLocalName() +
case null, default -> throwOrLog("Ignored node '" + node.getLocalName() +
"' in configuration document", checkOnly);

//TODO : throw an exception like above ? -pb
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@ public void configure(final DBBroker broker, final Txn transaction, final Collec
if(separators == null || separators.size() != 1) {
throw new TriggerException("A separator parameter must be provided to the CSVExtractingTrigger configuration");
} else {
this.separator = separators.get(0);
this.separator = separators.getFirst();
}

//get the extractions
final List<Map<String, List>> paths = (List<Map<String, List>>)parameters.get("path");
for(final Map<String, List> path : paths){
final List<String> xpaths = path.get("xpath");
if(xpaths != null && xpaths.size() == 1) {
String xpath = xpaths.get(0);
String xpath = xpaths.getFirst();

//split out the path and preficate (if present) from the xpath
String pathExpr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,42 +241,32 @@ public void comment(final char[] ch, final int start, final int length) throws S
protected void applyDeferredEvents() throws SAXException {
SAXEvent event = null;
while((event = deferred.poll()) != null) {
if(event instanceof SetDocumentLocator setDocumentLocator) {
setDocumentLocator_deferred(setDocumentLocator.locator);
} else if(event instanceof StartDocument) {
startDocument_deferred();
} else if(event instanceof EndDocument) {
endDocument_deferred();
} else if(event instanceof StartPrefixMapping startPrefixMapping) {
startPrefixMapping_deferred(startPrefixMapping.prefix, startPrefixMapping.uri);
} else if(event instanceof EndPrefixMapping endPrefixMapping) {
endPrefixMapping_deferred(endPrefixMapping.prefix);
} else if(event instanceof StartElement startElement) {
startElement_deferred(startElement.namespaceURI, startElement.localName, startElement.qname, startElement.attributes);
} else if(event instanceof EndElement endElement) {
endElement_deferred(endElement.namespaceURI, endElement.localName, endElement.qname);
} else if(event instanceof Characters characters) {
characters_deferred(characters.ch, 0, characters.ch.length);
} else if(event instanceof IgnorableWhitespace ignorableWhitespace) {
ignorableWhitespace_deferred(ignorableWhitespace.ch, 0, ignorableWhitespace.ch.length);
} else if(event instanceof ProcessingInstruction processingInstruction) {
processingInstruction_deferred(processingInstruction.target, processingInstruction.data);
} else if(event instanceof SkippedEntity skippedEntity) {
skippedEntity_deferred(skippedEntity.name);
} else if(event instanceof StartDTD startDTD) {
startDTD_deferred(startDTD.name, startDTD.publicId, startDTD.systemId);
} else if(event instanceof EndDTD) {
endDTD_deferred();
} else if(event instanceof StartEntity startEntity) {
startEntity_deferred(startEntity.name);
} else if(event instanceof EndEntity endEntity) {
endEntity_deferred(endEntity.name);
} else if(event instanceof StartCDATA) {
startCDATA_deferred();
} else if(event instanceof EndCDATA) {
endCDATA_deferred();
} else if(event instanceof Comment comment) {
comment_deferred(comment.ch, 0, comment.ch.length);
switch (event) {
case SetDocumentLocator setDocumentLocator -> setDocumentLocator_deferred(setDocumentLocator.locator);
case StartDocument startDocument -> startDocument_deferred();
case EndDocument endDocument -> endDocument_deferred();
case StartPrefixMapping startPrefixMapping ->
startPrefixMapping_deferred(startPrefixMapping.prefix, startPrefixMapping.uri);
case EndPrefixMapping endPrefixMapping -> endPrefixMapping_deferred(endPrefixMapping.prefix);
case StartElement startElement ->
startElement_deferred(startElement.namespaceURI, startElement.localName, startElement.qname, startElement.attributes);
case EndElement endElement ->
endElement_deferred(endElement.namespaceURI, endElement.localName, endElement.qname);
case Characters characters -> characters_deferred(characters.ch, 0, characters.ch.length);
case IgnorableWhitespace ignorableWhitespace ->
ignorableWhitespace_deferred(ignorableWhitespace.ch, 0, ignorableWhitespace.ch.length);
case ProcessingInstruction processingInstruction ->
processingInstruction_deferred(processingInstruction.target, processingInstruction.data);
case SkippedEntity skippedEntity -> skippedEntity_deferred(skippedEntity.name);
case StartDTD startDTD -> startDTD_deferred(startDTD.name, startDTD.publicId, startDTD.systemId);
case EndDTD endDTD -> endDTD_deferred();
case StartEntity startEntity -> startEntity_deferred(startEntity.name);
case EndEntity endEntity -> endEntity_deferred(endEntity.name);
case StartCDATA startCDATA -> startCDATA_deferred();
case EndCDATA endCDATA -> endCDATA_deferred();
case Comment comment -> comment_deferred(comment.ch, 0, comment.ch.length);
default -> {
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void configure(final DBBroker broker, final Txn transaction, final Collec

if(parameters.containsKey(PARAM_ROOT_NAME)) {
try {
rootPath = XmldbURI.xmldbUriFor(parameters.get(PARAM_ROOT_NAME).get(0).toString());
rootPath = XmldbURI.xmldbUriFor(parameters.get(PARAM_ROOT_NAME).getFirst().toString());
} catch(final URISyntaxException e) {
throw new TriggerException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class STXTransformerTrigger extends SAXTrigger implements DocumentTrigger
@Override
public void configure(DBBroker broker, Txn transaction, Collection parent, Map<String, List<?>> parameters) throws TriggerException {
super.configure(broker, transaction, parent, parameters);
final String stylesheet = (String)parameters.get("src").get(0);
final String stylesheet = (String)parameters.get("src").getFirst();
if(stylesheet == null) {
throw new TriggerException("STXTransformerTrigger requires an attribute 'src'");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Iterator;
import java.util.Objects;

/**
* Avoid infinite recursions in Triggers by preventing the same trigger
Expand Down Expand Up @@ -59,38 +60,38 @@ public static void setAndTest(final Trigger trigger, final TriggerPhase triggerP

int skipBefores = 0;

for (final Iterator<TriggerState> it = states.iterator(); it.hasNext(); ) {
prevState = it.next();

// travel up, first "Before" we encounter - we should check if (a) that we complete it, and/or (b) is non-cyclic (if not we are also cyclic)
if (prevState.triggerPhase == TriggerPhase.BEFORE) {

if (skipBefores > 0) {
skipBefores--;

} else {
if (prevState.isCompletedBy(trigger, triggerPhase, triggerEvent, src, dst)) {
if (prevState instanceof PossibleCyclicTriggerState) {
// if the Before phase is a PossibleCyclicTriggerState then this completing After phase must also be a PossibleCyclicTriggerState
final TriggerState newState = new PossibleCyclicTriggerState(trigger, triggerPhase, triggerEvent, src, dst);
states.addFirst(newState);

throw new CyclicTriggerException("Detected Matching possible cyclic trigger event for After phase (" + newState + ") of previous Before phase (" + prevState + ")");

} else {
// if the Before Phase is NOT a PossibleCyclicTriggerState, then neither is this completing After phase...
states.addFirst(new TriggerState(trigger, triggerPhase, triggerEvent, src, dst));
return;
}

} else {
throw new IllegalStateException("Cannot interleave Trigger states");
}
}
} else if (prevState.triggerPhase == TriggerPhase.AFTER) {
skipBefores++;
}
}
for (TriggerState state : states) {
prevState = state;

// travel up, first "Before" we encounter - we should check if (a) that we complete it, and/or (b) is non-cyclic (if not we are also cyclic)
if (prevState.triggerPhase == TriggerPhase.BEFORE) {

if (skipBefores > 0) {
skipBefores--;

} else {
if (prevState.isCompletedBy(trigger, triggerPhase, triggerEvent, src, dst)) {
if (prevState instanceof PossibleCyclicTriggerState) {
// if the Before phase is a PossibleCyclicTriggerState then this completing After phase must also be a PossibleCyclicTriggerState
final TriggerState newState = new PossibleCyclicTriggerState(trigger, triggerPhase, triggerEvent, src, dst);
states.addFirst(newState);

throw new CyclicTriggerException("Detected Matching possible cyclic trigger event for After phase (" + newState + ") of previous Before phase (" + prevState + ")");

} else {
// if the Before Phase is NOT a PossibleCyclicTriggerState, then neither is this completing After phase...
states.addFirst(new TriggerState(trigger, triggerPhase, triggerEvent, src, dst));
return;
}

} else {
throw new IllegalStateException("Cannot interleave Trigger states");
}
}
} else if (prevState.triggerPhase == TriggerPhase.AFTER) {
skipBefores++;
}
}

throw new IllegalStateException("Could not find a matching Before phase for After phase");

Expand Down Expand Up @@ -238,7 +239,7 @@ private boolean equals(final Object o, final boolean ignorePhase) {
return false;
}

return dst != null ? dst.equals(that.dst) : that.dst == null;
return Objects.equals(dst, that.dst);
}

private boolean equalsIgnoringPhase(final Trigger otherTrigger, final TriggerEvent otherTriggerEvent, final XmldbURI otherSrc, @Nullable final XmldbURI otherDst) {
Expand All @@ -254,7 +255,7 @@ private boolean equalsIgnoringPhase(final Trigger otherTrigger, final TriggerEve
return false;
}

return dst != null ? dst.equals(otherDst) : otherDst == null;
return Objects.equals(dst, otherDst);
}

public boolean isCompletedBy(final Trigger otherTrigger, final TriggerPhase otherTriggerPhase, final TriggerEvent otherTriggerEvent, final XmldbURI otherSrc, @Nullable final XmldbURI otherDst) {
Expand All @@ -275,7 +276,7 @@ public boolean isCompletedBy(final Trigger otherTrigger, final TriggerPhase othe
return false;
}

return dst != null ? dst.equals(otherDst) : otherDst == null;
return Objects.equals(dst, otherDst);
}

public boolean completes(final Object o) {
Expand Down Expand Up @@ -306,7 +307,7 @@ public boolean completes(final Object o) {
return false;
}

return dst != null ? dst.equals(that.dst) : that.dst == null;
return Objects.equals(dst, that.dst);
}
}
}
Loading
Loading