Skip to content

Commit 5ad7223

Browse files
committed
Add new equals overloads to glyphline-related classes
DEVSIX-1259
1 parent efeb4a7 commit 5ad7223

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

io/src/main/java/com/itextpdf/io/font/otf/Glyph.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ public boolean equals(Object obj) {
300300
if (this == obj) {
301301
return true;
302302
}
303-
if (!(obj instanceof Glyph)) {
303+
if (obj == null || getClass() != obj.getClass()) {
304304
return false;
305305
}
306306
Glyph other = (Glyph) obj;

io/src/main/java/com/itextpdf/io/font/otf/GlyphLine.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,37 @@ public Iterator<GlyphLinePart> iterator() {
319319
return new ActualTextIterator(this);
320320
}
321321

322+
@Override
323+
public boolean equals(Object obj) {
324+
if (this == obj) {
325+
return true;
326+
}
327+
if (obj == null || getClass() != obj.getClass()) {
328+
return false;
329+
}
330+
GlyphLine other = (GlyphLine)obj;
331+
if (end - start != other.end - other.start) {
332+
return false;
333+
}
334+
if (actualText == null && other.actualText != null || actualText != null && other.actualText == null) {
335+
return false;
336+
}
337+
for (int i = start; i < end; i++) {
338+
int otherPos = other.start + i - start;
339+
Glyph myGlyph = get(i);
340+
Glyph otherGlyph = other.get(otherPos);
341+
if (myGlyph == null && otherGlyph != null || !myGlyph.equals(otherGlyph)) {
342+
return false;
343+
}
344+
ActualText myAT = actualText == null ? null : actualText.get(i);
345+
ActualText otherAT = other.actualText == null ? null : other.actualText.get(otherPos);
346+
if (myAT == null && otherAT != null || !myAT.equals(otherAT)) {
347+
return false;
348+
}
349+
}
350+
return true;
351+
}
352+
322353
private void removeGlyph(int index) {
323354
glyphs.remove(index);
324355
if (actualText != null) {
@@ -369,5 +400,17 @@ public ActualText(String value) {
369400
}
370401

371402
public String value;
403+
404+
@Override
405+
public boolean equals(Object obj) {
406+
if (this == obj) {
407+
return true;
408+
}
409+
if (obj == null || getClass() != obj.getClass()) {
410+
return false;
411+
}
412+
ActualText other = (ActualText) obj;
413+
return value == null && other.value == null || value.equals(other.value);
414+
}
372415
}
373416
}

0 commit comments

Comments
 (0)