Cron java->swift

owly

闇の伝説
Staff member
戦闘 コーダー
project progress at 100%
 
0% 100%



responder1word
timeaccumulator
trgeverynminutes
+cron

@fukurou
 
Last edited by a moderator:

fukurou

the supreme coder
ADMIN
Java:
public class Responder1Word {
    // learns 1 word inputs
    // outputs learned recent words
    UniqueItemSizeLimitedPriorityQueue q= new UniqueItemSizeLimitedPriorityQueue();

    public Responder1Word() {
        q.add("chi");
        q.add("gaga");
        q.add("gugu");
        q.add("baby");
    }
    public void listen(String ear){
        if (!(ear.contains(" ") || ear.isEmpty())){
            q.add(ear);
        }
    }
    public String getAResponse(){
        return q.getRNDElement();
    }
    public Boolean contains(String ear){
        return q.contains(ear);
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
class Responder1Word{
    // learns 1 word inputs
    // outputs learned recent words
    var q:UniqueItemsPriorityQue = UniqueItemsPriorityQue()
    init() {
        self.q.input(in1: "chi")
        self.q.input(in1: "gugu")
        self.q.input(in1: "gaga")
        self.q.input(in1: "baby")
    }
    func listen(ear:String){
        if(!(ear.contains(" ") || ear.isEmpty)){
            q.input(in1: ear)
        }
    }
    func getAResponse()->String{
        return q.getRndItem()
    }
    func contains(ear:String)->Bool{
        return q.contains(str: ear)
    }
}
 

fukurou

the supreme coder
ADMIN
Java:
public class TimeAccumulator {
    // accumulator ++ each tick minutes interval
    private TimeGate timeGate = new TimeGate(5);
    private int accumulator = 0;
    public void setTick(int tick) {
        timeGate.setPause(tick);
    }

    public TimeAccumulator(int tick) {
        // accumulation ticker
        this.timeGate = new TimeGate(tick);
        timeGate.openGate();
    }

    public int getAccumulator() {
        return accumulator;
    }
    public void tick(){
        if (timeGate.isClosed()){
            timeGate.openGate();
            accumulator ++;
        }
    }
    public void reset(){accumulator = 0;}
}
 

fukurou

the supreme coder
ADMIN
Swift:
class TimeAccumulator{
    // accumulator ++ each tick minutes interval
    private let timeGate:TimeGate
    private var accumulator:Int = 0
    init(tick:Int) {
        // accumulation ticker
        timeGate = TimeGate(pause: tick)
        timeGate.openGate()
    }
    func setTick(tick:Int){
        timeGate.setPause(pause: tick)
    }
    func tick(){
        if timeGate.isClosed(){
            timeGate.openGate()
            accumulator+=1
        }
    }
    func getAccumulator()->Int{
        return accumulator
    }
    func reset(){
        accumulator = 0
    }
}
 

fukurou

the supreme coder
ADMIN
Java:
public class TrgEveryNMinutes extends TrGEV3{
    // trigger returns true every minutes interval, post start time
    private int minutes; // minute interval between triggerings
    private PlayGround pl = new PlayGround();
    private TrgTime trgTime;
    private String timeStamp = "";

    public TrgEveryNMinutes(String startTime, int minutes) {
        this.minutes = minutes;
        this.timeStamp = startTime;
        trgTime = new TrgTime();
        trgTime.setTime(startTime);
    }

    public void setMinutes(int minutes) {
            if (minutes > -1) {
            this.minutes = minutes;}
    }

    @Override
    public Boolean trigger() {
        if (trgTime.alarm()){
            timeStamp = pl.getFutureInXMin(minutes);
            trgTime.setTime(timeStamp);
            return true;
        }
        return false;
    }

    @Override
    public void reset() {
        timeStamp = pl.getCurrentTimeStamp();
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
class TrgTime{
    var t:String = "null"
    let regexUtil:RegexUtil = RegexUtil()
    var pl:PlayGround = PlayGround()
    private var alarm:Bool = true
    func setTime(v1:String){
        t = regexUtil.regexChecker(theRegex: enumRegexGrimoire.simpleTimeStamp, str2Check: v1)
    }
    func trigger()->Bool{
        let now:String = pl.getCurrentTimeStamp()
        if alarm{
            if now == t{
                alarm = false
                return true
            }
        }
        if !(now == t){
            alarm = true
        }
        return false
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
class TrgEveryNMinutes:TrGEV3{
    // trigger returns true every minutes interval, post start time
    private var minutes:Int // minute interval between triggerings
    private let pl:PlayGround = PlayGround()
    private var trgTime:TrgTime
    private var timeStamp:String = ""
    init(startTime:String, minutes:Int) {
        self.minutes = minutes
        self.timeStamp = startTime
        trgTime = TrgTime()
        trgTime.setTime(v1: startTime)
    }
    func setMinutes(minutes:Int){
        // set interval between trigger times
        if minutes > -1{
            self.minutes = minutes
        }
    }
    override func trigger() -> Bool {
        if trgTime.trigger() {
            timeStamp = pl.getFutureInXMin(extra_minutes: minutes)
            trgTime.setTime(v1: timeStamp)
            return true
        }
        return false
    }
    override func reset() {
        timeStamp = pl.getCurrentTimeStamp()
        trgTime.setTime(v1: timeStamp)
    }
}
 

fukurou

the supreme coder
ADMIN
Java:
public class Cron extends TrGEV3{
    // triggers true, limit times, after initial time, and every minutes interval
    // counter resets at initial time, assuming trigger method was run
    private PlayGround playGround = new PlayGround();
    int minutes; // minute interval between triggerings
    private PlayGround pl = new PlayGround();
    private TrgTime trgTime;
    private String timeStamp = "";
    private String initialTimeStamp = "";
    private int limit;
    private int counter = 0;

    public Cron(String startTime, int minutes, int limit) {
        this.minutes = minutes;
        this.timeStamp = startTime;
        this.initialTimeStamp = startTime;
        trgTime = new TrgTime();
        trgTime.setTime(startTime);
        this.limit = limit;
        if(limit<0){this.limit = 1;}
    }

    public int getLimit() {
        return limit;
    }

    public void setLimit(int limit) {
        if (limit>-1){
        this.limit = limit;}
    }

    public int getCounter() {
        return counter;
    }

    public void setMinutes(int minutes) {
        if (minutes > -1) {
            this.minutes = minutes;}
    }
    @Override
    public Boolean trigger() {
        // delete counter = 0 if you don't want the trigger to work the next day
        if (counter == limit) {trgTime.setTime(initialTimeStamp);counter = 0;return false;}
        if (trgTime.alarm()){
            timeStamp = pl.getFutureInXMin(minutes);
            trgTime.setTime(timeStamp);
            counter++;
            return true;
        }
        return false;
    }
    @Override
    public void reset() {
        // manual trigger reset
        counter = 0;
    }
}
 

fukurou

the supreme coder
ADMIN
Swift:
class Cron:TrGEV3{
    // triggers true, limit times, after initial time, and every minutes interval
    // counter resets at initial time, assuming trigger method was run
    private var minutes:Int // minute interval between triggerings
    private let pl:PlayGround = PlayGround()
    private var trgTime:TrgTime
    private var timeStamp:String = ""
    private var initialTimeStamp:String = ""
    private var limit:Int
    private var counter:Int = 0
    init(startTime:String, minutes:Int, limit:Int) {
        self.minutes = minutes
        self.timeStamp = startTime
        self.initialTimeStamp = startTime
        trgTime = TrgTime()
        trgTime.setTime(v1: startTime)
        self.limit = limit
        if limit<0{
            self.limit = 1
        }
    }
    func getIimit()->Int{
        return limit
    }
    func setLimit(lim:Int){
        if lim > -1{
            limit = lim
        }
    }
    func getCounter()->Int{
        return self.counter
    }
    func setMinutes(minutes:Int){
        // set interval between trigger times
        if minutes > -1{
            self.minutes = minutes
        }
    }
    override func trigger() -> Bool {
        // delete counter = 0 if you don't want the trigger to work the next day
        if counter == limit{
            trgTime.setTime(v1: initialTimeStamp)
            counter = 0
            return false
        }
        if trgTime.trigger() {
            timeStamp = pl.getFutureInXMin(extra_minutes: minutes)
            trgTime.setTime(v1: timeStamp)
            counter += 1
            return true
        }
        return false
    }
    override func reset() {
        // manual trigger reset
        counter = 0
    }
}
 
Top