/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License.
*/
package org.netbeans.api.diff;
import java.io.Serializable;
/** * This class represents a single difference between two files. * * @author Martin Entlicher
*/ publicclass Difference extends Object implements Serializable {
/** Delete type of difference - a portion of a file was removed in the other */ publicstaticfinalintDELETE = 0;
/** Add type of difference - a portion of a file was added in the other */ publicstaticfinalint ADD = 1;
/** Change type of difference - a portion of a file was changed in the other */ publicstaticfinalint CHANGE = 2;
/** The text of the difference in the first file. */ private String firstText; /** The text of the difference in the second file. */ private String secondText;
/** * Creates a new instance of Difference * @param type The type of the difference. Must be one of the {@link #DELETE DELETE}, * {@link #ADD ADD} or {@link #CHANGE CHANGE} * @param firstStart The line number on which the difference starts in the first file. * @param firstEnd The line number on which the difference ends in the first file. * @param secondStart The line number on which the difference starts in the second file. * @param secondEnd The line number on which the difference ends in the second file.
*/ public Difference(int type, int firstStart, int firstEnd, int secondStart, int secondEnd) { this(type, firstStart, firstEnd, secondStart, secondEnd, null, null, null, null);
}
/** * Creates a new instance of Difference * @param type The type of the difference. Must be one of the {@link #DELETE DELETE}, * {@link #ADD ADD} or {@link #CHANGE CHANGE} * @param firstStart The line number on which the difference starts in the first file. * @param firstEnd The line number on which the difference ends in the first file. * @param secondStart The line number on which the difference starts in the second file. * @param secondEnd The line number on which the difference ends in the second file. * @param firstText The text content of the difference in the first file. * @param secondText The text content of the difference in the second file.
*/ public Difference(int type, int firstStart, int firstEnd, int secondStart, int secondEnd,
String firstText, String secondText) { this(type, firstStart, firstEnd, secondStart, secondEnd, firstText, secondText, null, null);
}
/** * Creates a new instance of Difference * @param type The type of the difference. Must be one of the {@link #DELETE DELETE}, * {@link #ADD ADD} or {@link #CHANGE CHANGE} * @param firstStart The line number on which the difference starts in the first file. * @param firstEnd The line number on which the difference ends in the first file. * @param secondStart The line number on which the difference starts in the second file. * @param secondEnd The line number on which the difference ends in the second file. * @param firstText The text content of the difference in the first file. * @param secondText The text content of the difference in the second file. * @param firstLineDiffs The list of differences on lines in the first file. * The list contains instances of {@link Difference.Part}. * Can be <code>null</code> when there are no line differences. * @param secondLineDiffs The list of differences on lines in the second file. * The list contains instances of {@link Difference.Part}. * Can be <code>null</code> when there are no line differences.
*/ public Difference(int type, int firstStart, int firstEnd, int secondStart, int secondEnd,
String firstText, String secondText, Difference.Part[] firstLineDiffs, Difference.Part[] secondLineDiffs) { if (type > 2 || type < 0) { thrownew IllegalArgumentException("Bad Difference type = "+type);
} this.type = type; this.firstStart = firstStart; this.firstEnd = firstEnd; this.secondStart = secondStart; this.secondEnd = secondEnd; this.firstText = firstText; this.secondText = secondText; this.firstLineDiffs = firstLineDiffs; this.secondLineDiffs = secondLineDiffs;
}
/** * Get the difference type. It's one of {@link #DELETE DELETE}, * {@link #ADD ADD} or {@link #CHANGE CHANGE} meaning * respective change in second source.
*/ publicint getType() { returnthis.type;
}
/** * Get the line number on which the difference starts in the first file. * * <p>For ADD changes it returns previous line number e.g. 0 for add * file start.
*/ publicint getFirstStart() { returnthis.firstStart;
}
/** * Get the line number on which the difference ends in the first file. * <p> * Does not have any meaning for ADD changes.
*/ publicint getFirstEnd() { returnthis.firstEnd;
}
/** * Get the line number on which the difference starts in the second file.
*/ publicint getSecondStart() { returnthis.secondStart;
}
/** * Get the line number on which the difference ends in the second file. * <p> * Does not have any meaning for DELETE changes.
*/ publicint getSecondEnd() { returnthis.secondEnd;
}
/** * The list of differences on lines in the first file. * The list contains instances of {@link Difference.Part}. * Can be <code>null</code> when there are no line differences.
*/ public Difference.Part[] getFirstLineDiffs() { return firstLineDiffs;
}
/** * The list of differences on lines in the second file. * The list contains instances of {@link Difference.Part}. * Can be <code>null</code> when there are no line differences.
*/ public Difference.Part[] getSecondLineDiffs() { return secondLineDiffs;
}
/** * Get the text content of the difference in the first file.
*/ public String getFirstText() { return firstText;
}
/** * Get the text content of the difference in the second file.
*/ public String getSecondText() { return secondText;
}
/** * Creates a new instance of LineDiff * @param type The type of the difference. Must be one of the {@link #DELETE DELETE}, * {@link #ADD ADD} or {@link #CHANGE CHANGE} * @param line The line number * @param pos1 The position on which the difference starts on this line. * @param pos2 The position on which the difference ends on this line.
*/ public Part(int type, int line, int pos1, int pos2) { if (type > 2 || type < 0) { thrownew IllegalArgumentException("Bad Difference type = "+type);
} this.type = type; this.line = line; this.pos1 = pos1; this.pos2 = pos2;
}
/** * Get the difference type. It's one of {@link #DELETE DELETE}, * {@link #ADD ADD} or {@link #CHANGE CHANGE}.
*/ publicint getType() { returnthis.type;
}
/** * Get the line number.
*/ publicint getLine() { returnthis.line;
}
/** * Get the position on which the difference starts on this line.
*/ publicint getStartPosition() { returnthis.pos1;
}
/** * Get the position on which the difference ends on this line.
*/ publicint getEndPosition() { returnthis.pos2;
}
/** * Set the text content of the difference. * public void setText(String text) { this.text = text; } /** * Get the text content of the difference. * public String getText() { return text; }
*/
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.