comparison src/org/tmatesoft/hg/internal/IntVector.java @ 552:45751456b471

Annotate file changes through few revisions, walking either direction (old to new and vice versa)
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 20 Feb 2013 22:23:50 +0100
parents 4ea0351ca878
children d3c71498919c
comparison
equal deleted inserted replaced
551:4ea0351ca878 552:45751456b471
47 data[count++] = v; 47 data[count++] = v;
48 } 48 }
49 49
50 public void add(int... values) { 50 public void add(int... values) {
51 if (count + values.length > data.length) { 51 if (count + values.length > data.length) {
52 grow(count + values.length - data.length); 52 grow(count + values.length);
53 } 53 }
54 for (int v : values) { 54 for (int v : values) {
55 data[count++] = v; 55 data[count++] = v;
56 } 56 }
57 } 57 }
90 public int[] toArray() { 90 public int[] toArray() {
91 int[] rv = new int[count]; 91 int[] rv = new int[count];
92 System.arraycopy(data, 0, rv, 0, count); 92 System.arraycopy(data, 0, rv, 0, count);
93 return rv; 93 return rv;
94 } 94 }
95
96 public void reverse() {
97 for (int a = 0, b = count-1; a < b; a++, b--) {
98 int t = data[b];
99 data[b] = data[a];
100 data[a] = t;
101 }
102 }
103
104 @Override
105 public String toString() {
106 return String.format("%s[%d]", IntVector.class.getSimpleName(), size());
107 }
95 108
96 /** 109 /**
97 * Use only when this instance won't be used any longer 110 * Use only when this instance won't be used any longer
98 */ 111 */
99 @Experimental 112 @Experimental
115 assert newCapacity > 0 && newCapacity != data.length : newCapacity; 128 assert newCapacity > 0 && newCapacity != data.length : newCapacity;
116 int[] newData = new int[newCapacity]; 129 int[] newData = new int[newCapacity];
117 System.arraycopy(data, 0, newData, 0, count); 130 System.arraycopy(data, 0, newData, 0, count);
118 data = newData; 131 data = newData;
119 } 132 }
120
121 @Override
122 public String toString() {
123 return String.format("%s[%d]", IntVector.class.getSimpleName(), size());
124 }
125 } 133 }