mirror of https://github.com/apache/poi.git
Sonar fixes
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1874530 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1aed0bc40b
commit
3691704678
|
@ -32,7 +32,6 @@
|
||||||
word-spacing: 0;
|
word-spacing: 0;
|
||||||
white-space: pre-wrap;
|
white-space: pre-wrap;
|
||||||
unicode-bidi: normal;
|
unicode-bidi: normal;
|
||||||
vertical-align: 0;
|
|
||||||
background-image: none;
|
background-image: none;
|
||||||
text-shadow: none;
|
text-shadow: none;
|
||||||
list-style-image: none;
|
list-style-image: none;
|
||||||
|
|
|
@ -147,6 +147,7 @@ public enum ClassIDPredefined {
|
||||||
return (classID == null) ? null : LOOKUP.get(classID.toString());
|
return (classID == null) ? null : LOOKUP.get(classID.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("java:S1201")
|
||||||
public boolean equals(ClassID classID) {
|
public boolean equals(ClassID classID) {
|
||||||
return getClassID().equals(classID);
|
return getClassID().equals(classID);
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,12 +119,7 @@ public final class HSSFCellStyle implements CellStyle, Duplicatable {
|
||||||
// we keep the cached data in ThreadLocal members in order to
|
// we keep the cached data in ThreadLocal members in order to
|
||||||
// avoid multi-threading issues when different workbooks are accessed in
|
// avoid multi-threading issues when different workbooks are accessed in
|
||||||
// multiple threads at the same time
|
// multiple threads at the same time
|
||||||
private static final ThreadLocal<Short> lastDateFormat = new ThreadLocal<Short>() {
|
private static final ThreadLocal<Short> lastDateFormat = ThreadLocal.withInitial(() -> Short.MIN_VALUE);
|
||||||
@Override
|
|
||||||
protected Short initialValue() {
|
|
||||||
return Short.MIN_VALUE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
private static final ThreadLocal<List<FormatRecord>> lastFormats = new ThreadLocal<>();
|
private static final ThreadLocal<List<FormatRecord>> lastFormats = new ThreadLocal<>();
|
||||||
private static final ThreadLocal<String> getDataFormatStringCache = new ThreadLocal<>();
|
private static final ThreadLocal<String> getDataFormatStringCache = new ThreadLocal<>();
|
||||||
|
|
||||||
|
|
|
@ -284,8 +284,8 @@ public class IntList
|
||||||
if (o == this) {
|
if (o == this) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (o.getClass()!=this.getClass()) {
|
if (!(o instanceof IntList)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -294,13 +294,13 @@ public class IntList
|
||||||
if (other._limit != _limit) {
|
if (other._limit != _limit) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i=0; i< _limit; i++) {
|
for (int i=0; i< _limit; i++) {
|
||||||
if (other._array[i] != _array[i]) {
|
if (other._array[i] != _array[i]) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,8 @@ import java.util.Locale;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
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.InvalidFormatException;
|
||||||
import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
|
import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
|
||||||
|
@ -675,41 +677,35 @@ public final class PackagePropertiesPart extends PackagePart implements PackageP
|
||||||
}
|
}
|
||||||
|
|
||||||
Matcher m = TIME_ZONE_PAT.matcher(dateStr);
|
Matcher m = TIME_ZONE_PAT.matcher(dateStr);
|
||||||
|
Date d = null;
|
||||||
if (m.find()) {
|
if (m.find()) {
|
||||||
String dateTzStr = dateStr.substring(0, m.start())+
|
String dateTzStr = dateStr.substring(0, m.start())+m.group(1)+m.group(2);
|
||||||
m.group(1)+m.group(2);
|
d = parseDateFormat(TZ_DATE_FORMATS, dateTzStr);
|
||||||
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.endsWith("Z") ? dateStr : (dateStr + "Z");
|
if (d == null) {
|
||||||
for (String fStr : DATE_FORMATS) {
|
String dateTzStr = dateStr.endsWith("Z") ? dateStr : (dateStr + "Z");
|
||||||
|
d = parseDateFormat(DATE_FORMATS, dateTzStr);
|
||||||
|
}
|
||||||
|
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);
|
SimpleDateFormat df = new SimpleDateFormat(fStr, Locale.ROOT);
|
||||||
df.setTimeZone(LocaleUtil.TIMEZONE_UTC);
|
df.setTimeZone(LocaleUtil.TIMEZONE_UTC);
|
||||||
Date d = df.parse(dateTzStr, new ParsePosition(0));
|
Date d = df.parse(dateTzStr, new ParsePosition(0));
|
||||||
if (d != null) {
|
if (d != null) {
|
||||||
return Optional.of(d);
|
return d;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//if you're here, no pattern matched, throw exception
|
return null;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -720,13 +716,14 @@ public final class PackagePropertiesPart extends PackagePart implements PackageP
|
||||||
* @return The formated date or null.
|
* @return The formated date or null.
|
||||||
* @see java.text.SimpleDateFormat
|
* @see java.text.SimpleDateFormat
|
||||||
*/
|
*/
|
||||||
private String getDateValue(Optional<Date> d) {
|
private static String getDateValue(Optional<Date> d) {
|
||||||
if (d == null || !d.isPresent()) {
|
return d.map(PackagePropertiesPart::getDateValue).orElse("");
|
||||||
return "";
|
}
|
||||||
}
|
|
||||||
|
private static String getDateValue(Date d) {
|
||||||
SimpleDateFormat df = new SimpleDateFormat(DEFAULT_DATEFORMAT, Locale.ROOT);
|
SimpleDateFormat df = new SimpleDateFormat(DEFAULT_DATEFORMAT, Locale.ROOT);
|
||||||
df.setTimeZone(LocaleUtil.TIMEZONE_UTC);
|
df.setTimeZone(LocaleUtil.TIMEZONE_UTC);
|
||||||
return df.format(d.get());
|
return df.format(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue