mirror of
https://github.com/apache/commons-collections.git
synced 2025-03-01 14:29:06 +00:00
[COLLECTIONS-404] Make Snake an inner class of SequencesComparator.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1476814 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
9ea429c977
commit
e7ae9283ba
@ -90,6 +90,25 @@ public class SequencesComparator<T> {
|
|||||||
vUp = new int[size];
|
vUp = new int[size];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the {@link EditScript} object.
|
||||||
|
* <p>
|
||||||
|
* It is guaranteed that the objects embedded in the {@link InsertCommand
|
||||||
|
* insert commands} come from the second sequence and that the objects
|
||||||
|
* embedded in either the {@link DeleteCommand delete commands} or
|
||||||
|
* {@link KeepCommand keep commands} come from the first sequence. This can
|
||||||
|
* be important if subclassing is used for some elements in the first
|
||||||
|
* sequence and the <code>equals</code> method is specialized.
|
||||||
|
*
|
||||||
|
* @return the edit script resulting from the comparison of the two
|
||||||
|
* sequences
|
||||||
|
*/
|
||||||
|
public EditScript<T> getScript() {
|
||||||
|
final EditScript<T> script = new EditScript<T>();
|
||||||
|
buildScript(0, sequence1.size(), 0, sequence2.size(), script);
|
||||||
|
return script;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build a snake.
|
* Build a snake.
|
||||||
*
|
*
|
||||||
@ -250,22 +269,58 @@ public class SequencesComparator<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the {@link EditScript} object.
|
* This class is a simple placeholder to hold the end part of a path
|
||||||
* <p>
|
* under construction in a {@link SequencesComparator SequencesComparator}.
|
||||||
* It is guaranteed that the objects embedded in the {@link InsertCommand
|
|
||||||
* insert commands} come from the second sequence and that the objects
|
|
||||||
* embedded in either the {@link DeleteCommand delete commands} or
|
|
||||||
* {@link KeepCommand keep commands} come from the first sequence. This can
|
|
||||||
* be important if subclassing is used for some elements in the first
|
|
||||||
* sequence and the <code>equals</code> method is specialized.
|
|
||||||
*
|
|
||||||
* @return the edit script resulting from the comparison of the two
|
|
||||||
* sequences
|
|
||||||
*/
|
*/
|
||||||
public EditScript<T> getScript() {
|
private static class Snake {
|
||||||
final EditScript<T> script = new EditScript<T>();
|
|
||||||
buildScript(0, sequence1.size(), 0, sequence2.size(), script);
|
/** Start index. */
|
||||||
return script;
|
private final int start;
|
||||||
|
|
||||||
|
/** End index. */
|
||||||
|
private final int end;
|
||||||
|
|
||||||
|
/** Diagonal number. */
|
||||||
|
private final int diag;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple constructor. Creates a new instance of Snake with specified indices.
|
||||||
|
*
|
||||||
|
* @param start start index of the snake
|
||||||
|
* @param end end index of the snake
|
||||||
|
* @param diag diagonal number
|
||||||
|
*/
|
||||||
|
public Snake(final int start, final int end, final int diag) {
|
||||||
|
this.start = start;
|
||||||
|
this.end = end;
|
||||||
|
this.diag = diag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the start index of the snake.
|
||||||
|
*
|
||||||
|
* @return start index of the snake
|
||||||
|
*/
|
||||||
|
public int getStart() {
|
||||||
|
return start;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the end index of the snake.
|
||||||
|
*
|
||||||
|
* @return end index of the snake
|
||||||
|
*/
|
||||||
|
public int getEnd() {
|
||||||
|
return end;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the diagonal number of the snake.
|
||||||
|
*
|
||||||
|
* @return diagonal number of the snake
|
||||||
|
*/
|
||||||
|
public int getDiag() {
|
||||||
|
return diag;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,90 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.apache.commons.collections4.comparators.sequence;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class is a simple placeholder to hold the end part of a path
|
|
||||||
* under construction in a {@link SequencesComparator SequencesComparator}.
|
|
||||||
* <p>
|
|
||||||
* A snake is an internal structure used in Eugene W. Myers algorithm
|
|
||||||
* (<a href="http://www.cis.upenn.edu/~bcpierce/courses/dd/papers/diff.ps">
|
|
||||||
* An O(ND) Difference Algorithm and Its Variations</a>).
|
|
||||||
*
|
|
||||||
* @since 4.0
|
|
||||||
* @version $Id$
|
|
||||||
*/
|
|
||||||
public class Snake {
|
|
||||||
|
|
||||||
/** Start index. */
|
|
||||||
private final int start;
|
|
||||||
|
|
||||||
/** End index. */
|
|
||||||
private final int end;
|
|
||||||
|
|
||||||
/** Diagonal number. */
|
|
||||||
private final int diag;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Simple constructor. Creates a new instance of Snake with default indices.
|
|
||||||
*/
|
|
||||||
public Snake() {
|
|
||||||
start = -1;
|
|
||||||
end = -1;
|
|
||||||
diag = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Simple constructor. Creates a new instance of Snake with specified indices.
|
|
||||||
*
|
|
||||||
* @param start start index of the snake
|
|
||||||
* @param end end index of the snake
|
|
||||||
* @param diag diagonal number
|
|
||||||
*/
|
|
||||||
public Snake(final int start, final int end, final int diag) {
|
|
||||||
this.start = start;
|
|
||||||
this.end = end;
|
|
||||||
this.diag = diag;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the start index of the snake.
|
|
||||||
*
|
|
||||||
* @return start index of the snake
|
|
||||||
*/
|
|
||||||
public int getStart() {
|
|
||||||
return start;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the end index of the snake.
|
|
||||||
*
|
|
||||||
* @return end index of the snake
|
|
||||||
*/
|
|
||||||
public int getEnd() {
|
|
||||||
return end;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the diagonal number of the snake.
|
|
||||||
*
|
|
||||||
* @return diagonal number of the snake
|
|
||||||
*/
|
|
||||||
public int getDiag() {
|
|
||||||
return diag;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user