-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Performance/placeholders #97
Changes from all commits
a25de02
e3cf2ba
df25d15
080d73d
737556c
80ec031
9781ac4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
package com.iridium.iridiumcore.utils; | ||
|
||
import java.util.function.Consumer; | ||
import java.util.function.Function; | ||
import java.util.function.Supplier; | ||
|
||
import lombok.Getter; | ||
|
@@ -11,8 +13,10 @@ | |
public class Placeholder { | ||
|
||
private final String key; | ||
private final String formattedKey; | ||
private String value; | ||
private Supplier<String> supplier; | ||
private Function<Integer, String> int_supplier; | ||
|
||
/** | ||
* The default constructor. | ||
|
@@ -21,7 +25,8 @@ public class Placeholder { | |
* @param value The actual value of the placeholder | ||
*/ | ||
public Placeholder(String key, String value) { | ||
this.key = "%" + key + "%"; | ||
this.key = key; | ||
this.formattedKey = "%" + key + "%"; | ||
this.value = value; | ||
} | ||
|
||
|
@@ -32,15 +37,34 @@ public Placeholder(String key, String value) { | |
* @param value The actual value of the placeholder | ||
*/ | ||
public Placeholder(String key, Supplier<String> supplier) { | ||
this.key = "%" + key + "%"; | ||
this.key = key; | ||
this.formattedKey = "%" + key + "%"; | ||
this.supplier = supplier; | ||
} | ||
|
||
public String getValue() | ||
{ | ||
/** | ||
* The default constructor. | ||
* | ||
* @param key The placeholder without curly brackets. | ||
* @param value The actual value of the placeholder | ||
*/ | ||
public Placeholder(String key, Function<Integer, String> supplier) { | ||
this.key = key; | ||
this.formattedKey = "%" + key + "%"; | ||
this.int_supplier = supplier; | ||
} | ||
|
||
public String getValue() { | ||
if(value==null && supplier!=null) value = supplier.get(); | ||
return value; | ||
return value; | ||
boiscljo marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
58
to
+59
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a case where both value and supplier can be null here now no? Is this an issue? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's an issue with normal placeholder it will just return null without throwing |
||
} | ||
|
||
public String getValue(int i) { | ||
if(this.int_supplier!=null) | ||
return this.int_supplier.apply(i); | ||
return getValue(); | ||
} | ||
|
||
/** | ||
* Replaces this placeholder in the provided line with the value of this | ||
* placeholder. | ||
|
@@ -52,8 +76,8 @@ public String getValue() | |
public String process(String line) { | ||
if (line == null || line.isEmpty()) | ||
return ""; | ||
if (line.contains(key)) | ||
return line.replace(key, getValue()); | ||
if (line.contains(formattedKey)) | ||
return line.replace(formattedKey, getValue()); | ||
else | ||
return line; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Semi breaking change, nothing should reference the key directly, but key is without percent signs, formattedKey is with signs