Skip to content

Commit 7a0b204

Browse files
committed
Use switch statement for readability of code.
1 parent 53e4520 commit 7a0b204

File tree

5 files changed

+194
-155
lines changed

5 files changed

+194
-155
lines changed

exist-core/src/main/java/org/exist/Indexer.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,16 @@ public Indexer(final DBBroker broker, final Txn transaction)
164164
final String suppressWS = (String) config
165165
.getProperty(PROPERTY_SUPPRESS_WHITESPACE);
166166
if (suppressWS != null) {
167-
if ("leading".equals(suppressWS)) {
168-
normalize = XMLString.SUPPRESS_LEADING_WS;
169-
} else if ("trailing".equals(suppressWS)) {
170-
normalize = XMLString.SUPPRESS_TRAILING_WS;
171-
} else if ("none".equals(suppressWS)) {
172-
normalize = 0;
167+
switch (suppressWS) {
168+
case "leading":
169+
normalize = XMLString.SUPPRESS_LEADING_WS;
170+
break;
171+
case "trailing":
172+
normalize = XMLString.SUPPRESS_TRAILING_WS;
173+
break;
174+
case "none":
175+
normalize = 0;
176+
break;
173177
}
174178
}
175179
Boolean temp;

exist-core/src/main/java/org/exist/dom/persistent/XMLUtil.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,19 @@ public static final String decodeAttrMarkup(final String str) {
110110
p = str.indexOf(';', i);
111111
if(p != Constants.STRING_NOT_FOUND) {
112112
ent = str.substring(i + 1, p);
113-
if("amp".equals(ent)) {
114-
out.append('&');
115-
} else if("lt".equals(ent)) {
116-
out.append('<');
117-
} else if("gt".equals(ent)) {
118-
out.append('>');
119-
} else if("quot".equals(ent)) {
120-
out.append('"');
113+
switch (ent) {
114+
case "amp":
115+
out.append('&');
116+
break;
117+
case "lt":
118+
out.append('<');
119+
break;
120+
case "gt":
121+
out.append('>');
122+
break;
123+
case "quot":
124+
out.append('"');
125+
break;
121126
}
122127
i = p;
123128
continue;

exist-core/src/main/java/org/exist/http/servlets/EXistServlet.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,13 @@ public void init(ServletConfig config) throws ServletException {
9494
private FeatureEnabled parseFeatureEnabled(final ServletConfig config, final String paramName, final FeatureEnabled defaultValue) {
9595
final String paramValue = config.getInitParameter(paramName);
9696
if(paramValue != null) {
97-
if (paramValue.equals("disabled")) {
98-
return FeatureEnabled.FALSE;
99-
} else if (paramValue.equals("enabled")) {
100-
return FeatureEnabled.TRUE;
101-
} else if (paramValue.equals("authenticated")) {
102-
return FeatureEnabled.AUTHENTICATED_USERS_ONLY;
97+
switch (paramValue) {
98+
case "disabled":
99+
return FeatureEnabled.FALSE;
100+
case "enabled":
101+
return FeatureEnabled.TRUE;
102+
case "authenticated":
103+
return FeatureEnabled.AUTHENTICATED_USERS_ONLY;
103104
}
104105
}
105106

exist-core/src/main/java/org/exist/xquery/regex/JDK15RegexTranslator.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -967,16 +967,21 @@ private static CharClass computeSubCategoryCharClass(String name) {
967967
final int[] addRanges = RegexData.CATEGORY_RANGES[sci / 2];
968968
for (int i = 0; i < addRanges.length; i += 2)
969969
classes.add(new CharRange(addRanges[i], addRanges[i + 1]));
970-
if ("Lu".equals(name))
971-
{classes.add(new SingleChar(RegexData.UNICODE_3_1_ADD_Lu));}
972-
else if ("Ll".equals(name))
973-
{classes.add(new SingleChar(RegexData.UNICODE_3_1_ADD_Ll));}
974-
else if ("Nl".equals(name))
975-
{classes.add(new CharRange(RegexData.UNICODE_3_1_CHANGE_No_to_Nl_MIN, RegexData.UNICODE_3_1_CHANGE_No_to_Nl_MAX));}
976-
else if ("No".equals(name))
977-
{return new Subtraction(new Union(classes),
978-
new CharRange(RegexData.UNICODE_3_1_CHANGE_No_to_Nl_MIN,
979-
RegexData.UNICODE_3_1_CHANGE_No_to_Nl_MAX));}
970+
switch (name) {
971+
case "Lu":
972+
classes.add(new SingleChar(RegexData.UNICODE_3_1_ADD_Lu));
973+
break;
974+
case "Ll":
975+
classes.add(new SingleChar(RegexData.UNICODE_3_1_ADD_Ll));
976+
break;
977+
case "Nl":
978+
classes.add(new CharRange(RegexData.UNICODE_3_1_CHANGE_No_to_Nl_MIN, RegexData.UNICODE_3_1_CHANGE_No_to_Nl_MAX));
979+
break;
980+
case "No":
981+
return new Subtraction(new Union(classes),
982+
new CharRange(RegexData.UNICODE_3_1_CHANGE_No_to_Nl_MIN,
983+
RegexData.UNICODE_3_1_CHANGE_No_to_Nl_MAX));
984+
}
980985
return new Union(classes);
981986
}
982987

exist-core/src/main/java/org/exist/xupdate/XUpdateProcessor.java

Lines changed: 149 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -361,142 +361,166 @@ public void startElement(
361361
}
362362

363363
// start a new modification section
364-
if (APPEND.equals(localName)) {
365-
final String child = atts.getValue("child");
366-
modification = new Append(broker, documentSet, select, child, namespaces, variables);
367-
} else if (UPDATE.equals(localName))
368-
{modification = new Update(broker, documentSet, select, namespaces, variables);}
369-
else if (INSERT_BEFORE.equals(localName))
370-
{modification =
371-
new Insert(broker, documentSet, select, Insert.INSERT_BEFORE, namespaces, variables);}
372-
else if (INSERT_AFTER.equals(localName))
373-
{modification =
374-
new Insert(broker, documentSet, select, Insert.INSERT_AFTER, namespaces, variables);}
375-
else if (REMOVE.equals(localName))
376-
{modification = new Remove(broker, documentSet, select, namespaces, variables);}
377-
else if (RENAME.equals(localName))
378-
{modification = new Rename(broker, documentSet, select, namespaces, variables);}
379-
else if (REPLACE.equals(localName))
380-
{modification = new Replace(broker, documentSet, select, namespaces, variables);}
381-
382-
// process commands for node creation
383-
else if (ELEMENT.equals(localName)) {
384-
String name = atts.getValue("name");
385-
if (name == null)
386-
{throw new SAXException("element requires a name attribute");}
387-
final int p = name.indexOf(':');
388-
String namespace = null;
389-
String prefix = "";
390-
if (p != Constants.STRING_NOT_FOUND) {
391-
prefix = name.substring(0, p);
392-
if (name.length() == p + 1)
393-
{throw new SAXException(
394-
"illegal prefix in qname: " + name);}
395-
name = name.substring(p + 1);
396-
namespace = atts.getValue("namespace");
397-
if(namespace == null)
398-
{namespace = (String) namespaces.get(prefix);}
399-
if (namespace == null) {
400-
throw new SAXException(
401-
"no namespace defined for prefix " + prefix);
364+
switch (localName) {
365+
case APPEND:
366+
final String child = atts.getValue("child");
367+
modification = new Append(broker, documentSet, select, child, namespaces, variables);
368+
break;
369+
case UPDATE:
370+
modification = new Update(broker, documentSet, select, namespaces, variables);
371+
break;
372+
case INSERT_BEFORE:
373+
modification =
374+
new Insert(broker, documentSet, select, Insert.INSERT_BEFORE, namespaces, variables);
375+
break;
376+
case INSERT_AFTER:
377+
modification =
378+
new Insert(broker, documentSet, select, Insert.INSERT_AFTER, namespaces, variables);
379+
break;
380+
case REMOVE:
381+
modification = new Remove(broker, documentSet, select, namespaces, variables);
382+
break;
383+
case RENAME:
384+
modification = new Rename(broker, documentSet, select, namespaces, variables);
385+
break;
386+
case REPLACE:
387+
modification = new Replace(broker, documentSet, select, namespaces, variables);
388+
break;
389+
390+
// process commands for node creation
391+
case ELEMENT: {
392+
String name = atts.getValue("name");
393+
if (name == null) {
394+
throw new SAXException("element requires a name attribute");
395+
}
396+
final int p = name.indexOf(':');
397+
String namespace = null;
398+
String prefix = "";
399+
if (p != Constants.STRING_NOT_FOUND) {
400+
prefix = name.substring(0, p);
401+
if (name.length() == p + 1) {
402+
throw new SAXException(
403+
"illegal prefix in qname: " + name);
404+
}
405+
name = name.substring(p + 1);
406+
namespace = atts.getValue("namespace");
407+
if (namespace == null) {
408+
namespace = (String) namespaces.get(prefix);
409+
}
410+
if (namespace == null) {
411+
throw new SAXException(
412+
"no namespace defined for prefix " + prefix);
413+
}
414+
}
415+
Element elem;
416+
if (namespace != null && namespace.length() > 0) {
417+
elem = doc.createElementNS(namespace, name);
418+
elem.setPrefix(prefix);
419+
} else {
420+
elem = doc.createElement(name);
402421
}
403-
}
404-
Element elem;
405-
if (namespace != null && namespace.length() > 0)
406-
{
407-
elem = doc.createElementNS(namespace, name);
408-
elem.setPrefix(prefix);
409-
}
410-
else
411-
{elem = doc.createElement(name);}
412422

413-
final Element last = stack.peek();
414-
if (last == null) {
415-
contents.add(elem);
416-
} else {
417-
last.appendChild(elem);
418-
}
423+
final Element last = stack.peek();
424+
if (last == null) {
425+
contents.add(elem);
426+
} else {
427+
last.appendChild(elem);
428+
}
419429

420-
stack.push(elem);
421-
this.setWhitespaceHandling(elem);
422-
} else if (ATTRIBUTE.equals(localName)) {
423-
final String name = atts.getValue("name");
424-
if (name == null)
425-
{throw new SAXException("attribute requires a name attribute");}
426-
final int p = name.indexOf(':');
427-
String namespace = null;
428-
if (p != Constants.STRING_NOT_FOUND) {
429-
final String prefix = name.substring(0, p);
430-
if (name.length() == p + 1)
431-
{throw new SAXException(
432-
"illegal prefix in qname: " + name);}
433-
namespace = atts.getValue("namespace");
434-
if(namespace == null)
435-
{namespace = (String) namespaces.get(prefix);}
436-
if (namespace == null)
437-
{throw new SAXException(
438-
"no namespace defined for prefix " + prefix);}
430+
stack.push(elem);
431+
this.setWhitespaceHandling(elem);
432+
break;
439433
}
440-
Attr attrib = namespace != null && namespace.length() > 0 ?
441-
doc.createAttributeNS(namespace, name) :
442-
doc.createAttribute(name);
443-
if (stack.isEmpty()) {
444-
for(int i = 0; i < contents.getLength(); i++) {
445-
final Node n = contents.item(i);
446-
String ns = n.getNamespaceURI();
447-
final String nname = ns == null ? n.getNodeName() : n.getLocalName();
448-
if(ns == null) {
449-
ns = XMLConstants.NULL_NS_URI;
434+
case ATTRIBUTE: {
435+
final String name = atts.getValue("name");
436+
if (name == null) {
437+
throw new SAXException("attribute requires a name attribute");
438+
}
439+
final int p = name.indexOf(':');
440+
String namespace = null;
441+
if (p != Constants.STRING_NOT_FOUND) {
442+
final String prefix = name.substring(0, p);
443+
if (name.length() == p + 1) {
444+
throw new SAXException(
445+
"illegal prefix in qname: " + name);
446+
}
447+
namespace = atts.getValue("namespace");
448+
if (namespace == null) {
449+
namespace = (String) namespaces.get(prefix);
450+
}
451+
if (namespace == null) {
452+
throw new SAXException(
453+
"no namespace defined for prefix " + prefix);
450454
}
451-
// check for duplicate attributes
452-
if(n.getNodeType() == Node.ATTRIBUTE_NODE &&
453-
nname.equals(name) &&
454-
ns.equals(namespace))
455-
{throw new SAXException("The attribute " + attrib.getNodeName() + " cannot be specified twice");}
456455
}
457-
contents.add(attrib);
458-
} else {
459-
final Element last = stack.peek();
460-
if(namespace != null && last.hasAttributeNS(namespace, name) ||
461-
namespace == null && last.hasAttribute(name))
462-
{throw new SAXException("The attribute " + attrib.getNodeName() + " cannot be specified " +
463-
"twice on the same element");}
464-
if (namespace != null)
465-
{last.setAttributeNodeNS(attrib);}
466-
else
467-
{last.setAttributeNode(attrib);}
468-
}
469-
inAttribute = true;
470-
currentNode = attrib;
471-
472-
// process value-of
473-
} else if (VALUE_OF.equals(localName)) {
474-
select = atts.getValue("select");
475-
if (select == null)
476-
{throw new SAXException("value-of requires a select attribute");}
477-
final Sequence seq = processQuery(select);
478-
if (LOG.isDebugEnabled())
479-
{LOG.debug("Found " + seq.getItemCount() + " items for value-of");}
480-
Item item;
481-
try {
482-
for (final SequenceIterator i = seq.iterate(); i.hasNext();) {
483-
item = i.nextItem();
484-
if(Type.subTypeOf(item.getType(), Type.NODE)) {
485-
final Node node = NodeSetHelper.copyNode(doc, ((NodeValue)item).getNode());
486-
final Element last = stack.peek();
487-
if (last == null) {
488-
contents.add(node);
489-
} else {
490-
last.appendChild(node);
456+
Attr attrib = namespace != null && namespace.length() > 0 ?
457+
doc.createAttributeNS(namespace, name) :
458+
doc.createAttribute(name);
459+
if (stack.isEmpty()) {
460+
for (int i = 0; i < contents.getLength(); i++) {
461+
final Node n = contents.item(i);
462+
String ns = n.getNamespaceURI();
463+
final String nname = ns == null ? n.getNodeName() : n.getLocalName();
464+
if (ns == null) {
465+
ns = XMLConstants.NULL_NS_URI;
491466
}
467+
// check for duplicate attributes
468+
if (n.getNodeType() == Node.ATTRIBUTE_NODE &&
469+
nname.equals(name) &&
470+
ns.equals(namespace)) {
471+
throw new SAXException("The attribute " + attrib.getNodeName() + " cannot be specified twice");
472+
}
473+
}
474+
contents.add(attrib);
475+
} else {
476+
final Element last = stack.peek();
477+
if (namespace != null && last.hasAttributeNS(namespace, name) ||
478+
namespace == null && last.hasAttribute(name)) {
479+
throw new SAXException("The attribute " + attrib.getNodeName() + " cannot be specified " +
480+
"twice on the same element");
481+
}
482+
if (namespace != null) {
483+
last.setAttributeNodeNS(attrib);
492484
} else {
493-
final String value = item.getStringValue();
494-
characters(value.toCharArray(), 0, value.length());
485+
last.setAttributeNode(attrib);
495486
}
496487
}
497-
} catch (final XPathException e) {
498-
throw new SAXException(e.getMessage(), e);
488+
inAttribute = true;
489+
currentNode = attrib;
490+
491+
// process value-of
492+
break;
499493
}
494+
case VALUE_OF:
495+
select = atts.getValue("select");
496+
if (select == null) {
497+
throw new SAXException("value-of requires a select attribute");
498+
}
499+
final Sequence seq = processQuery(select);
500+
if (LOG.isDebugEnabled()) {
501+
LOG.debug("Found " + seq.getItemCount() + " items for value-of");
502+
}
503+
Item item;
504+
try {
505+
for (final SequenceIterator i = seq.iterate(); i.hasNext(); ) {
506+
item = i.nextItem();
507+
if (Type.subTypeOf(item.getType(), Type.NODE)) {
508+
final Node node = NodeSetHelper.copyNode(doc, ((NodeValue) item).getNode());
509+
final Element last = stack.peek();
510+
if (last == null) {
511+
contents.add(node);
512+
} else {
513+
last.appendChild(node);
514+
}
515+
} else {
516+
final String value = item.getStringValue();
517+
characters(value.toCharArray(), 0, value.length());
518+
}
519+
}
520+
} catch (final XPathException e) {
521+
throw new SAXException(e.getMessage(), e);
522+
}
523+
break;
500524
}
501525
} else if (inModification) {
502526
final Element elem = namespaceURI != null && namespaceURI.length() > 0 ?

0 commit comments

Comments
 (0)