battle programmers alliance
Would you like to react to this message? Create an account in a few clicks or log in to continue.


battle programming a forum for elite programmers with extreme will power to sharpen theire skills
 
HomeSearchRegisterLog in
 

 the 1st skill made DSayer

Go down 
AuthorMessage
Moti Barski
super
super
Moti Barski

Posts : 464
Join date : 2011-08-02

the 1st skill made DSayer Empty
PostSubject: the 1st skill made DSayer   the 1st skill made DSayer EmptyThu Oct 24, 2019 2:12 am

very useful, for testing and other stuff

DSayer

Code:


import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

// very simple Dclass for creating a say something x times algorithm
public class DSayer extends AbsCmdReq implements Neuronable {
    private int times;
    private String param;

    public DSayer() {
        super();
        this.times = 1;
        this.param = "";
    }

    public static 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 "";
    }

    @Override
    public void input(String command) {
        int foo = 1;
        String myString = regexChecker("(\\d+)(?= times)", command);
        String toSay = regexChecker("(?<=say)(.*)(?=\\d)", command);
        if (myString != "") {
            foo = Integer.parseInt(myString);
        } else {
            toSay = regexChecker("(?<=say)(.*)", command);
        }
        this.param = toSay;
        this.times = foo;
    }

    @Override
    public void output(Neuron noiron) {
        // TODO Auto-generated method stub
        if (!param.isEmpty()) {
            AbsAlgPart itte = new APSay(this.times, this.param);
            String representation = "say " + param;
            if (this.times > 1) {
                representation += " " + this.times + " times";
            }
            ArrayList<AbsAlgPart> algParts1 = new ArrayList<>();
            algParts1.add(itte);
            Algorithm algorithm = new Algorithm("say", representation, algParts1);
            noiron.algParts.add(algorithm);
        }

    }
}

bwahaha

chii say hi results hi
chii say hello 2 times results : hello, hello other 2 cycles of running.
[chobit name or 2nd name] say (?) (digit) times

_________________
MB over and out emp it up
Back to top Go down
 
the 1st skill made DSayer
Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
battle programmers alliance :: battle programming alliance :: the LivinGrimoire-
Jump to: