File: VsqBPListComparisonContext.cs

package info (click to toggle)
cadencii 3.3.9%2Bsvn20110818.r1732-6
  • links: PTS
  • area: main
  • in suites: buster
  • size: 35,916 kB
  • sloc: cs: 160,836; java: 42,449; cpp: 7,605; ansic: 1,728; perl: 1,087; makefile: 236; php: 142; xml: 117; sh: 21
file content (114 lines) | stat: -rw-r--r-- 3,466 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
 * VsqBPListComparisonContext.cs
 * Copyright © 2010-2011 kbinani
 *
 * This file is part of org.kbinani.cadencii.
 *
 * org.kbinani.cadencii is free software; you can redistribute it and/or
 * modify it under the terms of the GPLv3 License.
 *
 * org.kbinani.cadencii is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 */
#if JAVA
package org.kbinani.cadencii;

import org.kbinani.vsq.*;
#else
using System;
using org.kbinani.vsq;

namespace org.kbinani.cadencii {
    using boolean = System.Boolean;
#endif

    /// <summary>
    /// VsqBPListを比較するための,比較用コンテキスト
    /// </summary>
#if JAVA
    public class VsqBPListComparisonContext implements IComparisonContext {
#else
    public class VsqBPListComparisonContext : IComparisonContext {
#endif
        public class WrappedVsqBPPair {
            public VsqBPPair body;
            public int clock;

            public WrappedVsqBPPair( VsqBPPair body, int clock ) {
                this.body = body;
                this.clock = clock;
            }
        }

        VsqBPList list1 = null;
        VsqBPList list2 = null;
        int pos1 = -1;
        int pos2 = -1;

        public VsqBPListComparisonContext( VsqBPList list1, VsqBPList list2 ) {
            // インデクス0の位置に,デフォルト値を持つダミーがあるように振舞わせる
            this.list1 = list1;
            this.list2 = list2;
        }

        public int getNextIndex1() {
            pos1++;
            return pos1;
        }

        public int getNextIndex2() {
            pos2++;
            return pos2;
        }

        public boolean hasNext1() {
            return (pos1 < list1.size());
        }

        public boolean hasNext2() {
            return (pos2 < list2.size());
        }

        public Object getElementAt1( int index ) {
            if ( index <= 0 ) {
                return new WrappedVsqBPPair( new VsqBPPair( list1.getDefault(), -1 ), 0 );
            } else {
                return new WrappedVsqBPPair( list1.getElementB( index - 1 ), list1.getKeyClock( index - 1 ) );
            }
        }

        public Object getElementAt2( int index ) {
            if ( index <= 0 ) {
                return new WrappedVsqBPPair( new VsqBPPair( list2.getDefault(), -1 ), 0 );
            } else {
                return new WrappedVsqBPPair( list2.getElementB( index - 1 ), list2.getKeyClock( index - 1 ) );
            }
        }

        public int getClockFrom( Object obj ) {
            if ( obj == null ) {
                return 0;
            }
            if ( !(obj is WrappedVsqBPPair) ) {
                return 0;
            }
            return ((WrappedVsqBPPair)obj).clock;
        }

        public boolean equals( Object obj1, Object obj2 ) {
            if ( obj1 == null || obj2 == null ) {
                return false;
            }
            if ( !(obj1 is WrappedVsqBPPair) || !(obj2 is WrappedVsqBPPair) ) {
                return false;
            }
            WrappedVsqBPPair item1 = (WrappedVsqBPPair)obj1;
            WrappedVsqBPPair item2 = (WrappedVsqBPPair)obj2;
            return (item1.body.value == item2.body.value);
        }
    }

#if !JAVA
}
#endif