mirror of
https://github.com/lightbend/config.git
synced 2025-03-22 23:30:27 +08:00
Fix comparator in config render options
This commit is contained in:
parent
6800a114b6
commit
9e76518062
@ -4,6 +4,7 @@
|
|||||||
package com.typesafe.config;
|
package com.typesafe.config;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.math.BigInteger;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -69,7 +70,7 @@ public final class ConfigRenderOptions {
|
|||||||
if (value == comments)
|
if (value == comments)
|
||||||
return this;
|
return this;
|
||||||
else
|
else
|
||||||
return new ConfigRenderOptions(originComments, value, formatted, json, new DefaultComparator());
|
return new ConfigRenderOptions(originComments, value, formatted, json, comparator);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -102,7 +103,7 @@ public final class ConfigRenderOptions {
|
|||||||
if (value == originComments)
|
if (value == originComments)
|
||||||
return this;
|
return this;
|
||||||
else
|
else
|
||||||
return new ConfigRenderOptions(value, comments, formatted, json, new DefaultComparator());
|
return new ConfigRenderOptions(value, comments, formatted, json, comparator);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -127,7 +128,7 @@ public final class ConfigRenderOptions {
|
|||||||
if (value == formatted)
|
if (value == formatted)
|
||||||
return this;
|
return this;
|
||||||
else
|
else
|
||||||
return new ConfigRenderOptions(originComments, comments, value, json, new DefaultComparator());
|
return new ConfigRenderOptions(originComments, comments, value, json, comparator);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -155,7 +156,7 @@ public final class ConfigRenderOptions {
|
|||||||
if (value == json)
|
if (value == json)
|
||||||
return this;
|
return this;
|
||||||
else
|
else
|
||||||
return new ConfigRenderOptions(originComments, comments, formatted, value, new DefaultComparator());
|
return new ConfigRenderOptions(originComments, comments, formatted, value, comparator);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -204,8 +205,7 @@ public final class ConfigRenderOptions {
|
|||||||
sb.append("formatted,");
|
sb.append("formatted,");
|
||||||
if (json)
|
if (json)
|
||||||
sb.append("json,");
|
sb.append("json,");
|
||||||
if (comparator != null)
|
sb.append(comparator.getClass().getSimpleName());
|
||||||
sb.append(comparator.getClass().getSimpleName());
|
|
||||||
if (sb.charAt(sb.length() - 1) == ',')
|
if (sb.charAt(sb.length() - 1) == ',')
|
||||||
sb.setLength(sb.length() - 1);
|
sb.setLength(sb.length() - 1);
|
||||||
sb.append(")");
|
sb.append(")");
|
||||||
@ -243,7 +243,7 @@ public final class ConfigRenderOptions {
|
|||||||
boolean aDigits = isAllDigits(a);
|
boolean aDigits = isAllDigits(a);
|
||||||
boolean bDigits = isAllDigits(b);
|
boolean bDigits = isAllDigits(b);
|
||||||
if (aDigits && bDigits) {
|
if (aDigits && bDigits) {
|
||||||
return Integer.compare(Integer.parseInt(a), Integer.parseInt(b));
|
return new BigInteger(a).compareTo(new BigInteger(b));
|
||||||
} else if (aDigits) {
|
} else if (aDigits) {
|
||||||
return -1;
|
return -1;
|
||||||
} else if (bDigits) {
|
} else if (bDigits) {
|
||||||
|
@ -983,9 +983,9 @@ class ConfigValueTest extends TestUtils {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
def renderDefaultSorting(): Unit = {
|
def renderDefaultSorting(): Unit = {
|
||||||
val config = parseConfig("""0=a,1=b,2=c,3=d,10=e,20=f,30=g""")
|
val config = parseConfig("""0=a,1=b,2=c,3=d,10=e,20a=f,20=g,30=h""")
|
||||||
val rendered = config.root.render(ConfigRenderOptions.concise())
|
val rendered = config.root.render(ConfigRenderOptions.concise())
|
||||||
assertEquals("""{"0":"a","1":"b","2":"c","3":"d","10":"e","20":"f","30":"g"}""", rendered)
|
assertEquals("""{"0":"a","1":"b","2":"c","3":"d","10":"e","20":"g","30":"h","20a":"f"}""", rendered)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
Reference in New Issue
Block a user