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: class QSequenceRestrictedMedia implements QSequenceMedia {
18:
19: // Fields =================================================================
20:
21: private final QSequenceMedia media;
22:
23: private int leftMin;
24: private int rightMin;
25: private int leftMax;
26: private int rightMax;
27:
28: // Setup ==================================================================
29:
30: public QSequenceRestrictedMedia(QSequenceMedia media) {
31: this .media = media;
32: restrictTo(1, media.getLeftLength(), 1, media.getRightLength());
33: }
34:
35: // Accessing ==============================================================
36:
37: public void restrictTo(int leftMin, int leftMax, int rightMin,
38: int rightMax) {
39: if (QSequenceAlgorithm.ASSERTIONS) {
40: QSequenceAssert.assertTrue(0 <= leftMin
41: && leftMin <= leftMax + 1);
42: QSequenceAssert
43: .assertTrue(leftMax <= media.getLeftLength());
44: QSequenceAssert.assertTrue(0 <= rightMin
45: && rightMin <= rightMax + 1);
46: QSequenceAssert.assertTrue(rightMax <= media
47: .getRightLength());
48: }
49:
50: this .leftMin = leftMin;
51: this .leftMax = leftMax;
52: this .rightMin = rightMin;
53: this .rightMax = rightMax;
54: }
55:
56: // Implemented ============================================================
57:
58: public int getLeftLength() {
59: return leftMax - leftMin + 1;
60: }
61:
62: public int getRightLength() {
63: return rightMax - rightMin + 1;
64: }
65:
66: public boolean equals(int leftIndex, int rightIndex)
67: throws QSequenceException {
68: if (QSequenceAlgorithm.ASSERTIONS) {
69: QSequenceAssert.assertTrue(1 <= leftIndex
70: && leftIndex <= leftMax - leftMin + 1);
71: }
72: if (QSequenceAlgorithm.ASSERTIONS) {
73: QSequenceAssert.assertTrue(1 <= rightIndex
74: && rightIndex <= rightMax - rightMin + 1);
75: }
76: return media.equals(leftMin + leftIndex - 2, rightMin
77: + rightIndex - 2);
78: }
79:
80: // Accessing ==============================================================
81:
82: public int getLeftMin() {
83: return leftMin;
84: }
85:
86: public int getLeftMax() {
87: return leftMax;
88: }
89:
90: public int getRightMin() {
91: return rightMin;
92: }
93:
94: public int getRightMax() {
95: return rightMax;
96: }
97:
98: }
|