01: /*
02: * ====================================================================
03: * Copyright (c) 2004 Marc Strapetz, marc.strapetz@smartsvn.com.
04: * All rights reserved.
05: *
06: * This software is licensed as described in the file COPYING, which
07: * you should have received as part of this distribution. Use is
08: * subject to license terms.
09: * ====================================================================
10: */
11:
12: package de.regnis.q.sequence.core;
13:
14: /**
15: * @author Marc Strapetz
16: */
17: final class QSequenceDeePathBackwardExtender extends
18: QSequenceDeePathExtender {
19:
20: // Fields =================================================================
21:
22: private int delta;
23: private int mediaLeftLength;
24: private int mediaRightLength;
25:
26: // Setup ==================================================================
27:
28: public QSequenceDeePathBackwardExtender(int maximumMediaLeftLength,
29: int maximumMediaRightLength) {
30: super (new QSequenceDeePathExtenderArray(maximumMediaLeftLength
31: + maximumMediaRightLength));
32: }
33:
34: // Accessing ==============================================================
35:
36: protected int getNextX(QSequenceDeePathExtenderArray xs,
37: int diagonal, int dee) {
38: if (diagonal - delta == dee
39: || (diagonal - delta != -dee && xs.get(diagonal + 1) > xs
40: .get(diagonal - 1))) {
41: return xs.get(diagonal - 1);
42: }
43:
44: return xs.get(diagonal + 1) - 1;
45: }
46:
47: protected int getSnakeX(QSequenceMedia media, int x, int y)
48: throws QSequenceException {
49: for (; x > 0 && y > 0 && media.equals(x, y);) {
50: x--;
51: y--;
52: }
53:
54: return x;
55: }
56:
57: protected final void reset(QSequenceMedia media,
58: QSequenceDeePathExtenderArray xs) {
59: mediaLeftLength = media.getLeftLength();
60: mediaRightLength = media.getRightLength();
61: delta = mediaLeftLength - mediaRightLength;
62: xs.setDelta(delta);
63: xs.set(delta - 1, mediaLeftLength);
64: }
65:
66: public int getProgress(int diagonal) {
67: return mediaLeftLength - getLeft(diagonal) + mediaRightLength
68: - getRight(diagonal);
69: }
70: }
|