add hashCode() and equals() to ReplaceRegion

Signed-off-by: mmews <marcus.mews@numberfour.eu>
This commit is contained in:
mmews 2020-01-15 14:33:58 +01:00
parent 0b7156d54f
commit 198a74e270

View file

@ -7,6 +7,8 @@
*******************************************************************************/
package org.eclipse.xtext.util;
import java.util.Objects;
/**
* @author Jan Koehnlein - Initial contribution and API
* @author Sebastian Zarnekow
@ -56,6 +58,25 @@ public class ReplaceRegion {
builder.replace(offset, getEndOffset(), text);
}
@Override
public boolean equals(Object object) {
if (object instanceof ReplaceRegion) {
ReplaceRegion rr = (ReplaceRegion) object;
boolean equals = true;
equals = equals && Objects.equals(getOffset(), rr.getOffset());
equals = equals && Objects.equals(getLength(), rr.getLength());
equals = equals && Objects.equals(getText(), rr.getText());
return equals;
}
return false;
}
@Override
public int hashCode() {
return Objects.hash(getOffset(), getLength(), getText());
}
@Override
public String toString() {
return "replace region [" + offset + " / length: " + length + "] '" + text + "'";