summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/gen
diff options
context:
space:
mode:
authorbculkin2442 <bjculkin@mix.wvu.edu>2016-05-10 16:02:45 -0400
committerbculkin2442 <bjculkin@mix.wvu.edu>2016-05-10 16:02:45 -0400
commit61fd71f69e080790da722e0e03b71ecd7c2538a2 (patch)
treee5c1150b27b84d550f807e44ac82688216451f00 /BJC-Utils2/src/main/java/bjc/utils/gen
parent87ae1dfc8d8cb7b51d7bda4750ce841bbe691cfc (diff)
General update
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/gen')
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/gen/RandomGrammar.java12
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/gen/WeightedGrammar.java52
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/gen/WeightedRandom.java10
3 files changed, 37 insertions, 37 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/gen/RandomGrammar.java b/BJC-Utils2/src/main/java/bjc/utils/gen/RandomGrammar.java
index 963fb32..a764a08 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/gen/RandomGrammar.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/gen/RandomGrammar.java
@@ -1,7 +1,7 @@
package bjc.utils.gen;
import bjc.utils.funcdata.FunctionalMap;
-import bjc.utils.funcdata.IFunctionalList;
+import bjc.utils.funcdata.IList;
/**
* A weighted grammar where all the rules have a equal chance of occuring.
@@ -28,8 +28,8 @@ public class RandomGrammar<E> extends WeightedGrammar<E> {
* The cases to add for this rule.
*/
@SafeVarargs
- public final void addCases(E rule, IFunctionalList<E>... cases) {
- for (IFunctionalList<E> currentCase : cases) {
+ public final void addCases(E rule, IList<E>... cases) {
+ for (IList<E> currentCase : cases) {
super.addCase(rule, 1, currentCase);
}
}
@@ -43,10 +43,10 @@ public class RandomGrammar<E> extends WeightedGrammar<E> {
* The cases to add for this rule.
*/
@SafeVarargs
- public final void makeRule(E rule, IFunctionalList<E>... cases) {
+ public final void makeRule(E rule, IList<E>... cases) {
super.addRule(rule);
- for (IFunctionalList<E> currentCase : cases) {
+ for (IList<E> currentCase : cases) {
super.addCase(rule, 1, currentCase);
}
}
@@ -60,7 +60,7 @@ public class RandomGrammar<E> extends WeightedGrammar<E> {
* The cases to add for this rule.
*/
public void makeRule(E rule,
- IFunctionalList<IFunctionalList<E>> cases) {
+ IList<IList<E>> cases) {
if (cases == null) {
throw new NullPointerException("Cases must not be null");
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/gen/WeightedGrammar.java b/BJC-Utils2/src/main/java/bjc/utils/gen/WeightedGrammar.java
index 131e507..78db7d8 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/gen/WeightedGrammar.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/gen/WeightedGrammar.java
@@ -7,8 +7,8 @@ import bjc.utils.data.IPair;
import bjc.utils.data.Pair;
import bjc.utils.funcdata.FunctionalList;
import bjc.utils.funcdata.FunctionalMap;
-import bjc.utils.funcdata.IFunctionalList;
-import bjc.utils.funcdata.IFunctionalMap;
+import bjc.utils.funcdata.IList;
+import bjc.utils.funcdata.IMap;
/**
* A random grammar, where certain rules will come up more often than
@@ -28,7 +28,7 @@ public class WeightedGrammar<E> {
/**
* The rules currently in this grammar
*/
- protected IFunctionalMap<E, WeightedRandom<IFunctionalList<E>>> rules;
+ protected IMap<E, WeightedRandom<IList<E>>> rules;
/**
* The random number generator used for random numbers
@@ -38,7 +38,7 @@ public class WeightedGrammar<E> {
/**
* All of the subgrammars of this grammar
*/
- protected IFunctionalMap<E, WeightedGrammar<E>> subgrammars;
+ protected IMap<E, WeightedGrammar<E>> subgrammars;
/**
* Create a new weighted grammar.
@@ -77,7 +77,7 @@ public class WeightedGrammar<E> {
* The case being added.
*/
public void addCase(E ruleName, int probability,
- IFunctionalList<E> cse) {
+ IList<E> cse) {
if (ruleName == null) {
throw new NullPointerException("Rule name must be not null");
} else if (cse == null) {
@@ -146,7 +146,7 @@ public class WeightedGrammar<E> {
* @return Whether or not the rule was succesfully added.
*/
public boolean addRule(E name,
- WeightedRandom<IFunctionalList<E>> cases) {
+ WeightedRandom<IList<E>> cases) {
if (name == null) {
throw new NullPointerException("Name must not be null");
} else if (cases == null) {
@@ -222,15 +222,15 @@ public class WeightedGrammar<E> {
* The rule to test.
* @return A set of sentances generated by the specified rule.
*/
- public IFunctionalList<IFunctionalList<E>> generateDebugValues(
+ public IList<IList<E>> generateDebugValues(
E ruleName) {
if (ruleName == null) {
throw new NullPointerException("Rule name must not be null");
}
- IFunctionalList<IFunctionalList<E>> returnedList = new FunctionalList<>();
+ IList<IList<E>> returnedList = new FunctionalList<>();
- WeightedRandom<IFunctionalList<E>> ruleGenerator = rules
+ WeightedRandom<IList<E>> ruleGenerator = rules
.get(ruleName);
for (int i = 0; i < 10; i++) {
@@ -255,7 +255,7 @@ public class WeightedGrammar<E> {
* @return A randomly generated sentance from the specified initial
* rule.
*/
- public <T> IFunctionalList<T> generateGenericValues(E initRule,
+ public <T> IList<T> generateGenericValues(E initRule,
Function<E, T> tokenTransformer, T spacer) {
if (initRule == null) {
throw new NullPointerException(
@@ -266,7 +266,7 @@ public class WeightedGrammar<E> {
throw new NullPointerException("Spacer must not be null");
}
- IFunctionalList<T> returnedList = new FunctionalList<>();
+ IList<T> returnedList = new FunctionalList<>();
if (subgrammars.containsKey(initRule)) {
subgrammars.get(initRule).generateGenericValues(initRule,
@@ -309,7 +309,7 @@ public class WeightedGrammar<E> {
* @return A list of random grammar elements generated by the specified
* rule.
*/
- public IFunctionalList<E> generateListValues(E initRule, E spacer) {
+ public IList<E> generateListValues(E initRule, E spacer) {
return generateGenericValues(initRule, strang -> strang, spacer);
}
@@ -336,7 +336,7 @@ public class WeightedGrammar<E> {
*
* @return The set of all rule names in this grammar
*/
- public IFunctionalList<E> getRuleNames() {
+ public IList<E> getRuleNames() {
return rules.keyList();
}
@@ -389,16 +389,16 @@ public class WeightedGrammar<E> {
"Number of times to prefix must be positive.");
}
- WeightedRandom<IFunctionalList<E>> rule = rules.get(ruleName);
+ WeightedRandom<IList<E>> rule = rules.get(ruleName);
- IFunctionalList<IPair<Integer, IFunctionalList<E>>> newResults = new FunctionalList<>();
+ IList<IPair<Integer, IList<E>>> newResults = new FunctionalList<>();
rule.getValues().forEach((pair) -> {
- IFunctionalList<IFunctionalList<E>> newRule = new FunctionalList<>();
+ IList<IList<E>> newRule = new FunctionalList<>();
for (int i = 1; i <= numberOfTimes; i++) {
- IFunctionalList<E> newCase = pair.merge((left, right) -> {
- IFunctionalList<E> returnVal = new FunctionalList<>();
+ IList<E> newCase = pair.merge((left, right) -> {
+ IList<E> returnVal = new FunctionalList<>();
for (E val : right.toIterable()) {
returnVal.add(val);
@@ -449,13 +449,13 @@ public class WeightedGrammar<E> {
"Prefix token must not be null");
}
- WeightedRandom<IFunctionalList<E>> rule = rules.get(ruleName);
+ WeightedRandom<IList<E>> rule = rules.get(ruleName);
- IFunctionalList<IPair<Integer, IFunctionalList<E>>> newResults = new FunctionalList<>();
+ IList<IPair<Integer, IList<E>>> newResults = new FunctionalList<>();
rule.getValues().forEach((pair) -> {
- IFunctionalList<E> newCase = pair.merge((left, right) -> {
- IFunctionalList<E> returnVal = new FunctionalList<>();
+ IList<E> newCase = pair.merge((left, right) -> {
+ IList<E> returnVal = new FunctionalList<>();
for (E val : right.toIterable()) {
returnVal.add(val);
@@ -503,13 +503,13 @@ public class WeightedGrammar<E> {
"Prefix token must not be null");
}
- WeightedRandom<IFunctionalList<E>> rule = rules.get(ruleName);
+ WeightedRandom<IList<E>> rule = rules.get(ruleName);
- IFunctionalList<IPair<Integer, IFunctionalList<E>>> newResults = new FunctionalList<>();
+ IList<IPair<Integer, IList<E>>> newResults = new FunctionalList<>();
rule.getValues().forEach((par) -> {
- IFunctionalList<E> newCase = par.merge((left, right) -> {
- IFunctionalList<E> returnVal = new FunctionalList<>();
+ IList<E> newCase = par.merge((left, right) -> {
+ IList<E> returnVal = new FunctionalList<>();
for (E val : right.toIterable()) {
returnVal.add(val);
diff --git a/BJC-Utils2/src/main/java/bjc/utils/gen/WeightedRandom.java b/BJC-Utils2/src/main/java/bjc/utils/gen/WeightedRandom.java
index 43d9928..7c6af23 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/gen/WeightedRandom.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/gen/WeightedRandom.java
@@ -6,7 +6,7 @@ import bjc.utils.data.IHolder;
import bjc.utils.data.IPair;
import bjc.utils.data.Identity;
import bjc.utils.funcdata.FunctionalList;
-import bjc.utils.funcdata.IFunctionalList;
+import bjc.utils.funcdata.IList;
/**
* Represents a random number generator where certain results are weighted
@@ -21,12 +21,12 @@ public class WeightedRandom<E> {
/**
* The list of probabilities for each result
*/
- private IFunctionalList<Integer> probabilities;
+ private IList<Integer> probabilities;
/**
* The list of possible results to pick from
*/
- private IFunctionalList<E> results;
+ private IList<E> results;
/**
* The source for any needed random numbers
@@ -103,7 +103,7 @@ public class WeightedRandom<E> {
*
* @return A list of all the values that can be generated
*/
- public IFunctionalList<E> getResults() {
+ public IList<E> getResults() {
return results;
}
@@ -113,7 +113,7 @@ public class WeightedRandom<E> {
*
* @return A list of pairs of values and value probabilities
*/
- public IFunctionalList<IPair<Integer, E>> getValues() {
+ public IList<IPair<Integer, E>> getValues() {
return probabilities.pairWith(results);
}
} \ No newline at end of file