Skip to content

Commit

Permalink
Clarify more comments and eliminate some warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
labkey-adam committed Jan 28, 2024
1 parent 2e080b0 commit 7e24584
Showing 1 changed file with 28 additions and 31 deletions.
59 changes: 28 additions & 31 deletions api/src/org/labkey/api/util/StringExpressionFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -308,7 +309,7 @@ public Object clone()

public static class ConstantPart extends StringPart
{
private String _value;
private final String _value;
public ConstantPart(String value)
{
_value = value;
Expand Down Expand Up @@ -497,25 +498,25 @@ public static SubstitutionFormat createDateSubstitutionFormat(String format)

private static DateTimeFormatter createDateFormatter(String format)
{
switch (format)
{
case "BASIC_ISO_DATE": return DateTimeFormatter.BASIC_ISO_DATE;
case "ISO_DATE": return DateTimeFormatter.ISO_DATE;
case "ISO_DATE_TIME": return DateTimeFormatter.ISO_DATE_TIME;
case "ISO_INSTANT": return DateTimeFormatter.ISO_INSTANT;
case "ISO_LOCAL_DATE": return DateTimeFormatter.ISO_LOCAL_DATE;
case "ISO_LOCAL_DATE_TIME": return DateTimeFormatter.ISO_LOCAL_DATE_TIME;
case "ISO_LOCAL_TIME": return DateTimeFormatter.ISO_LOCAL_TIME;
case "ISO_OFFSET_DATE": return DateTimeFormatter.ISO_OFFSET_DATE;
case "ISO_OFFSET_DATE_TIME": return DateTimeFormatter.ISO_OFFSET_DATE_TIME;
case "ISO_OFFSET_TIME": return DateTimeFormatter.ISO_OFFSET_TIME;
case "ISO_ORDINAL_DATE": return DateTimeFormatter.ISO_ORDINAL_DATE;
case "ISO_TIME": return DateTimeFormatter.ISO_TIME;
case "ISO_WEEK_DATE": return DateTimeFormatter.ISO_WEEK_DATE;
case "ISO_ZONED_DATE_TIME": return DateTimeFormatter.ISO_ZONED_DATE_TIME;
case "RFC_1123_DATE_TIME": return DateTimeFormatter.RFC_1123_DATE_TIME;
default: return DateTimeFormatter.ofPattern(format);
}
return switch (format)
{
case "BASIC_ISO_DATE" -> DateTimeFormatter.BASIC_ISO_DATE;
case "ISO_DATE" -> DateTimeFormatter.ISO_DATE;
case "ISO_DATE_TIME" -> DateTimeFormatter.ISO_DATE_TIME;
case "ISO_INSTANT" -> DateTimeFormatter.ISO_INSTANT;
case "ISO_LOCAL_DATE" -> DateTimeFormatter.ISO_LOCAL_DATE;
case "ISO_LOCAL_DATE_TIME" -> DateTimeFormatter.ISO_LOCAL_DATE_TIME;
case "ISO_LOCAL_TIME" -> DateTimeFormatter.ISO_LOCAL_TIME;
case "ISO_OFFSET_DATE" -> DateTimeFormatter.ISO_OFFSET_DATE;
case "ISO_OFFSET_DATE_TIME" -> DateTimeFormatter.ISO_OFFSET_DATE_TIME;
case "ISO_OFFSET_TIME" -> DateTimeFormatter.ISO_OFFSET_TIME;
case "ISO_ORDINAL_DATE" -> DateTimeFormatter.ISO_ORDINAL_DATE;
case "ISO_TIME" -> DateTimeFormatter.ISO_TIME;
case "ISO_WEEK_DATE" -> DateTimeFormatter.ISO_WEEK_DATE;
case "ISO_ZONED_DATE_TIME" -> DateTimeFormatter.ISO_ZONED_DATE_TIME;
case "RFC_1123_DATE_TIME" -> DateTimeFormatter.RFC_1123_DATE_TIME;
default -> DateTimeFormatter.ofPattern(format);
};
}

private static class RenderContextPart extends SubstitutePart
Expand Down Expand Up @@ -662,7 +663,7 @@ public static abstract class AbstractStringExpression implements StringExpressio
// FieldParts know the field, so this is hard.
public enum NullValueBehavior
{
// Any null field results in a null eval (good for URLs)
// Any null or missing field results in a null eval of the whole expression (good for URLs)
NullResult(StringExpressionType.ReplaceMissing.NULL_RESULT)
{
@Override
Expand All @@ -672,8 +673,7 @@ public String handleNull(StringExpressionFactory.StringPart part) throws StopIte
}
},

// Null fields get replaced with blank. Any missing field results in null eval of the whole expression

// All null fields get replaced with blank. Any missing field results in a null eval of the whole expression.
ReplaceNullWithBlank(StringExpressionType.ReplaceMissing.BLANK_VALUE)
{
@Override
Expand All @@ -683,7 +683,7 @@ public String handleNull(StringExpressionFactory.StringPart part)
}
},

// Null and missing fields get replaced with blank
// All null and missing fields get replaced with blank
ReplaceNullAndMissingWithBlank(StringExpressionType.ReplaceMissing.BLANK_VALUE)
{
@Override
Expand All @@ -699,7 +699,7 @@ public String handleUndefined(StringPart part)
}
},

// Insert "null" into the string
// All null fields get replaces with "null". Any missing field results in a null eval of the whole expression.
OutputNull(StringExpressionType.ReplaceMissing.NULL_VALUE)
{
@Override
Expand All @@ -709,6 +709,7 @@ public String handleNull(StringExpressionFactory.StringPart part)
}
},

// All null and missing fields get skipped (substitution is left in place)
KeepSubstitution(StringExpressionType.ReplaceMissing.KEEP_SUBSTITUTION)
{
@Override
Expand Down Expand Up @@ -775,10 +776,7 @@ public String handleUndefined(StringExpressionFactory.StringPart part) throws St
AbstractStringExpression(String source, NullValueBehavior nullValueBehavior, boolean allowSideEffects)
{
_source = source;
if (nullValueBehavior != null)
_nullValueBehavior = nullValueBehavior;
else
_nullValueBehavior = NullValueBehavior.NullResult;
_nullValueBehavior = Objects.requireNonNullElse(nullValueBehavior, NullValueBehavior.NullResult);
_allowSideEffects = allowSideEffects;
//MemTracker.getInstance().put(this);
}
Expand All @@ -798,9 +796,8 @@ public synchronized ArrayList<StringPart> getDeepParsedExpression()
ArrayList<StringPart> parts = new ArrayList<>();
for (StringPart part : getParsedExpression())
{
if (part instanceof NameGenerator.CounterExpressionPart)
if (part instanceof NameGenerator.CounterExpressionPart counterPart)
{
NameGenerator.CounterExpressionPart counterPart = (NameGenerator.CounterExpressionPart) part;
parts.addAll(counterPart.getParsedNameExpression().getParsedExpression());
}
else
Expand Down

0 comments on commit 7e24584

Please sign in to comment.