diff src/org/tmatesoft/hg/internal/IntSliceSeq.java @ 680:58a6900f845d

Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Sun, 21 Jul 2013 17:15:34 +0200
parents 19f5167c2155
children
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/internal/IntSliceSeq.java	Sat Jul 20 17:40:52 2013 +0200
+++ b/src/org/tmatesoft/hg/internal/IntSliceSeq.java	Sun Jul 21 17:15:34 2013 +0200
@@ -24,7 +24,7 @@
  * @author Artem Tikhomirov
  * @author TMate Software Ltd.
  */
-public final class IntSliceSeq implements Iterable<IntTuple> {
+public final class IntSliceSeq implements Iterable<IntTuple>, Cloneable {
 	private final IntVector slices;
 	private final int slice;
 
@@ -39,13 +39,13 @@
 	}
 	
 	public IntSliceSeq add(int... values) {
-		checkValues(values);
+		checkValuesAny(values);
 		slices.add(values);
 		return this;
 	}
 	
 	public IntSliceSeq set(int sliceIndex, int... values) {
-		checkValues(values);
+		checkValuesExact(values);
 		for (int i = 0, j = sliceIndex*slice; i < slice; i++,j++) {
 			slices.set(j, values[i]);
 		}
@@ -63,6 +63,13 @@
 		return slices.get(sliceIndex*slice + valueIndex);
 	}
 	
+	public void addAll(IntSliceSeq other) {
+		if (other.slice != this.slice) {
+			throw new IllegalArgumentException(String.format("Tuple size doesn't match: %d and %d", slice, other.slice));
+		}
+		slices.addAll(other.slices);
+	}
+	
 	public int size() {
 		return slices.size() / slice;
 	}
@@ -117,6 +124,15 @@
 		}
 		return sb.toString();
 	}
+	
+	@Override
+	public IntSliceSeq clone() {
+		try {
+			return (IntSliceSeq) super.clone();
+		} catch (CloneNotSupportedException ex) {
+			throw new Error(ex);
+		}
+	}
 
 	private void checkArgRange(int rangeSize, int index) {
 		if (index >= 0 && index < rangeSize) {
@@ -124,9 +140,14 @@
 		}
 		throw new IllegalArgumentException(String.valueOf(index));
 	}
-	private void checkValues(int[] values) {
+	private void checkValuesExact(int[] values) {
 		if (values == null || values.length != slice) {
 			throw new IllegalArgumentException(String.valueOf(values == null ? values : values.length));
 		}
 	}
+	private void checkValuesAny(int[] values) {
+		if (values == null || values.length % slice != 0) {
+			throw new IllegalArgumentException(String.valueOf(values == null ? values : values.length));
+		}
+	}
 }