001/*-----------------------------------------------------------------------+ 002 | com.teamscale.ui 003 | | 004 $Id$ 005 | | 006 | Copyright (c) 2009-2013 CQSE GmbH | 007 +-----------------------------------------------------------------------*/ 008package org.conqat.lib.commons.diff; 009 010/** 011 * Class describing a substring of the diffed text as used for the diff 012 * algorithms. 013 */ 014public class TextChunk { 015 016 /** Start offset of the text (inclusive, 0-based). */ 017 /* package */final int startOffset; 018 019 /** End offset of the text (exclusive, 0-based). */ 020 /* package */final int endOffset; 021 022 /** Start offset of the text (inclusive, 1-based). */ 023 /* package */final int startLine; 024 025 /** End offset of the text (exclusive, 1-based). */ 026 /* package */final int endLine; 027 028 /** Text used for comparison of the chunk. */ 029 private final String comparisonText; 030 031 /** Constructor. */ 032 public TextChunk(int startOffset, int endOffset, int startLine, int endLine, String comparisonText) { 033 this.startOffset = startOffset; 034 this.endOffset = endOffset; 035 this.startLine = startLine; 036 this.endLine = endLine; 037 this.comparisonText = comparisonText; 038 } 039 040 /** {@inheritDoc} */ 041 @Override 042 public int hashCode() { 043 return comparisonText.hashCode(); 044 } 045 046 /** {@inheritDoc} */ 047 @Override 048 public boolean equals(Object other) { 049 return ((TextChunk) other).comparisonText.equals(comparisonText); 050 } 051 052 /** {@inheritDoc} */ 053 @Override 054 public String toString() { 055 return "\"" + comparisonText + "\" (lines: " + startLine + "-" + endLine + ", offsets: " + startOffset + "-" 056 + endOffset + ")"; 057 } 058}