de.regnis.q.sequence.core.QSequenceDeePathBackwardExtender Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sequence-library Show documentation
Show all versions of sequence-library Show documentation
Textual Diff and Merge Library
/*
* ====================================================================
* Copyright (c) 2000-2008 SyntEvo GmbH, [email protected]
* All rights reserved.
*
* This software is licensed as described in the file SEQUENCE-LICENSE,
* which you should have received as part of this distribution. Use is
* subject to license terms.
* ====================================================================
*/
package de.regnis.q.sequence.core;
/**
* @author Marc Strapetz
*/
final class QSequenceDeePathBackwardExtender extends QSequenceDeePathExtender {
// Fields =================================================================
private int delta;
private int mediaLeftLength;
private int mediaRightLength;
// Setup ==================================================================
public QSequenceDeePathBackwardExtender(int maximumMediaLeftLength, int maximumMediaRightLength) {
super(new QSequenceDeePathExtenderArray(maximumMediaLeftLength + maximumMediaRightLength));
}
// Accessing ==============================================================
protected int getNextX(QSequenceDeePathExtenderArray xs, int diagonal, int dee) {
if (diagonal - delta == dee || (diagonal - delta != -dee && xs.get(diagonal + 1) > xs.get(diagonal - 1))) {
return xs.get(diagonal - 1);
}
return xs.get(diagonal + 1) - 1;
}
protected int getSnakeX(QSequenceMedia media, int x, int y) throws QSequenceException {
for (; x > 0 && y > 0 && media.equals(x, y);) {
x--;
y--;
}
return x;
}
protected final void reset(QSequenceMedia media, QSequenceDeePathExtenderArray xs) {
mediaLeftLength = media.getLeftLength();
mediaRightLength = media.getRightLength();
delta = mediaLeftLength - mediaRightLength;
xs.setDelta(delta);
xs.set(delta - 1, mediaLeftLength);
}
public int getProgress(int diagonal) {
return mediaLeftLength - getLeft(diagonal) + mediaRightLength - getRight(diagonal);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy