mirror of
https://github.com/apache/commons-collections.git
synced 2025-02-27 13:36:33 +00:00
Must override toString() for Java 17
This commit is contained in:
parent
21c8c53418
commit
f59447dd4f
@ -19,6 +19,7 @@ package org.apache.commons.collections4.properties;
|
||||
import java.util.AbstractMap.SimpleEntry;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
@ -145,4 +146,28 @@ public class OrderedProperties extends Properties {
|
||||
}
|
||||
return remove;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized String toString() {
|
||||
// Must override for Java 17 to maintain order since the implementation is based on a map
|
||||
final int max = size() - 1;
|
||||
if (max == -1) {
|
||||
return "{}";
|
||||
}
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
final Iterator<Map.Entry<Object, Object>> it = entrySet().iterator();
|
||||
sb.append('{');
|
||||
for (int i = 0;; i++) {
|
||||
final Map.Entry<Object, Object> e = it.next();
|
||||
final Object key = e.getKey();
|
||||
final Object value = e.getValue();
|
||||
sb.append(key == this ? "(this Map)" : key.toString());
|
||||
sb.append('=');
|
||||
sb.append(value == this ? "(this Map)" : value.toString());
|
||||
if (i == max) {
|
||||
return sb.append('}').toString();
|
||||
}
|
||||
sb.append(", ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -288,7 +288,6 @@ public class OrderedPropertiesTest {
|
||||
assertFalse(Collections.list(props.propertyNames()).contains(k));
|
||||
}
|
||||
|
||||
@Disabled("Fails on GHA?")
|
||||
@Test
|
||||
public void testToString() {
|
||||
final OrderedProperties orderedProperties = new OrderedProperties();
|
||||
|
Loading…
x
Reference in New Issue
Block a user