@Override public void add(int pos, Element arg1) { // all numbers >= pos in the two sets must be incremented by one adjustAllGE(sectionElementIndices, pos, 1); adjustAllGE(nonSectionElementIndices, pos, 1); // now we can do the addition entries.add(pos, arg1); ((arg1 instanceof Section) ? sectionElementIndices : nonSectionElementIndices).add(pos); elementForName.put(arg1.getName(), arg1); }
@Override public Element set(int arg0, Element arg1) { Element replaced = entries.set(arg0, arg1); elementForName.remove(replaced.getName()); elementForName.put(arg1.getName(), arg1); if (replaced instanceof Section) { // we lost a section sectionElementIndices.remove(arg0); } else { // we lost a non-section nonSectionElementIndices.remove(arg0); } if (arg1 instanceof Section) { // we gained a section sectionElementIndices.add(arg0); } else { // we gained a non-section nonSectionElementIndices.add(arg0); } return replaced; }
@Override public boolean add(Element arg) { elementForName.put(arg.getName(), arg); boolean changed = entries.add(arg); if (changed) { int pos = size() - 1; incrementSectionCounters(arg, pos); } return changed; }
@Override public boolean remove(Object arg) { boolean ret = entries.remove(arg); int pos = entries.indexOf(arg); if (ret) { // remove its index from the appropriate set decrementSectionCounters((Element) arg, pos); // adjust other indices adjustAllGE(nonSectionElementIndices, pos, -1); adjustAllGE(sectionElementIndices, pos, -1); // now we can remove it elementForName.remove(((Element) arg).getName()); } return ret; }
private Element(String name, int alignment, int elementIndex) { /* Null is not allowed as an Element name. */ assert name != null : "Null not allowed as Element name."; /* The empty string is not allowed as a name. */ assert !name.equals("") : "The empty string is not allowed as an Element name."; this.name = name; if (elementIndex == -1) { ObjectFile.this.elements.add(this); } else { ObjectFile.this.elements.add(elementIndex, this); } /* check our name mapping was created. */ assert ObjectFile.this.elements.forName(getName()) == this; this.alignment = alignment; }
public String nameForElement(Element e) { return e.getName(); }
@Override public Element remove(int arg0) { adjustAllGE(sectionElementIndices, arg0, -1); adjustAllGE(nonSectionElementIndices, arg0, -1); Element e = entries.remove(arg0); elementForName.remove(e.getName()); return e; }