/** * Add a new double constant to the ConstantPool, if it is not already in there. * * @param n Double number to add * @return index of entry */ public int addDouble(double n) { int ret; if((ret = lookupDouble(n)) != -1) return ret; // Already in CP adjustSize(); ret = index; constants[index] = new ConstantDouble(n); index += 2; // Wastes one entry according to spec return ret; }
/** * Add a new double constant to the ConstantPool, if it is not already in there. * * @param n Double number to add * @return index of entry */ public int addDouble( final double n ) { int ret; if ((ret = lookupDouble(n)) != -1) { return ret; // Already in CP } adjustSize(); ret = index; constants[index] = new ConstantDouble(n); index += 2; // Wastes one entry according to spec return ret; }
public void testCreateDoubleElementValue() throws Exception { final ClassGen cg = createClassGen("HelloWorld"); final ConstantPoolGen cp = cg.getConstantPool(); final SimpleElementValueGen evg = new SimpleElementValueGen( ElementValueGen.PRIMITIVE_DOUBLE, cp, 333.44); // Creation of an element like that should leave a new entry in the // cpool final int idx = cp.lookupDouble(333.44); assertTrue("Should have the same index in the constantpool but " + evg.getIndex() + "!=" + idx, evg.getIndex() == idx); checkSerialize(evg, cp); }