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.media;
13:
14: import de.regnis.q.sequence.core.*;
15:
16: /**
17: * @author Marc Strapetz
18: */
19: public class QSequenceDiscardingMedia implements QSequenceMedia,
20: QSequenceMediaIndexTransformer {
21:
22: // Fields =================================================================
23:
24: private final QSequenceIntMedia media;
25: private final QSequenceCanceller canceller;
26: private final QSequenceDiscardingMediaBlock leftBlock;
27: private final QSequenceDiscardingMediaBlock rightBlock;
28:
29: private final int[] undiscardedLeftSymbols;
30: private final int[] undiscardedRightSymbols;
31: private final int undiscardedLeftSymbolCount;
32: private final int undiscardedRightSymbolCount;
33:
34: // Setup ==================================================================
35:
36: public QSequenceDiscardingMedia(
37: QSequenceIntMedia media,
38: QSequenceDiscardingMediaConfusionDetector confusionDetector,
39: QSequenceCanceller canceller) {
40: this .media = media;
41: this .canceller = canceller;
42: this .leftBlock = new QSequenceDiscardingMediaLeftBlock(
43: this .media);
44: this .rightBlock = new QSequenceDiscardingMediaRightBlock(
45: this .media);
46:
47: leftBlock.init(rightBlock, confusionDetector);
48: rightBlock.init(leftBlock, confusionDetector);
49:
50: undiscardedLeftSymbols = leftBlock.getUndiscardedSymbols();
51: undiscardedLeftSymbolCount = leftBlock
52: .getUndiscardedSymbolCount();
53: undiscardedRightSymbols = rightBlock.getUndiscardedSymbols();
54: undiscardedRightSymbolCount = rightBlock
55: .getUndiscardedSymbolCount();
56: }
57:
58: // Implemented ============================================================
59:
60: public int getLeftLength() {
61: return undiscardedLeftSymbolCount;
62: }
63:
64: public int getRightLength() {
65: return undiscardedRightSymbolCount;
66: }
67:
68: public boolean equals(int leftIndex, int rightIndex)
69: throws QSequenceCancelledException {
70: canceller.checkCancelled();
71: return undiscardedLeftSymbols[leftIndex] == undiscardedRightSymbols[rightIndex];
72: }
73:
74: public int getMediaLeftIndex(int index) {
75: return leftBlock.getMediaIndex(index);
76: }
77:
78: public int getMediaRightIndex(int index) {
79: return rightBlock.getMediaIndex(index);
80: }
81:
82: public int getMediaLeftLength() {
83: return media.getLeftLength();
84: }
85:
86: public int getMediaRightLength() {
87: return media.getRightLength();
88: }
89: }
|