-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ce7d119
commit 354c726
Showing
4 changed files
with
77 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package pisi.unitedmeows.yystal.utils; | ||
|
||
import pisi.unitedmeows.yystal.clazz.function; | ||
import pisi.unitedmeows.yystal.parallel.IFunction; | ||
|
||
import java.util.HashMap; | ||
import java.util.function.Consumer; | ||
import java.util.function.Predicate; | ||
|
||
public class Capsule { | ||
|
||
protected final HashMap<String, Object> parameters; | ||
|
||
public static Capsule of(Pair<String, ?>... params) { | ||
final Capsule capsule = new Capsule(params.length); | ||
for (Pair<String, ?> param : params) { | ||
capsule.parameters.put(param.item1(), param.item2()); | ||
} | ||
return capsule; | ||
} | ||
|
||
protected Capsule(int paramCount) { | ||
parameters = new HashMap<>(paramCount); | ||
} | ||
|
||
public <X> X get(String paramName) { | ||
return (X) parameters.getOrDefault(paramName, null); | ||
} | ||
|
||
public <X> X getOrDefault(String paramName, X defaultVal) { | ||
return (X) parameters.getOrDefault(paramName, defaultVal); | ||
} | ||
|
||
public boolean contains(String paramName) { | ||
return parameters.containsKey(paramName); | ||
} | ||
|
||
public boolean exists() { | ||
return !parameters.isEmpty(); | ||
} | ||
|
||
public <X> X ifExists(String paramName, Consumer<X> func) { | ||
X value = get(paramName); | ||
if (value != null) { | ||
func.accept(value); | ||
} | ||
return value; | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package test.yystal; | ||
|
||
import pisi.unitedmeows.yystal.utils.Capsule; | ||
import pisi.unitedmeows.yystal.utils.kThread; | ||
|
||
|
||
import static pisi.unitedmeows.yystal.parallel.Async.*; | ||
import static pisi.unitedmeows.yystal.YYStal.*; | ||
|
||
public enum YTestStart { | ||
gaming; /* :D */ | ||
|
||
public static void main(final String[] args) { | ||
|
||
Capsule capsule = Capsule.of(pair("hello", 5), pair("var2", ":DDD"), pair("token", 12)); | ||
|
||
System.out.println((String)capsule.get("hello")); | ||
capsule.ifExists("var2", o -> { | ||
System.out.println("var2 exists"); | ||
}); | ||
|
||
kThread.sleep(1099900); | ||
} | ||
|
||
|
||
} |