Skip to content

Commit

Permalink
Merge branch 'master' into fb_jpms
Browse files Browse the repository at this point in the history
  • Loading branch information
struberg authored Dec 5, 2024
2 parents f20639a + d2f8cac commit c64d702
Show file tree
Hide file tree
Showing 12 changed files with 502 additions and 518 deletions.
12 changes: 10 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.12.0</version>
<scope>provided</scope>
<version>${commons.text.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
Expand Down Expand Up @@ -174,6 +174,7 @@
<commons.jacoco.branchRatio>0.92</commons.jacoco.branchRatio>
<commons.jacoco.lineRatio>0.95</commons.jacoco.lineRatio>
<commons.jacoco.complexityRatio>0.90</commons.jacoco.complexityRatio>
<commons.text.version>1.12.0</commons.text.version>
</properties>

<build>
Expand Down Expand Up @@ -226,6 +227,13 @@
</manifest>
</archive>
<doclint>all</doclint>
<additionalDependencies>
<additionalDependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>${commons.text.version}</version>
</additionalDependency>
</additionalDependencies>
</configuration>
<executions>
<execution>
Expand Down
4 changes: 4 additions & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ The <action> type attribute can be add,update,fix,remove.
<action type="fix" dev="ggregory" due-to="Gary Gregory">Make Failable.run(FailableRunnable) null-safe.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">Make Failable.accept(*) null-safe.</action>
<action type="fix" dev="ggregory" due-to="maxxedev, Piotr P. Karwasz, Gary Gregory">Improve container detection by mimicking systemd #1323.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">Make LangCollectors.collect(...) null-safe.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">Make LangCollectors.collect(...) null-safe.</action>
<action type="fix" dev="ggregory" due-to="IBue, Gary Gregory">Fix names of UTF-16 surrogate character test fixture constants, see also #1326.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">Moditect plugin generates split package warnings.</action>
<!-- ADD -->
<action type="add" dev="ggregory" due-to="Gary Gregory">Add Strings and refactor StringUtils.</action>
<action issue="LANG-1747" type="add" dev="ggregory" due-to="Oliver B. Fischer, Gary Gregory">Add StopWatch.run([Failable]Runnable) and get([Failable]Supplier).</action>
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/apache/commons/lang3/LocaleUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ static class SyncAvoid {

/**
* The undetermined language {@value}.
* <p>
* If a language is empty, or not <em>well-formed</am> (for example "a" or "e2"), {@link Locale#toLanguageTag()} will return {@code "und"} (Undetermined).
* </p>
*
* @see Locale#toLanguageTag()
*/
private static final String UNDETERMINED = "und";

Expand Down
163 changes: 38 additions & 125 deletions src/main/java/org/apache/commons/lang3/builder/ToStringStyle.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,162 +150,62 @@ private static final class JsonToStringStyle extends ToStringStyle {
}

@Override
public void append(final StringBuffer buffer, final String fieldName,
final boolean[] array, final Boolean fullDetail) {

if (fieldName == null) {
throw new UnsupportedOperationException(
"Field names are mandatory when using JsonToStringStyle");
}
if (!isFullDetail(fullDetail)) {
throw new UnsupportedOperationException(
"FullDetail must be true when using JsonToStringStyle");
}

public void append(final StringBuffer buffer, final String fieldName, final boolean[] array, final Boolean fullDetail) {
checkAppendInput(fieldName, fullDetail);
super.append(buffer, fieldName, array, fullDetail);
}

@Override
public void append(final StringBuffer buffer, final String fieldName, final byte[] array,
final Boolean fullDetail) {

if (fieldName == null) {
throw new UnsupportedOperationException(
"Field names are mandatory when using JsonToStringStyle");
}
if (!isFullDetail(fullDetail)) {
throw new UnsupportedOperationException(
"FullDetail must be true when using JsonToStringStyle");
}

public void append(final StringBuffer buffer, final String fieldName, final byte[] array, final Boolean fullDetail) {
checkAppendInput(fieldName, fullDetail);
super.append(buffer, fieldName, array, fullDetail);
}

@Override
public void append(final StringBuffer buffer, final String fieldName, final char[] array,
final Boolean fullDetail) {

if (fieldName == null) {
throw new UnsupportedOperationException(
"Field names are mandatory when using JsonToStringStyle");
}
if (!isFullDetail(fullDetail)) {
throw new UnsupportedOperationException(
"FullDetail must be true when using JsonToStringStyle");
}

public void append(final StringBuffer buffer, final String fieldName, final char[] array, final Boolean fullDetail) {
checkAppendInput(fieldName, fullDetail);
super.append(buffer, fieldName, array, fullDetail);
}

@Override
public void append(final StringBuffer buffer, final String fieldName,
final double[] array, final Boolean fullDetail) {

if (fieldName == null) {
throw new UnsupportedOperationException(
"Field names are mandatory when using JsonToStringStyle");
}
if (!isFullDetail(fullDetail)) {
throw new UnsupportedOperationException(
"FullDetail must be true when using JsonToStringStyle");
}

public void append(final StringBuffer buffer, final String fieldName, final double[] array, final Boolean fullDetail) {
checkAppendInput(fieldName, fullDetail);
super.append(buffer, fieldName, array, fullDetail);
}

@Override
public void append(final StringBuffer buffer, final String fieldName,
final float[] array, final Boolean fullDetail) {

if (fieldName == null) {
throw new UnsupportedOperationException(
"Field names are mandatory when using JsonToStringStyle");
}
if (!isFullDetail(fullDetail)) {
throw new UnsupportedOperationException(
"FullDetail must be true when using JsonToStringStyle");
}

public void append(final StringBuffer buffer, final String fieldName, final float[] array, final Boolean fullDetail) {
checkAppendInput(fieldName, fullDetail);
super.append(buffer, fieldName, array, fullDetail);
}

@Override
public void append(final StringBuffer buffer, final String fieldName, final int[] array,
final Boolean fullDetail) {

if (fieldName == null) {
throw new UnsupportedOperationException(
"Field names are mandatory when using JsonToStringStyle");
}
if (!isFullDetail(fullDetail)) {
throw new UnsupportedOperationException(
"FullDetail must be true when using JsonToStringStyle");
}

public void append(final StringBuffer buffer, final String fieldName, final int[] array, final Boolean fullDetail) {
checkAppendInput(fieldName, fullDetail);
super.append(buffer, fieldName, array, fullDetail);
}

@Override
public void append(final StringBuffer buffer, final String fieldName, final long[] array,
final Boolean fullDetail) {

if (fieldName == null) {
throw new UnsupportedOperationException(
"Field names are mandatory when using JsonToStringStyle");
}
if (!isFullDetail(fullDetail)) {
throw new UnsupportedOperationException(
"FullDetail must be true when using JsonToStringStyle");
}

public void append(final StringBuffer buffer, final String fieldName, final long[] array, final Boolean fullDetail) {
checkAppendInput(fieldName, fullDetail);
super.append(buffer, fieldName, array, fullDetail);
}

@Override
public void append(final StringBuffer buffer, final String fieldName, final Object value,
final Boolean fullDetail) {

if (fieldName == null) {
throw new UnsupportedOperationException(
"Field names are mandatory when using JsonToStringStyle");
}
if (!isFullDetail(fullDetail)) {
throw new UnsupportedOperationException(
"FullDetail must be true when using JsonToStringStyle");
}

public void append(final StringBuffer buffer, final String fieldName, final Object value, final Boolean fullDetail) {
checkAppendInput(fieldName, fullDetail);
super.append(buffer, fieldName, value, fullDetail);
}

@Override
public void append(final StringBuffer buffer, final String fieldName,
final Object[] array, final Boolean fullDetail) {

if (fieldName == null) {
throw new UnsupportedOperationException(
"Field names are mandatory when using JsonToStringStyle");
}
if (!isFullDetail(fullDetail)) {
throw new UnsupportedOperationException(
"FullDetail must be true when using JsonToStringStyle");
}

public void append(final StringBuffer buffer, final String fieldName, final Object[] array, final Boolean fullDetail) {
checkAppendInput(fieldName, fullDetail);
super.append(buffer, fieldName, array, fullDetail);
}

@Override
public void append(final StringBuffer buffer, final String fieldName,
final short[] array, final Boolean fullDetail) {

if (fieldName == null) {
throw new UnsupportedOperationException(
"Field names are mandatory when using JsonToStringStyle");
}
if (!isFullDetail(fullDetail)) {
throw new UnsupportedOperationException(
"FullDetail must be true when using JsonToStringStyle");
}

public void append(final StringBuffer buffer, final String fieldName, final short[] array, final Boolean fullDetail) {
checkAppendInput(fieldName, fullDetail);
super.append(buffer, fieldName, array, fullDetail);
}

Expand All @@ -325,7 +225,6 @@ protected void appendDetail(final StringBuffer buffer, final String fieldName, f
buffer.append(getArrayEnd());
return;
}

buffer.append(coll);
}

Expand Down Expand Up @@ -390,10 +289,7 @@ protected void appendDetail(final StringBuffer buffer, final String fieldName, f
@Override
protected void appendFieldStart(final StringBuffer buffer, final String fieldName) {

if (fieldName == null) {
throw new UnsupportedOperationException(
"Field names are mandatory when using JsonToStringStyle");
}
checkFieldName(fieldName);

super.appendFieldStart(buffer, FIELD_NAME_QUOTE + StringEscapeUtils.escapeJson(fieldName)
+ FIELD_NAME_QUOTE);
Expand All @@ -409,6 +305,23 @@ private void appendValueAsString(final StringBuffer buffer, final String value)
buffer.append('"').append(StringEscapeUtils.escapeJson(value)).append('"');
}

private void checkAppendInput(final String fieldName, final Boolean fullDetail) {
checkFieldName(fieldName);
checkIsFullDetail(fullDetail);
}

private void checkFieldName(final String fieldName) {
if (fieldName == null) {
throw new UnsupportedOperationException("Field names are mandatory when using JsonToStringStyle");
}
}

private void checkIsFullDetail(final Boolean fullDetail) {
if (!isFullDetail(fullDetail)) {
throw new UnsupportedOperationException("FullDetail must be true when using JsonToStringStyle");
}
}

private boolean isJsonArray(final String valueAsString) {
return valueAsString.startsWith(getArrayStart())
&& valueAsString.endsWith(getArrayEnd());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,16 @@ public Supplier<A> supplier() {
* @param <R> the type of the result.
* @param <A> the intermediate accumulation type of the {@code Collector}.
* @param collector the {@code Collector} describing the reduction.
* @param array The array, assumed to be unmodified during use.
* @param array The array, assumed to be unmodified during use, a null array treated as an empty array.
* @return the result of the reduction
* @see Stream#collect(Collector)
* @see Arrays#stream(Object[])
* @see Collectors
* @since 3.16.0
*/
@SafeVarargs
public static <T, R, A> R collect(final Collector<? super T, A, R> collector, final T... array) {
return Arrays.stream(array).collect(collector);
return Streams.of(array).collect(collector);
}

/**
Expand Down
Loading

0 comments on commit c64d702

Please sign in to comment.