public boolean addAt(int index, Object e) { if (index < 0) index = size(); while (index > size()) { if (!add(Converter.convert(null, type))) return false; } if (type != null) e = Converter.convert(e, type); super.add(index, e); return true; }
/** * Copy from the copy method in StructUtil. Did not want to drag that code in. maybe this actually * should go to struct. * * @param from * @param to * @param excludes * @return * @throws Exception */ public static <T extends struct> T xcopy(struct from, T to, String... excludes) throws Exception { Arrays.sort(excludes); for (Field f : from.fields()) { if (Arrays.binarySearch(excludes, f.getName()) >= 0) continue; Object o = f.get(from); if (o == null) continue; Field tof = to.getField(f.getName()); if (tof != null) try { tof.set(to, Converter.cnv(tof.getGenericType(), o)); } catch (Exception e) { System.out.println( "Failed to convert " + f.getName() + " from " + from.getClass() + " to " + to.getClass() + " value " + o + " exception " + e); } } return to; }
public Object set(int index, Object e) { Object old = get(index); if (index < 0 || index >= size()) add(index, e); else { if (type != null) e = Converter.convert(e, type); super.set(index, e); } return old; }