Author: kiwiwings
Date: Tue Feb 25 21:27:07 2020
New Revision: 1874530
URL: http://svn.apache.org/viewvc?rev=1874530&view=rev
Log:
Sonar fixes
Modified:
poi/trunk/src/examples/src/org/apache/poi/ss/examples/html/excelStyle.css
poi/trunk/src/java/org/apache/poi/hpsf/ClassIDPredefined.java
poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java
poi/trunk/src/java/org/apache/poi/util/IntList.java
poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java
Modified:
poi/trunk/src/examples/src/org/apache/poi/ss/examples/html/excelStyle.css
URL:
http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/ss/examples/html/excelStyle.css?rev=1874530&r1=1874529&r2=1874530&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/ss/examples/html/excelStyle.css
(original)
+++ poi/trunk/src/examples/src/org/apache/poi/ss/examples/html/excelStyle.css
Tue Feb 25 21:27:07 2020
@@ -32,7 +32,6 @@
word-spacing: 0;
white-space: pre-wrap;
unicode-bidi: normal;
- vertical-align: 0;
background-image: none;
text-shadow: none;
list-style-image: none;
Modified: poi/trunk/src/java/org/apache/poi/hpsf/ClassIDPredefined.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hpsf/ClassIDPredefined.java?rev=1874530&r1=1874529&r2=1874530&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hpsf/ClassIDPredefined.java (original)
+++ poi/trunk/src/java/org/apache/poi/hpsf/ClassIDPredefined.java Tue Feb 25
21:27:07 2020
@@ -147,6 +147,7 @@ public enum ClassIDPredefined {
return (classID == null) ? null : LOOKUP.get(classID.toString());
}
+ @SuppressWarnings("java:S1201")
public boolean equals(ClassID classID) {
return getClassID().equals(classID);
}
Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java?rev=1874530&r1=1874529&r2=1874530&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java
(original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java Tue Feb
25 21:27:07 2020
@@ -119,12 +119,7 @@ public final class HSSFCellStyle impleme
// we keep the cached data in ThreadLocal members in order to
// avoid multi-threading issues when different workbooks are accessed in
// multiple threads at the same time
- private static final ThreadLocal<Short> lastDateFormat = new
ThreadLocal<Short>() {
- @Override
- protected Short initialValue() {
- return Short.MIN_VALUE;
- }
- };
+ private static final ThreadLocal<Short> lastDateFormat =
ThreadLocal.withInitial(() -> Short.MIN_VALUE);
private static final ThreadLocal<List<FormatRecord>> lastFormats = new
ThreadLocal<>();
private static final ThreadLocal<String> getDataFormatStringCache = new
ThreadLocal<>();
Modified: poi/trunk/src/java/org/apache/poi/util/IntList.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/util/IntList.java?rev=1874530&r1=1874529&r2=1874530&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/util/IntList.java (original)
+++ poi/trunk/src/java/org/apache/poi/util/IntList.java Tue Feb 25 21:27:07 2020
@@ -284,8 +284,8 @@ public class IntList
if (o == this) {
return true;
}
-
- if (o.getClass()!=this.getClass()) {
+
+ if (!(o instanceof IntList)) {
return false;
}
@@ -294,13 +294,13 @@ public class IntList
if (other._limit != _limit) {
return false;
}
-
+
for (int i=0; i< _limit; i++) {
if (other._array[i] != _array[i]) {
return false;
}
}
-
+
return true;
}
Modified:
poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java?rev=1874530&r1=1874529&r2=1874530&view=diff
==============================================================================
---
poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java
(original)
+++
poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java
Tue Feb 25 21:27:07 2020
@@ -26,6 +26,8 @@ import java.util.Locale;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
@@ -675,41 +677,35 @@ public final class PackagePropertiesPart
}
Matcher m = TIME_ZONE_PAT.matcher(dateStr);
+ Date d = null;
if (m.find()) {
- String dateTzStr = dateStr.substring(0, m.start())+
- m.group(1)+m.group(2);
- for (String fStr : TZ_DATE_FORMATS) {
- SimpleDateFormat df = new SimpleDateFormat(fStr, Locale.ROOT);
- df.setTimeZone(LocaleUtil.TIMEZONE_UTC);
- Date d = df.parse(dateTzStr, new ParsePosition(0));
- if (d != null) {
- return Optional.of(d);
- }
- }
+ String dateTzStr = dateStr.substring(0,
m.start())+m.group(1)+m.group(2);
+ d = parseDateFormat(TZ_DATE_FORMATS, dateTzStr);
+ }
+ if (d == null) {
+ String dateTzStr = dateStr.endsWith("Z") ? dateStr : (dateStr +
"Z");
+ d = parseDateFormat(DATE_FORMATS, dateTzStr);
}
- String dateTzStr = dateStr.endsWith("Z") ? dateStr : (dateStr + "Z");
- for (String fStr : DATE_FORMATS) {
+ if (d != null) {
+ return Optional.of(d);
+ }
+
+ //if you're here, no pattern matched, throw exception
+ String allFormats = Stream.of(TZ_DATE_FORMATS, DATE_FORMATS)
+ .flatMap(Stream::of).collect(Collectors.joining(", "));
+ throw new InvalidFormatException("Date " + dateStr + " not well
formatted, expected format in: "+ allFormats);
+ }
+
+ private static Date parseDateFormat(String[] formats, String dateTzStr) {
+ for (String fStr : formats) {
SimpleDateFormat df = new SimpleDateFormat(fStr, Locale.ROOT);
df.setTimeZone(LocaleUtil.TIMEZONE_UTC);
Date d = df.parse(dateTzStr, new ParsePosition(0));
if (d != null) {
- return Optional.of(d);
+ return d;
}
}
- //if you're here, no pattern matched, throw exception
- StringBuilder sb = new StringBuilder();
- int i = 0;
- for (String fStr : TZ_DATE_FORMATS) {
- if (i++ > 0) {
- sb.append(", ");
- }
- sb.append(fStr);
- }
- for (String fStr : DATE_FORMATS) {
- sb.append(", ").append(fStr);
- }
- throw new InvalidFormatException("Date " + dateStr + " not well
formatted, "
- + "expected format in: "+ sb);
+ return null;
}
/**
@@ -720,13 +716,14 @@ public final class PackagePropertiesPart
* @return The formated date or null.
* @see java.text.SimpleDateFormat
*/
- private String getDateValue(Optional<Date> d) {
- if (d == null || !d.isPresent()) {
- return "";
- }
+ private static String getDateValue(Optional<Date> d) {
+ return d.map(PackagePropertiesPart::getDateValue).orElse("");
+ }
+
+ private static String getDateValue(Date d) {
SimpleDateFormat df = new SimpleDateFormat(DEFAULT_DATEFORMAT,
Locale.ROOT);
df.setTimeZone(LocaleUtil.TIMEZONE_UTC);
- return df.format(d.get());
+ return df.format(d);
}
@Override
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]