001: /*
002: * ====================================================================
003: * Copyright (c) 2004 Marc Strapetz, marc.strapetz@smartsvn.com.
004: * All rights reserved.
005: *
006: * This software is licensed as described in the file COPYING, which
007: * you should have received as part of this distribution. Use is
008: * subject to license terms.
009: * ====================================================================
010: */
011:
012: package de.regnis.q.sequence;
013:
014: import junit.framework.*;
015:
016: import de.regnis.q.sequence.core.*;
017: import de.regnis.q.sequence.media.*;
018:
019: /**
020: * @author Marc Strapetz
021: */
022: public class QSequenceTestMedia implements QSequenceCachableMedia,
023: QSequenceMediaComparer {
024:
025: // Static =================================================================
026:
027: public static QSequenceTestMedia createStringMedia(String[] left,
028: String[] right) {
029: return new QSequenceTestMedia(left, right);
030: }
031:
032: public static QSequenceTestMedia createCharacterMedia(
033: String leftChars, String rightChars) {
034: final String[] left = new String[leftChars.length()];
035: for (int index = 0; index < left.length; index++) {
036: left[index] = String.valueOf(leftChars.charAt(index));
037: }
038: final String[] right = new String[rightChars.length()];
039: for (int index = 0; index < right.length; index++) {
040: right[index] = String.valueOf(rightChars.charAt(index));
041: }
042: return new QSequenceTestMedia(left, right);
043: }
044:
045: // Fields =================================================================
046:
047: private final String[] left;
048: private final String[] right;
049:
050: // Setup ==================================================================
051:
052: private QSequenceTestMedia(String[] left, String[] right) {
053: this .left = left;
054: this .right = right;
055: }
056:
057: // Implemented ============================================================
058:
059: public int getLeftLength() {
060: return left.length;
061: }
062:
063: public int getRightLength() {
064: return right.length;
065: }
066:
067: public Object getMediaLeftObject(int index) {
068: return left[index];
069: }
070:
071: public Object getMediaRightObject(int index) {
072: return right[index];
073: }
074:
075: public boolean equals(int leftIndex, int rightIndex) {
076: Assert.assertTrue(0 <= leftIndex && leftIndex < left.length);
077: Assert.assertTrue(0 <= rightIndex && rightIndex < right.length);
078:
079: return left[leftIndex].equals(right[rightIndex]);
080: }
081:
082: public boolean equalsLeft(int left1, int left2)
083: throws QSequenceCancelledException {
084: return left[left1].equals(left[left2]);
085: }
086:
087: public boolean equalsRight(int right1, int right2)
088: throws QSequenceCancelledException {
089: return right[right1].equals(right[right2]);
090: }
091:
092: // Accessing ==============================================================
093:
094: public String getLeftLine(int index) {
095: return left[index];
096: }
097:
098: public String getRightLine(int index) {
099: return right[index];
100: }
101: }
|