Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@
<method>createXmlStream</method>
<justification>This method is not intended to be overwritten</justification>
</item>
<item>
<code>java.field.serialVersionUIDUnchanged</code>
<classSimpleName>Change</classSimpleName>
<justification>This API is not finally in use yet.</justification>
</item>
</differences>
</revapi.differences>
</analysisConfiguration>
Expand Down
60 changes: 51 additions & 9 deletions src/main/java/io/jenkins/plugins/forensics/delta/model/Change.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
/**
* A change made on specific lines within a specific file.
*
* <p>The lines are defined by a starting and an ending point (1-based line counter), describing the made changes within
* the new version of the file. In case of a deleted file, the line range describes the deleted lines within the old
* version of the file, since only then it is possible to determine what has been deleted.
* <p>The interval of lines which contains the change is defined by a starting and an ending point (1-based line
* counter). Also, the affected lines of the file before the change has been inserted are specified by a starting and an
* ending point, as already described, in order to be able to determine removed lines for example.
*
* @author Florian Orendi
*/
Expand All @@ -20,11 +20,20 @@ public class Change implements Serializable {
private final ChangeEditType changeEditType;

/**
* The starting point of the change (1-based).
* The included starting point of the lines which will be affected by this change (1-based).
*/
private int changedFromLine = 0; // since 1.9.0
/**
* The included ending point of the lines which will be affected by this change (1-based).
*/
private int changedToLine = 0; // since 1.9.0

/**
* The included starting point of the lines which contain the change (1-based).
*/
private final int fromLine;
/**
* The ending point of the change (1-based).
* The included ending point of the lines which contain the change (1-based).
*/
private final int toLine;

Expand All @@ -37,9 +46,35 @@ public class Change implements Serializable {
* The starting line
* @param toLine
* The ending line
*
* @deprecated This constructor is deprecated since it does not initialize the interval which provides the
* information about which lines of the original file has been affected by the change. This interval will be
* initialized with '0'.
*/
@Deprecated
public Change(final ChangeEditType changeEditType, final int fromLine, final int toLine) {
this(changeEditType, 0, 0, fromLine, toLine);
}

/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use this(...) to initialize the deprecated constructor

* Constructor for an instance which wraps a specific change within a file.
*
* @param changeEditType
* The type of the change
* @param changedFromLine
* The starting line of the lines which are affected by the change
* @param changedToLine
* The ending line of the lines which are affected by the change
* @param fromLine
* The starting line of the inserted change
* @param toLine
* The ending line of the inserted change
*/
public Change(final ChangeEditType changeEditType, final int changedFromLine, final int changedToLine,
final int fromLine, final int toLine) {
this.changeEditType = changeEditType;
this.changedFromLine = changedFromLine;
this.changedToLine = changedToLine;
this.fromLine = fromLine;
this.toLine = toLine;
}
Expand All @@ -48,6 +83,14 @@ public ChangeEditType getEditType() {
return changeEditType;
}

public int getChangedFromLine() {
return changedFromLine;
}

public int getChangedToLine() {
return changedToLine;
}

public int getFromLine() {
return fromLine;
}
Expand All @@ -65,13 +108,12 @@ public boolean equals(final Object o) {
return false;
}
Change change = (Change) o;
return fromLine == change.fromLine
&& toLine == change.toLine
&& changeEditType == change.changeEditType;
return changedFromLine == change.changedFromLine && changedToLine == change.changedToLine
&& fromLine == change.fromLine && toLine == change.toLine && changeEditType == change.changeEditType;
}

@Override
public int hashCode() {
return Objects.hash(changeEditType, fromLine, toLine);
return Objects.hash(changeEditType, changedFromLine, changedToLine, fromLine, toLine);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,26 @@
class ChangeTest {

private static final ChangeEditType EDIT_TYPE = ChangeEditType.INSERT;
private static final int CHANGED_FROM_LINE = 1;
private static final int CHANGED_TO_LINE = 1;
private static final int FROM_LINE = 1;
private static final int TO_LINE = 3;

@Test
void testChangeGetters() {
void shouldHaveWorkingGetters() {
Change change = createChange();
assertThat(change.getEditType()).isEqualTo(EDIT_TYPE);
assertThat(change.getFromLine()).isEqualTo(FROM_LINE);
assertThat(change.getToLine()).isEqualTo(TO_LINE);
assertThat(change).hasEditType(EDIT_TYPE);
assertThat(change).hasChangedFromLine(CHANGED_FROM_LINE);
assertThat(change).hasChangedToLine(CHANGED_TO_LINE);
assertThat(change).hasFromLine(FROM_LINE);
assertThat(change).hasToLine(TO_LINE);
}

@Test
void shouldInitializeChangedLinesPerDefault() {
Change change = new Change(EDIT_TYPE, FROM_LINE, TO_LINE);
assertThat(change).hasChangedFromLine(0);
assertThat(change).hasChangedToLine(0);
}

@Test
Expand All @@ -36,6 +47,6 @@ void shouldObeyEqualsContract() {
* @return the created instance
*/
private Change createChange() {
return new Change(EDIT_TYPE, FROM_LINE, TO_LINE);
return new Change(EDIT_TYPE, CHANGED_FROM_LINE, CHANGED_TO_LINE, FROM_LINE, TO_LINE);
}
}