package AXJava;
import LivinGrimoire.*;
public class LGTypeConverter {
private RegexUtil r1 = new RegexUtil();
public int convertToInt(String v1){
String temp = r1.extractRegex(enumRegexGrimoire.integer, v1);
if (temp.isEmpty()) {return 0;}
return Integer.parseInt(temp);
}
public Double convertToDouble(String v1){
String temp = r1.extractRegex(enumRegexGrimoire.double_num, v1);
if (temp.isEmpty()) {return 0.0;}
return Double.parseDouble(temp);
}
}
package AXJava;
import java.util.Hashtable;
public class Catche {
private Hashtable<String,String> dic1 = new Hashtable<>();
private int limit = 3;
public void setLimit(int limit) {
this.limit = limit;
}
public int getLimit() {
return limit;
}
public Boolean containsKey(String str1){
return dic1.containsKey(str1);
}
public void overwriteInsert(String oldKey,String key, String value){
int index = dicIndex.get(oldKey);
dicIndex.put(key,index);
dicIndex.remove(oldKey);
indexDic.remove(index);
indexDic.put(index,key);
dic1.remove(oldKey);
dic1.put(key,value);
}
public Boolean hasRoom(){
return limit > dic1.size();
}
private Hashtable<Integer,String> indexDic = new Hashtable<>();
private Hashtable<String, Integer> dicIndex = new Hashtable<>();
public void Insert(String key, String value){
if (hasRoom()) {
int index = dic1.size();
dic1.put(key,value);
indexDic.put(index,key);
dicIndex.put(key,index);
}
}
public void insertAt(int position, String key, String value){
if (!(position < limit) || !(position > -1)){
return;
}
String oldkey = indexDic.get(position);
dic1.remove(oldkey);
dic1.put(key,value);
indexDic.put(position, key);
dicIndex.remove(oldkey);
dicIndex.put(key,position);
}
public String getItem(String key){
return dic1.getOrDefault(key,"");
}
public String getItem(int position){
if (!(position < limit) || !(position > -1)){
return "";
}
String key = indexDic.get(position);
return dic1.getOrDefault(key,"");
}
}
public class CountDownGate {
private int cycler = 0;
private int limit;
public CountDownGate(int limit) {
super();
this.limit = limit;
cycler = limit;
}
public int getLimit() {
return limit;
}
public void setLimit(int limit) {
this.limit = limit;
}
public Boolean countingDown() {
cycler--;
if (cycler < 1) {
cycler = -1;
return false;
}
return true;
}
public void reset() {
cycler = limit;
}
public void setToOff() {
cycler = 0;
}
}
package AXJava;
public class Cycler {
// cycles through numbers limit to 0 non-stop
private int cycler = 0;
private int limit;
public Cycler(int limit) {
super();
this.limit = limit;
cycler = limit;
}
public int getLimit() {
return limit;
}
public void setLimit(int limit) {
this.limit = limit;
}
public int cycleCount() {
cycler--;
if (cycler < 0) {
cycler = limit;
}
return cycler;
}
public void reset() {
cycler = limit;
}
}
class DrawRnd {
private var numbers:Array<Int> = [Int]()
init(size:Int){
for index in 1...size{
numbers.append(index)
}
}
init(_ markers:Int...) {
for num in markers {
numbers.append(num)
}
}
func draw() -> Int {
if numbers.isEmpty {return 0}
let x:Int = Int.random(in: 0..<numbers.count)
let element:Int = numbers[x]
numbers.remove(at: x)
return element
}
}
package AXJava;
import java.util.ArrayList;
import java.util.Random;
public class DrawRnd {
// draw a random element than take said element out
private ArrayList<String> strings = new ArrayList<>();
private Random rand = new Random();
public DrawRnd(String... values) {
for (int i = 0; i < values.length; i++) {
strings.add(values[i]);
}
}
public String draw(){
if (strings.isEmpty()) {return "";}
int x = rand.nextInt(strings.size());
String element = strings.get(x);
strings.remove(x);
return element;
}
public int getSimpleRNDNum(int bound){
// return 0->bound-1
return rand.nextInt(bound);
}
private LGTypeConverter tc = new LGTypeConverter();
public int drawAsInt(){
if (strings.isEmpty()) {return 0;}
Random rand = new Random();
int x = rand.nextInt(strings.size());
String element = strings.get(x);
strings.remove(x);
return tc.convertToInt(element);
}
}
// (*)Algorithm Dispensers
class AlgDispenser {
// super class to output an algorithm out of a selection of algorithms
var algs:Array<Algorithm> = [Algorithm]()
var activeAlg:Int = 0
init(_algorithms:Algorithm...){
for alg in _algorithms {
algs.append(alg)
}
}
func addAlgorithm(alg:Algorithm) -> AlgDispenser {
algs.append(alg)
return self
}
func dispenseAlgorithm() -> Algorithm {
return algs[activeAlg]
}
func rndAlg(){
activeAlg = Int.random(in: 0..<algs.count)
}
func moodAlg (mood:Int){
let c1:Int = algs.count
if -1<mood && mood<c1 {
activeAlg = mood
}
}
func cycleAlg(){
activeAlg += 1
if activeAlg == algs.count {activeAlg = 0}
}
}
package AXJava;
import LivinGrimoire.Algorithm;
import java.util.ArrayList;
import java.util.Random;
// (*)Algorithm Dispensers
public class AlgDispenser {
// super class to output an algorithm out of a selection of algorithms
private ArrayList<Algorithm> algs = new ArrayList<Algorithm>();
private int activeAlg = 0;
private Random rand = new Random();
public AlgDispenser(Algorithm...algorithms) {
for (Algorithm alg : algorithms)
{
algs.add(alg);
}
}
public AlgDispenser addAlgorithm(Algorithm alg){
// builder pattern
algs.add(alg);
return this;
}
public Algorithm dispenseAlgorithm(){
return algs.get(activeAlg);
}
public Algorithm rndAld(){
// return a random algorithm
return algs.get(rand.nextInt(algs.size()));
}
public void moodAlg(int mood){
// set output algorithm based on number representing mood
if ((mood>-1) && mood < (algs.size())){
activeAlg = mood;
}
}
public void algUpdate(int mood,Algorithm alg){
// update an algorithm
if (!((mood>-1) && mood < (algs.size()))){
return;
}
algs.set(mood,alg);
}
public void algRemove(int mood){
// remove an algorithm
if (!((mood>-1) && mood < (algs.size()))){
return;
}
algs.remove(mood);
}
public void cycleAlg(){
activeAlg++;
if (activeAlg == algs.size()){
activeAlg = 0;
}
}
}