/*
* Subregions (base 1) described as { [start1, end1], [start2, end2], ...}
*/
- private List<int[]> fromShifts = new ArrayList<int[]>();
+ private List<int[]> fromShifts;
/*
* Same format as fromShifts, for the 'mapped to' sequence
*/
- private List<int[]> toShifts = new ArrayList<int[]>();
+ private List<int[]> toShifts;
/*
* number of steps in fromShifts to one toRatio unit
private int toHighest;
/**
+ * Constructor
+ */
+ public MapList()
+ {
+ fromShifts = new ArrayList<int[]>();
+ toShifts = new ArrayList<int[]>();
+ }
+
+ /**
* Two MapList objects are equal if they are the same object, or they both
* have populated shift ranges and all values are the same.
*/
}
/**
- * Constructor.
+ * Constructor given from and to ranges as [start1, end1, start2, end2,...].
+ * If any end is equal to the next start, the ranges will be merged.
*
* @param from
* contiguous regions as [start1, end1, start2, end2, ...]
*/
public MapList(int from[], int to[], int fromRatio, int toRatio)
{
+ this();
this.fromRatio = fromRatio;
this.toRatio = toRatio;
fromLowest = from[0];
fromHighest = from[1];
+ int added = 0;
+
for (int i = 0; i < from.length; i += 2)
{
fromLowest = Math.min(fromLowest, from[i]);
fromHighest = Math.max(fromHighest, from[i + 1]);
-
- fromShifts.add(new int[] { from[i], from[i + 1] });
+ if (added > 0 && from[i] == fromShifts.get(added - 1)[1])
+ {
+ /*
+ * this range starts where the last ended - just extend it
+ */
+ fromShifts.get(added - 1)[1] = from[i + 1];
+ }
+ else
+ {
+ fromShifts.add(new int[] { from[i], from[i + 1] });
+ added++;
+ }
}
toLowest = to[0];
toHighest = to[1];
+ added = 0;
for (int i = 0; i < to.length; i += 2)
{
toLowest = Math.min(toLowest, to[i]);
toHighest = Math.max(toHighest, to[i + 1]);
- toShifts.add(new int[] { to[i], to[i + 1] });
+ if (added > 0 && to[i] == toShifts.get(added - 1)[1])
+ {
+ toShifts.get(added - 1)[1] = to[i + 1];
+ }
+ else
+ {
+ toShifts.add(new int[] { to[i], to[i + 1] });
+ added++;
+ }
}
}
*/
public MapList(MapList map)
{
+ this();
// TODO not used - remove?
this.fromLowest = map.fromLowest;
this.fromHighest = map.fromHighest;
public MapList(List<int[]> fromRange, List<int[]> toRange, int fromRatio,
int toRatio)
{
+ this();
this.fromShifts = fromRange;
this.toShifts = toRange;
this.fromRatio = fromRatio;