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;
13:
14: import java.util.*;
15:
16: import de.regnis.q.sequence.core.*;
17: import de.regnis.q.sequence.media.*;
18:
19: /**
20: * @author Marc Strapetz
21: */
22: public class QSequenceDifference implements QSequenceSnakeRegister,
23: QSequenceCommonBlockFactory {
24:
25: // Fields =================================================================
26:
27: private final QSequenceMedia media;
28: private final QSequenceMediaIndexTransformer indexTransformer;
29: private final boolean[] leftCommonPoints;
30: private final boolean[] rightCommonPoints;
31: private final int maximumSearchDepth;
32:
33: // Setup ==================================================================
34:
35: public QSequenceDifference(QSequenceMedia media,
36: QSequenceMediaIndexTransformer indexTransformer) {
37: this (media, indexTransformer, Integer.MAX_VALUE);
38: }
39:
40: public QSequenceDifference(QSequenceMedia media,
41: QSequenceMediaIndexTransformer indexTransformer,
42: int maximumSearchDepth) {
43: QSequenceAssert.assertNotNull(media);
44: QSequenceAssert.assertNotNull(indexTransformer);
45:
46: this .media = media;
47: this .indexTransformer = indexTransformer;
48: this .leftCommonPoints = new boolean[indexTransformer
49: .getMediaLeftLength()];
50: this .rightCommonPoints = new boolean[indexTransformer
51: .getMediaRightLength()];
52: this .maximumSearchDepth = maximumSearchDepth;
53: }
54:
55: // Implemented ============================================================
56:
57: public void registerSnake(int leftFrom, int leftTo, int rightFrom,
58: int rightTo) throws QSequenceCancelledException {
59: for (int leftIndex = leftFrom; leftIndex <= leftTo; leftIndex++) {
60: QSequenceAssert
61: .assertTrue(!leftCommonPoints[indexTransformer
62: .getMediaLeftIndex(leftIndex)]);
63: leftCommonPoints[indexTransformer
64: .getMediaLeftIndex(leftIndex)] = true;
65: }
66:
67: for (int rightIndex = rightFrom; rightIndex <= rightTo; rightIndex++) {
68: QSequenceAssert
69: .assertTrue(!rightCommonPoints[indexTransformer
70: .getMediaRightIndex(rightIndex)]);
71: rightCommonPoints[indexTransformer
72: .getMediaRightIndex(rightIndex)] = true;
73: }
74: }
75:
76: public Object createCommonBlock(int leftFrom, int leftTo,
77: int rightFrom, int rightTo) {
78: return null;
79: }
80:
81: public Object createDistinctBlock(int leftFrom, int leftTo,
82: int rightFrom, int rightTo) {
83: return new QSequenceDifferenceBlock(leftFrom, leftTo,
84: rightFrom, rightTo);
85: }
86:
87: // Accessing ==============================================================
88:
89: public List getBlocks() throws QSequenceException {
90: final QSequenceAlgorithm algorithm = new QSequenceAlgorithm(
91: media, this, maximumSearchDepth);
92: algorithm.produceSnakesInOrder();
93: return QSequenceCommonBlocks.createBlocks(leftCommonPoints,
94: rightCommonPoints, this);
95: }
96: }
|