1
2
3
4
5
6
7
8
9
10
11 package org.eclipse.jgit.diff;
12
13
14
15
16
17
18
19
20
21
22
23 public class HashedSequencePair<S extends Sequence> {
24 private final SequenceComparator<? super S> cmp;
25
26 private final S baseA;
27
28 private final S baseB;
29
30 private HashedSequence<S> cachedA;
31
32 private HashedSequence<S> cachedB;
33
34
35
36
37
38
39
40
41
42
43
44 public HashedSequencePair(SequenceComparator<? super S> cmp, S a, S b) {
45 this.cmp = cmp;
46 this.baseA = a;
47 this.baseB = b;
48 }
49
50
51
52
53
54
55 public HashedSequenceComparator<S> getComparator() {
56 return new HashedSequenceComparator<>(cmp);
57 }
58
59
60
61
62
63
64 public HashedSequence<S> getA() {
65 if (cachedA == null)
66 cachedA = wrap(baseA);
67 return cachedA;
68 }
69
70
71
72
73
74
75 public HashedSequence<S> getB() {
76 if (cachedB == null)
77 cachedB = wrap(baseB);
78 return cachedB;
79 }
80
81 private HashedSequence<S> wrap(S base) {
82 final int end = base.size();
83 final int[] hashes = new int[end];
84 for (int ptr = 0; ptr < end; ptr++)
85 hashes[ptr] = cmp.hash(base, ptr);
86 return new HashedSequence<>(base, hashes);
87 }
88 }