55import org .jetbrains .annotations .NotNull ;
66import org .jetbrains .annotations .Nullable ;
77
8+ import java .util .Map ;
89import java .util .Optional ;
910import java .util .UUID ;
1011import java .util .function .Function ;
12+ import java .util .regex .Matcher ;
13+ import java .util .regex .Pattern ;
1114
1215public class ValueDisplay extends NumberDisplay <UUID , Double > {
16+ private static final Pattern VALUE_PLACEHOLDER_PATTERN = Pattern .compile ("\\ {value(?:_(.*))?}" );
17+
18+ public final String defaultLine ;
1319 public final String displayNullName ;
1420 public final String displayNullUuid ;
1521 private final Function <UUID , String > nameFunction ;
1622
1723 public ValueDisplay (Function <UUID , String > nameFunction , Settings settings ) {
18- super (settings .defaultLine (), settings . displayNullValue ());
24+ super (settings .displayNullValue ());
1925 this .nameFunction = nameFunction ;
26+ this .defaultLine = settings .defaultLine ();
2027 this .displayNullName = settings .displayNullName ();
2128 this .displayNullUuid = settings .displayNullUuid ();
2229 }
@@ -29,6 +36,22 @@ public ValueDisplay(Function<UUID, String> nameFunction, Settings settings) {
2936 return Optional .ofNullable (uuid ).map (nameFunction ).orElse (displayNullName );
3037 }
3138
39+ public String getDisplayLine (int index /* 1-based */ , @ Nullable Map .Entry <UUID , Double > entry ) {
40+ String line = this .defaultLine
41+ .replace ("{index}" , String .valueOf (index ))
42+ .replace ("{uuid}" , getDisplayKey (entry == null ? null : entry .getKey ()))
43+ .replace ("{name}" , getDisplayName (entry == null ? null : entry .getKey ()));
44+
45+ Double value = entry == null ? null : entry .getValue ();
46+ Matcher matcher = VALUE_PLACEHOLDER_PATTERN .matcher (line );
47+ while (matcher .find ()) {
48+ String formatType = matcher .group (1 );
49+ line = line .replace (matcher .group (), getDisplayValue (value , formatType ));
50+ }
51+
52+ return line ;
53+ }
54+
3255 public String getDisplayLine (int index /* 1-based */ , NumberTopHolder holder ) {
3356 return getDisplayLine (index , holder .getSnapshotAgent ().getSnapshotByIndex (index - 1 ).orElse (null ));
3457 }
0 commit comments