Mercurial > jhg
annotate src/org/tmatesoft/hg/internal/IntTuple.java @ 685:9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 25 Jul 2013 21:32:09 +0200 |
parents | 1c49c0cee540 |
children |
rev | line source |
---|---|
674
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
1 /* |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2013 TMate Software Ltd |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
3 * |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
6 * the Free Software Foundation; version 2 of the License. |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
7 * |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
8 * This program is distributed in the hope that it will be useful, |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
11 * GNU General Public License for more details. |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
12 * |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
13 * For information on how to redistribute this software under |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
14 * the terms of a license other than GNU General Public License |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
15 * contact TMate Software at support@hg4j.com |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
16 */ |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
17 package org.tmatesoft.hg.internal; |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
19 /** |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
20 * Tuple of integers |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
21 * @author Artem Tikhomirov |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
22 * @author TMate Software Ltd. |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
23 */ |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
24 public final class IntTuple implements Cloneable { |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
25 private final int size; |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
26 private IntVector v; |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
27 private int start; |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
28 |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
29 IntTuple(int length) { |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
30 size = length; |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
31 } |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
32 /*package*/IntTuple set(IntVector vect, int index) { |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
33 v = vect; |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
34 start = index; |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
35 return this; |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
36 } |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
37 |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
38 public int size() { |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
39 return size; |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
40 } |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
41 |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
42 public int at(int index) { |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
43 if (index < size) { |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
44 return v.get(start + index); |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
45 } |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
46 throw new IllegalArgumentException(String.valueOf(index)); |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
47 } |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
48 |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
49 public IntTuple clone() { |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
50 try { |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
51 return (IntTuple) super.clone(); |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
52 } catch (CloneNotSupportedException ex) { |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
53 throw new Error(ex); |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
54 } |
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
55 } |
677
1c49c0cee540
Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
56 |
1c49c0cee540
Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
57 @Override |
1c49c0cee540
Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
58 public String toString() { |
1c49c0cee540
Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
59 StringBuilder sb = new StringBuilder(); |
1c49c0cee540
Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
60 sb.append('('); |
1c49c0cee540
Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
61 for (int i = 0; i < size; i++) { |
1c49c0cee540
Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
62 sb.append(at(i)); |
1c49c0cee540
Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
63 sb.append(", "); |
1c49c0cee540
Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
64 } |
1c49c0cee540
Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
65 sb.setLength(sb.length() - 2); |
1c49c0cee540
Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
66 sb.append(')'); |
1c49c0cee540
Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
67 return sb.toString(); |
1c49c0cee540
Report line number at the first appearance, like 'hg annotate -l' does
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
674
diff
changeset
|
68 } |
674
cce0387c6041
Introduced dedicated IntSliceSeq/IntTuple in place of IntArray with subsequences
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
69 } |