[skill package] active task

fukurou

the supreme coder
ADMIN
RegexUtil :


Java:
import java.awt.Point;
import java.util.ArrayList;
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 "";
    }

    public String numberRegex(String str2Check) {
        String theRegex = "[-+]?[0-9]{1,13}(\\.[0-9]*)?";
        ArrayList<String> list = new ArrayList<String>();
        Pattern checkRegex = Pattern.compile(theRegex);
        Matcher regexMatcher = checkRegex.matcher(str2Check);
        while (regexMatcher.find()) {
            if (regexMatcher.group().length() != 0) {
                return regexMatcher.group().trim();
            }
        }
        return "";
    }

    public String timeStampRegex(String str2Check) {
        String theRegex = "(([0-9]|[0-1][0-9]|[2][0-3]):([0-5][0-9])$)|(^([0-9]|[1][0-9]|[2][0-3])$)";
        ArrayList<String> list = new ArrayList<String>();
        Pattern checkRegex = Pattern.compile(theRegex);
        Matcher regexMatcher = checkRegex.matcher(str2Check);
        while (regexMatcher.find()) {
            if (regexMatcher.group().length() != 0) {
                return regexMatcher.group().trim();
            }
        }
        return "";
    }
    public String intRegex(String str2Check) {
        String theRegex = "[-+]?[0-9]{1,13}";
        ArrayList<String> list = new ArrayList<String>();
        Pattern checkRegex = Pattern.compile(theRegex);
        Matcher regexMatcher = checkRegex.matcher(str2Check);
        while (regexMatcher.find()) {
            if (regexMatcher.group().length() != 0) {
                return regexMatcher.group().trim();
            }
        }
        return "";
    }
    public Point pointRegex(String str2Check) {
        // "[-+]?[0-9]{1,13}(\\.[0-9]*)?" for double numbers
        String theRegex = "[-+]?[0-9]{1,13}";
        Point result = new Point(0, 0);
        ArrayList<String> list = new ArrayList<String>();
        Pattern checkRegex = Pattern.compile(theRegex);
        Matcher regexMatcher = checkRegex.matcher(str2Check);
        while (regexMatcher.find()) {
            if (regexMatcher.group().length() != 0) {
                result.y = Integer.parseInt(regexMatcher.group().trim());
            }
        }
        String phase2 = str2Check.replace(result.y + "", "");
        phase2 = numberRegex(phase2);
        result.x = Integer.parseInt(phase2);
        return result;
    }
    public ArrayList<String> regexChecker2(String theRegex, String str2Check) {
        // return a list of all matches
        ArrayList<String> list = new ArrayList<String>();
        Pattern checkRegex = Pattern.compile(theRegex);
        Matcher regexMatcher = checkRegex.matcher(str2Check);
        while (regexMatcher.find()) {
            if (regexMatcher.group().length() != 0) {
                list.add(regexMatcher.group().trim());
            }
        }
        return list;
    }

    public String contactRegex(String str2Check) {
        // return a list of all matches
        String theRegex = "(?<=contact)(.*)";
        ArrayList<String> list = new ArrayList<String>();
        Pattern checkRegex = Pattern.compile(theRegex);
        Matcher regexMatcher = checkRegex.matcher(str2Check);
        while (regexMatcher.find()) {
            if (regexMatcher.group().length() != 0) {
                return regexMatcher.group().trim();
            }
        }
        return "";
    }

    public String emailRegex(String str2Check) {
        // return a list of all matches
        String theRegex = "^([_a-zA-Z0-9-]+(\\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*(\\.[a-zA-Z]{1,6}))?$";
        ArrayList<String> list = new ArrayList<String>();
        Pattern checkRegex = Pattern.compile(theRegex);
        Matcher regexMatcher = checkRegex.matcher(str2Check);
        while (regexMatcher.find()) {
            if (regexMatcher.group().length() != 0) {
                return regexMatcher.group().trim();
            }
        }
        return "";
    }

    public String duplicateRegex(String str2Check) {
        // return a list of all matches
        // String theRegex = "\\b(\\w+)(\\b\\W+\\b\\1\\b)*";
        String theRegex = "\\b([\\w\\s']+) \\1\\b"; // set to 1 repeat of a word like hadoken hadoken
        ArrayList<String> list = new ArrayList<String>();
        Pattern checkRegex = Pattern.compile(theRegex);
        Matcher regexMatcher = checkRegex.matcher(str2Check);
        while (regexMatcher.find()) {
            if (regexMatcher.group().length() != 0) {
                return uniqueWord(regexMatcher.group().trim());
            }
        }
        return "";
    }

    public String uniqueWord(String str) {
        ArrayList<String> list = new ArrayList<String>();
        String s[] = str.split(" ");

        String p = s[0];
        list.add(p);

        for (int i = 1; i < s.length; i++) {

            if (!(p == s[i])) {
                list.add(s[i]);
            }
            p = s[i];
        } // i

        return list.get(0);
    }
    public String afterWord(String word, String str2Check) {
        // return a list of all matches
        String theRegex = "(?<=" + word + ")(.*)";
        ArrayList<String> list = new ArrayList<String>();
        Pattern checkRegex = Pattern.compile(theRegex);
        Matcher regexMatcher = checkRegex.matcher(str2Check);
        while (regexMatcher.find()) {
            if (regexMatcher.group().length() != 0) {
                return regexMatcher.group().trim();
            }
        }
        return "";
    }

    public String phoneRegex1(String str2Check) {
        return regexChecker("[0]\\d{2}\\d{4}\\d{3}$", str2Check);
    }

    public String firstWord(String str2Check) {
        String arr[] = str2Check.split(" ", 2);
        String firstWord = arr[0]; // the
        return firstWord;
    }
}
 

fukurou

the supreme coder
ADMIN
ZeroTimeGate :

Java:
import java.util.Calendar;
import java.util.Date;

public class ZeroTimeGate {
    // a gate that only opens x minutes after it has been set
    private int pause = 1;
    private Date openedGate = new Date();
    private Date checkPoint = new Date();

    public ZeroTimeGate(int minutes) {
        super();
        this.pause = minutes;
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            // e.printStackTrace();
        }
    }

    public ZeroTimeGate() {
    }

    public Boolean isClosed() {
        return openedGate.before(new Date());
    }

    public Boolean isOpen() {
        return !openedGate.before(new Date());
    }
    public void open() {
        this.openedGate = addMinutesToJavaUtilDate(new Date(), pause);
    }

    public void open(int minutes) {
        Date now = new Date();
        openedGate = addMinutesToJavaUtilDate(now, minutes);
    }

    private Date addMinutesToJavaUtilDate(Date date, int minutes) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.MINUTE, minutes);
        return calendar.getTime();
    }

    public void setPause(int pause) {
        if (pause < 60 && pause > 0) {
            this.pause = pause;
        }
    }

    public void resetCheckPoint() {
        this.checkPoint = new Date();
    }

    public int givenTwoDateTimesInJava8_whenDifferentiatingInSeconds_thenWeGetTen() {
        Date now = new Date();
        long diff = now.getTime() - this.checkPoint.getTime();
        long diffSeconds = diff / 1000 % 60;
        // long diffMinutes = diff / (60 * 1000) % 60;
        // long diffHours = diff / (60 * 60 * 1000) % 24;
        // long diffDays = diff / (24 * 60 * 60 * 1000);
        // System.out.print(diffDays + " days, ");
        // System.out.print(diffHours + " hours, ");
        // System.out.print(diffMinutes + " minutes, ");
        // System.out.print(diffSeconds + " seconds.");
        return (int) diffSeconds;
    }
}
 
Top