package Sequenic.T2; import java.util.Random; /** * An implementation of {@link Sequenic.T2.BaseDomain BaseDomain}, providing * values for primitive types, enumeration types, and String. This is T2's * default base domain. Its behavior * is as follows: * *
    *

  1. If an instance of an enumeration type is requested, one will be * picked randomly. * *

  2. If an instance of a boolean or Boolean is requested, than true or * false will be chosen randomly. * *

  3. If an instance of a int-like numeric type (primitive or its wrapper) is * requested, a value between -3 upto (and exclusive) range-3 will be picked * randomly. The default of range is 7. * *

  4. If an instance of a float-like numeric type (primitive or its wrapper) is * requested, a value between -3 upto (and exclusive) range-3 will be picked * randomly. * *

  5. If an instance of a char is requested, one of the following will be * chosen randomly: 'a', 'A', '@' , '\n' , '\u0000', '\uFFFF'. * *

  6. If an instance of a string is requested, one of the following will be * chosen randomly: "", * "croco", * "TiGeR", * "1", * "line1 \n line2", * "\n \t", * "~!@#$%^&*()_-+<>?,.:;'[]{}`", * "\"quote me\"", * "\"". * *

  7. If a value of a primitive type is requested, this base domain * always return a value of its wrapper type. * *

  8. This base domain never returns a null. *
* * */ public class BaseDomainSmall extends BaseDomain { protected Random rnd = new Random() ; protected int range = 7 ; public int getRange() { return range; } protected char[] charsupply = { 'a' , 'A', '@' , '\n' , '\u0000', '\uFFFF' } ; protected String[] stringsupply = { "", "croco", "TiGeR", "1", "line1 \n line2", "\n \t", "~!@#$%^&*()_-+<>?,.:;'[]{}`", "\"quote me\"", "\"" } ; public char[] getCharsupply() { return charsupply ; } public String[] getStringsupply() { return stringsupply ; } // Introduce these variables at the object level as optimization: private int a = 0 ; private float x = 0 ; private Object[] res = new Object[1] ; public BaseDomainSmall() { } public BaseDomainSmall(int Range) { range = Range ; } public Object[] get(Class C) { a = rnd.nextInt(range) - 3 ; x = rnd.nextFloat()*range - 3 ; //System.out.println(">>" + a) ; //System.out.println(">>" + x) ; if (C == Integer.TYPE || C == Integer.class) { res[0] = a ; return res ; } if (C == Float.TYPE || C == Float.class) { res[0] = x ; return res ; } if (C == Double.TYPE || C == Double.class) { res[0] = x ; return res ; } if (C == Boolean.TYPE || C == Boolean.class) { res[0] = rnd.nextBoolean() ; return res ; } if (C == Byte.TYPE || C == Byte.class) { res[0] = (byte) a ; return res ; } if (C == Short.TYPE || C == Short.class) { res[0] = (short) a ; return res ; } if (C == Long.TYPE || C == Long.class) { res[0] = a ; return res ; } if (C == Character.TYPE || C == Character.class) { //System.out.println("!!!") ; res[0] = charsupply[rnd.nextInt(charsupply.length)] ; return res ; } if (C == String.class) { res[0] = stringsupply[rnd.nextInt(stringsupply.length)] ; return res ; } if (C.isEnum()) { Object [] enumvals = C.getEnumConstants() ; res[0] = enumvals[rnd.nextInt(enumvals.length)] ; return res ; } return null ; } }