DAlarmer java class :
uses classes :
Cloudian :
RegexUtil
:rain: :shine:
Code:
package chobit;
import java.util.ArrayList;
/*creates algorithms with alg parts that can become dormant
* can wake a dormant algorithm
* should use notify if you add more cloudians to a wake one of many said algorithm
* */
public class DAlarmer extends AbsCmdReq implements Neuronable {
private RegexUtil regexUtil = new RegexUtil();
private String jikan = "";
private Cloudian cloudian = new Cloudian();
private String representation = "";
private Boolean summon = false;
private String ear = "";
@Override
public void output(Neuron noiron) {
if (summon) {
// AbsAlgPart itte = new APCldAlarm(cloudian, jikan);
AbsAlgPart itte = new APCldAlarm(cloudian, jikan);
ArrayList<AbsAlgPart> algParts1 = new ArrayList<>();
algParts1.add(itte);
Algorithm algorithm = new Algorithm("alm", representation, algParts1);
this.cloudian.setAlgorithm(algorithm); // ***
noiron.algParts.add(algorithm);
reset();
return;
}
if (this.cloudian.updateStat(ear, "")) {
noiron.algParts.add(this.cloudian.getAlgorithm());
}
}
private void reset() {
representation = "";
summon = false;
}
@Override
public void input(String ear, String skin, String eye) {
this.ear = ear;
jikan = regexUtil.regexChecker("\\d+:\\d+", ear);
if (eye.contains("wake me at") && !jikan.isEmpty()) {
summon = true;
representation = ear;
}
}
@Override
public Boolean auto() {
// this skill can be triggered by time
return true;
}
}
uses classes :
Cloudian :
Code:
/*a trigger for reviving a dormant algorithm
* there should be a cloudian per APCld (alg part cloudian user)
* */
public class Cloudian {
private Boolean active = false;
private Algorithm algorithm = null;
private String timeTrig = ""; // time trigger
private String earTrig = "zhakhrixxer";
private String eyeTrig = "zhakhrixxer";
private int countDown = 0;
private Boolean dead = false;
public Boolean getDead() {
return dead;
}
private Boolean fin = false;
public Boolean getFin() {
return fin;
}
private PlayGround playGround = new PlayGround();
public Boolean updateStat(String ear, String eye) {
Boolean result = false;
if (ear.contains(earTrig) || eye.contains(eyeTrig)) {
fin = true;
result = true;
}
if (playGround.getCurrentTimeStamp().equals(this.timeTrig)) {
result = true;
}
result = result && !active;
if (result) {
active = true;
}
return result;
}
public int getCountDown() {
return countDown;
}
public void setCountDown(int countDown) {
this.countDown = countDown;
}
public void reset() {
active = false;
algorithm = null;
timeTrig = ""; // time trigger
earTrig = "zhakhrixxer";
eyeTrig = "zhakhrixxer";
countDown = 0;
dead = false;
fin = false;
}
public void setMe(int count, String ear, String eye, String setAlmTo) {
this.countDown = count;
this.earTrig = ear;
this.eyeTrig = eye;
this.timeTrig = setAlmTo;
}
public void sleep(int dormantFor) {
if (this.countDown > 0) {
this.countDown--;
} else {
this.dead = true;
}
// this.timeTrig = playGround.getFutureInXMin(dormantFor);
this.timeTrig = playGround.getFutureFromXInYMin(dormantFor, this.timeTrig);
}
public Boolean getActive() {
return active;
}
public void setActive(Boolean active) {
this.active = active;
}
public Algorithm getAlgorithm() {
return algorithm;
}
public void setAlgorithm(Algorithm algorithm) {
this.algorithm = algorithm;
}
public String getTimeTrig() {
return timeTrig;
}
public void setTimeTrig(String timeTrig) {
this.timeTrig = timeTrig;
}
public String getEarTrig() {
return earTrig;
}
public void setEarTrig(String earTrig) {
this.earTrig = earTrig;
}
public String getEyeTrig() {
return eyeTrig;
}
public void setEyeTrig(String eyeTrig) {
this.eyeTrig = eyeTrig;
}
}
RegexUtil
Code:
import java.util.regex.Matcher;
import java.util.regex.Pattern;
// returns expression of type theRegex from the string str2Check
public class RegexUtil {
public String regexChecker(String theRegex, String str2Check) {
Pattern checkRegex = Pattern.compile(theRegex);
Matcher regexMatcher = checkRegex.matcher(str2Check);
while (regexMatcher.find()) {
if (regexMatcher.group().length() != 0) {
return regexMatcher.group().trim();
}
}
return "";
}
}
:rain: :shine: