/** * Add a new Float constant to the ConstantPool, if it is not already in there. * * @param n Float number to add * @return index of entry */ public int addFloat(float n) { int ret; if((ret = lookupFloat(n)) != -1) return ret; // Already in CP adjustSize(); ret = index; constants[index++] = new ConstantFloat(n); return ret; }
/** * Add a new Float constant to the ConstantPool, if it is not already in there. * * @param n Float number to add * @return index of entry */ public int addFloat( final float n ) { int ret; if ((ret = lookupFloat(n)) != -1) { return ret; // Already in CP } adjustSize(); ret = index; constants[index++] = new ConstantFloat(n); return ret; }
public void testCreateFloatElementValue() throws Exception { final ClassGen cg = createClassGen("HelloWorld"); final ConstantPoolGen cp = cg.getConstantPool(); final SimpleElementValueGen evg = new SimpleElementValueGen( ElementValueGen.PRIMITIVE_FLOAT, cp, 111.222f); // Creation of an element like that should leave a new entry in the // cpool assertTrue("Should have the same index in the constantpool but " + evg.getIndex() + "!=" + cp.lookupFloat(111.222f), evg .getIndex() == cp.lookupFloat(111.222f)); checkSerialize(evg, cp); }