/** * Define equality of state. Equality is based on the MainStartPos of the * attribute. * * @param aThat * the {@link PropertyTextUnitPlaceholder} that is compared to * this object */ @Override public boolean equals(Object aThat) { if (this == aThat) return true; if (!(aThat instanceof PropertyTextUnitPlaceholder)) return false; PropertyTextUnitPlaceholder that = (PropertyTextUnitPlaceholder) aThat; return (this.getMainStartPos() == that.getMainStartPos()); }
/** * Compare two {@link PropertyTextUnitPlaceholder}s. Compare is based in * MainStartPos order only. Allows sorting of many * {@link PropertyTextUnitPlaceholder}s in the order they appear in the * input * * @param aThat * the {@link PropertyTextUnitPlaceholder} used to compare to * this object */ public int compareTo(PropertyTextUnitPlaceholder aThat) { final int BEFORE = -1; final int EQUAL = 0; final int AFTER = 1; // this optimization is usually worthwhile, and can // always be added if (this.getMainStartPos() == aThat.getMainStartPos()) return EQUAL; // primitive numbers follow this form if (this.getMainStartPos() < aThat.getMainStartPos()) return BEFORE; if (this.getMainStartPos() > aThat.getMainStartPos()) return AFTER; return EQUAL; }
/** * <b>A class that overrides equals must also override hashCode.</b> Return * a hash code based on the MainStartPos only */ @Override public int hashCode() { int result = HashCodeUtil.SEED; result = HashCodeUtil.hash(result, this.getMainStartPos()); return result; }
private void embeddedReadonlyProp(INameable resource, PropertyTextUnitPlaceholder propOrText, String tag, LocaleId locId) { setPropertyBasedOnLocale(resource, locId, new Property(propOrText.getName(), propOrText.getValue(), true)); currentSkeleton.add(tag.substring(propOrText.getMainStartPos(), propOrText.getMainEndPos())); }
/** * Appends an existing list placeholders to this text run. * @param text optional text to add to the run * @param offset the offset of the placeholders (added to the start / end) * @param propertyTextUnitPlaceholders The existing placeholders to add. */ public void appendWithPropertyTextUnitPlaceholders(String text, int offset, List<PropertyTextUnitPlaceholder> propertyTextUnitPlaceholders) { if ( text != null ) this.text.append(text); for(PropertyTextUnitPlaceholder p : propertyTextUnitPlaceholders) { p.setMainStartPos(p.getMainStartPos()+offset); p.setMainEndPos(p.getMainEndPos()+offset); p.setValueStartPos(p.getValueStartPos()+offset); p.setValueEndPos(p.getValueEndPos()+offset); if (this.propertyTextUnitPlaceholders==null) this.propertyTextUnitPlaceholders = new ArrayList<PropertyTextUnitPlaceholder>(); this.propertyTextUnitPlaceholders.add(p); } }
private void embeddedWritableProp(INameable resource, PropertyTextUnitPlaceholder propOrText, String tag, LocaleId locale) { setPropertyBasedOnLocale(resource, locale, new Property(propOrText.getName(), propOrText.getValue(), false)); currentSkeleton.add(tag.substring(propOrText.getMainStartPos(), propOrText.getValueStartPos())); currentSkeleton.addValuePlaceholder(resource, propOrText.getName(), locale); currentSkeleton.add(tag.substring(propOrText.getValueEndPos(), propOrText.getMainEndPos())); }
currentSkeleton.add(tag.substring(0, pt.getMainStartPos())); PropertyTextUnitPlaceholder pt1 = propertyTextUnitPlaceholders.get(propOrTextId - 1); PropertyTextUnitPlaceholder pt2 = propertyTextUnitPlaceholders.get(propOrTextId); currentSkeleton.add(tag.substring(pt1.getMainEndPos(), pt2.getMainStartPos()));
private ITextUnit embeddedTextUnit(PropertyTextUnitPlaceholder propOrText, String tag) { ITextUnit tu = new TextUnit(textUnitId.createId(), propOrText.getValue()); tu.setPreserveWhitespaces(this.preserveWhitespace); tu.setMimeType(propOrText.getMimeType()); tu.setIsReferent(true); tu.setType(propOrText.getElementType() == null ? propOrText.getName() : propOrText.getElementType()); GenericSkeleton skel = new GenericSkeleton(); skel.add(tag.substring(propOrText.getMainStartPos(), propOrText.getValueStartPos())); skel.addContentPlaceholder(tu); skel.add(tag.substring(propOrText.getValueEndPos(), propOrText.getMainEndPos())); tu.setSkeleton(skel); postProcessTextUnit(tu); return tu; }