Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -33,7 +33,7 @@ public class PrettyPrintXMLWriter implements XMLWriter {

private PrintWriter writer;

private LinkedList<String> elementStack = new LinkedList<String>();
private LinkedList<String> elementStack = new LinkedList<>();

private boolean tagInProgress;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class SerializerXMLWriter implements XMLWriter {

private final String namespace;

private final Stack<String> elements = new Stack<String>();
private final Stack<String> elements = new Stack<>();

private List<Exception> exceptions;

Expand Down Expand Up @@ -95,7 +95,7 @@ public void endElement() {
*/
private void storeException(IOException e) {
if (exceptions == null) {
exceptions = new ArrayList<Exception>();
exceptions = new ArrayList<>();
}
exceptions.add(e);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/codehaus/plexus/util/xml/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
* @since 1.0
*
*/
class StringUtils {
final class StringUtils {
/**
* <p>
* <code>StringUtils</code> instances should NOT be constructed in standard programming. Instead, the class should
Expand All @@ -100,7 +100,7 @@ private StringUtils() {}
* @return <code>true</code> if the String is <code>null</code>, or length zero
*/
public static boolean isEmpty(String str) {
return ((str == null) || (str.isEmpty()));
return (str == null) || (str.isEmpty());
}

// Splitting
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/org/codehaus/plexus/util/xml/XmlReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public XmlReader(InputStream is, String httpContentType) throws IOException {
*/
public XmlReader(InputStream is, String httpContentType, boolean lenient, String defaultEncoding)
throws IOException, XmlStreamReaderException {
_defaultEncoding = (defaultEncoding == null) ? _staticDefaultEncoding : defaultEncoding;
_defaultEncoding = defaultEncoding == null ? _staticDefaultEncoding : defaultEncoding;
try {
doHttpStream(is, httpContentType, lenient);
} catch (XmlStreamReaderException ex) {
Expand Down Expand Up @@ -346,7 +346,7 @@ private void doLenientDetection(String httpContentType, XmlStreamReaderException
encoding = ex.getContentTypeEncoding();
}
if (encoding == null) {
encoding = (_defaultEncoding == null) ? UTF_8 : _defaultEncoding;
encoding = _defaultEncoding == null ? UTF_8 : _defaultEncoding;
}
prepareReader(ex.getInputStream(), encoding);
}
Expand Down Expand Up @@ -409,7 +409,7 @@ private String calculateRawEncoding(String bomEnc, String xmlGuessEnc, String xm
String encoding;
if (bomEnc == null) {
if (xmlGuessEnc == null || xmlEnc == null) {
encoding = (_defaultEncoding == null) ? UTF_8 : _defaultEncoding;
encoding = _defaultEncoding == null ? UTF_8 : _defaultEncoding;
} else if (xmlEnc.equals(UTF_16) && (xmlGuessEnc.equals(UTF_16BE) || xmlGuessEnc.equals(UTF_16LE))) {
encoding = xmlGuessEnc;
} else {
Expand Down Expand Up @@ -460,7 +460,7 @@ private String calculateHttpEncoding(
if (appXml) {
encoding = calculateRawEncoding(bomEnc, xmlGuessEnc, xmlEnc, is);
} else {
encoding = (_defaultEncoding == null) ? US_ASCII : _defaultEncoding;
encoding = _defaultEncoding == null ? US_ASCII : _defaultEncoding;
}
} else if (bomEnc != null && (cTEnc.equals(UTF_16BE) || cTEnc.equals(UTF_16LE))) {
throw new XmlStreamReaderException(
Expand Down Expand Up @@ -506,7 +506,7 @@ private static String getContentTypeMime(String httpContentType) {
String mime = null;
if (httpContentType != null) {
int i = httpContentType.indexOf(";");
mime = ((i == -1) ? httpContentType : httpContentType.substring(0, i)).trim();
mime = (i == -1 ? httpContentType : httpContentType.substring(0, i)).trim();
}
return mime;
}
Expand All @@ -521,8 +521,8 @@ private static String getContentTypeEncoding(String httpContentType) {
if (i > -1) {
String postMime = httpContentType.substring(i + 1);
Matcher m = CHARSET_PATTERN.matcher(postMime);
encoding = (m.find()) ? m.group(1) : null;
encoding = (encoding != null) ? encoding.toUpperCase(Locale.ENGLISH) : null;
encoding = m.find() ? m.group(1) : null;
encoding = encoding != null ? encoding.toUpperCase(Locale.ENGLISH) : null;
}
}
return encoding;
Expand Down
21 changes: 10 additions & 11 deletions src/main/java/org/codehaus/plexus/util/xml/Xpp3Dom.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public Xpp3Dom(Xpp3Dom src, String name) {

int childCount = src.getChildCount();

childList = new ArrayList<Xpp3Dom>(childCount);
childList = new ArrayList<>(childCount);

setValue(src.getValue());

Expand Down Expand Up @@ -164,7 +164,7 @@ public String[] getAttributeNames() {
}

public String getAttribute(String name) {
return (null != attributes) ? attributes.get(name) : null;
return null != attributes ? attributes.get(name) : null;
}

/**
Expand All @@ -191,7 +191,7 @@ public void setAttribute(String name, String value) {
throw new NullPointerException("Attribute name can not be null");
}
if (null == attributes) {
attributes = new HashMap<String, String>();
attributes = new HashMap<>();
}

attributes.put(name, value);
Expand Down Expand Up @@ -244,7 +244,7 @@ private List<Xpp3Dom> getChildrenAsList(String name) {
for (Xpp3Dom configuration : childList) {
if (name.equals(configuration.getName())) {
if (children == null) {
children = new ArrayList<Xpp3Dom>();
children = new ArrayList<>();
}
children.add(configuration);
}
Expand Down Expand Up @@ -320,7 +320,7 @@ public void writeToSerializer(String namespace, XmlSerializer serializer) throws
// document - not the desired behaviour!
SerializerXMLWriter xmlWriter = new SerializerXMLWriter(namespace, serializer);
Xpp3DomWriter.write(xmlWriter, this);
if (xmlWriter.getExceptions().size() > 0) {
if (!xmlWriter.getExceptions().isEmpty()) {
throw (IOException) xmlWriter.getExceptions().get(0);
}
}
Expand Down Expand Up @@ -418,14 +418,14 @@ private static void mergeIntoXpp3Dom(Xpp3Dom dominant, Xpp3Dom recessive, Boolea
dominant.addChild(aDominantChildren);
}
} else {
Map<String, Iterator<Xpp3Dom>> commonChildren = new HashMap<String, Iterator<Xpp3Dom>>();
Map<String, Iterator<Xpp3Dom>> commonChildren = new HashMap<>();

for (Xpp3Dom recChild : recessive.childList) {
if (commonChildren.containsKey(recChild.name)) {
continue;
}
List<Xpp3Dom> dominantChildren = dominant.getChildrenAsList(recChild.name);
if (dominantChildren.size() > 0) {
if (!dominantChildren.isEmpty()) {
commonChildren.put(recChild.name, dominantChildren.iterator());
}
}
Expand Down Expand Up @@ -524,8 +524,7 @@ public int hashCode() {
result = 37 * result + (name != null ? name.hashCode() : 0);
result = 37 * result + (value != null ? value.hashCode() : 0);
result = 37 * result + (attributes != null ? attributes.hashCode() : 0);
result = 37 * result + (childList != null ? childList.hashCode() : 0);
return result;
return 37 * result + (childList != null ? childList.hashCode() : 0);
}

@Override
Expand All @@ -548,10 +547,10 @@ public String toUnescapedString() {
}

public static boolean isNotEmpty(String str) {
return ((str != null) && (str.length() > 0));
return (str != null) && (str.length() > 0);
}

public static boolean isEmpty(String str) {
return ((str == null) || (str.trim().length() == 0));
return (str == null) || (str.trim().length() == 0);
}
}
6 changes: 3 additions & 3 deletions src/main/java/org/codehaus/plexus/util/xml/Xpp3DomUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void writeToSerializer(String namespace, XmlSerializer serializer, Xpp3Do
// document - not the desired behaviour!
SerializerXMLWriter xmlWriter = new SerializerXMLWriter(namespace, serializer);
Xpp3DomWriter.write(xmlWriter, dom);
if (xmlWriter.getExceptions().size() > 0) {
if (!xmlWriter.getExceptions().isEmpty()) {
throw (IOException) xmlWriter.getExceptions().get(0);
}
}
Expand Down Expand Up @@ -241,7 +241,7 @@ public static Xpp3Dom mergeXpp3Dom(Xpp3Dom dominant, Xpp3Dom recessive) {
*/
@Deprecated
public static boolean isNotEmpty(String str) {
return (str != null && str.length() > 0);
return str != null && str.length() > 0;
}

/**
Expand All @@ -251,6 +251,6 @@ public static boolean isNotEmpty(String str) {
*/
@Deprecated
public static boolean isEmpty(String str) {
return (str == null || str.length() == 0);
return str == null || str.length() == 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ private String newString(char[] cbuf, int off, int len) {
* diminishing hash quality for long strings but for XML parsing it should be good enough ...
*/
private static int fastHash(char ch[], int off, int len) {
if (len == 0) return 0;
if (len == 0) {
return 0;
}
// assert len >0
int hash = ch[off]; // hash at beginning
// try {
Expand All @@ -83,11 +85,15 @@ private static int fastHash(char ch[], int off, int len) {
// aie.printStackTrace(); //should never happen ...
// throw new RuntimeException("this is violation of pre-condition");
// }
if (len > 16) hash = (hash << 7) + ch[off + (len / 4)]; // 1/4 from beginning
if (len > 8) hash = (hash << 7) + ch[off + (len / 2)]; // 1/2 of string size ...
// notice that hash is at most done 3 times <<7 so shifted by 21 bits 8 bit value
// so max result == 29 bits so it is quite just below 31 bits for long (2^32) ...
// assert hash >= 0;
if (len > 16) {
hash = (hash << 7) + ch[off + (len / 4)]; // 1/4 from beginning
}
if (len > 8) {
hash = (hash << 7) + ch[off + (len / 2)]; // 1/2 of string size ...
// notice that hash is at most done 3 times <<7 so shifted by 21 bits 8 bit value
// so max result == 29 bits so it is quite just below 31 bits for long (2^32) ...
// assert hash >= 0;
}
return hash;
}

Expand Down
Loading
Loading