DefineList { public void generateSource(StringBuilder sb, List<String> defineNames, List<VarType> defineTypes) { for (int i = 0; i < values.length; i++) { if (!isSet(i)) { continue; } sb.append("#define ").append(defineNames.get(i)).append(' '); if (defineTypes != null && defineTypes.get(i) == VarType.Float) { float val = Float.intBitsToFloat(values[i]); if (Float.isInfinite(val) || Float.isNaN(val)) { throw new IllegalArgumentException( "GLSL does not support NaN " + "or Infinite float literals"); } sb.append(val); } else { sb.append(values[i]); } sb.append('\n'); } } DefineList(int numValues); private  DefineList(DefineList original); boolean isSet(int id); void unset(int id); void set(int id, int val); void set(int id, float val); void set(int id, boolean val); void set(int id, VarType type, Object value); void setAll(DefineList other); void clear(); boolean getBoolean(int id); float getFloat(int id); int getInt(int id); @Override int hashCode(); @Override boolean equals(Object other); DefineList deepClone(); void generateSource(StringBuilder sb, List<String> defineNames, List<VarType> defineTypes); String generateSource(List<String> defineNames, List<VarType> defineTypes); static final int MAX_DEFINES; }
@Test public void testGenerateSource() { DefineList dl = new DefineList(NUM_DEFINES); assertEquals("", generateSource(dl)); dl.set(BOOL_VAR, true); assertEquals("#define BOOL_VAR 1\n", generateSource(dl)); dl.set(INT_VAR, 123); assertEquals("#define BOOL_VAR 1\n" + "#define INT_VAR 123\n", generateSource(dl)); dl.set(BOOL_VAR, false); assertEquals("#define INT_VAR 123\n", generateSource(dl)); dl.set(BOOL_VAR, true); assertEquals("#define BOOL_VAR 1\n" + "#define INT_VAR 123\n", generateSource(dl)); dl.unset(BOOL_VAR); assertEquals("#define INT_VAR 123\n", generateSource(dl)); }