mirror of
https://github.com/dmolony/DiskBrowser.git
synced 2024-06-15 19:29:45 +00:00
62 lines
1.3 KiB
Java
62 lines
1.3 KiB
Java
|
package com.bytezone.diskbrowser.visicalc;
|
||
|
|
||
|
import java.security.InvalidParameterException;
|
||
|
import java.util.ArrayList;
|
||
|
import java.util.Iterator;
|
||
|
import java.util.List;
|
||
|
|
||
|
class Range implements Iterable<Address>
|
||
|
{
|
||
|
Address from, to;
|
||
|
List<Address> range = new ArrayList<Address> ();
|
||
|
|
||
|
public Range (Address from, Address to)
|
||
|
{
|
||
|
this.from = from;
|
||
|
this.to = to;
|
||
|
|
||
|
range.add (from);
|
||
|
|
||
|
if (from.row == to.row)
|
||
|
while (from.compareTo (to) < 0)
|
||
|
{
|
||
|
from = from.nextColumn ();
|
||
|
range.add (from);
|
||
|
}
|
||
|
else if (from.column == to.column)
|
||
|
while (from.compareTo (to) < 0)
|
||
|
{
|
||
|
from = from.nextRow ();
|
||
|
range.add (from);
|
||
|
}
|
||
|
else
|
||
|
throw new InvalidParameterException ();
|
||
|
}
|
||
|
|
||
|
public Range (String[] cells)
|
||
|
{
|
||
|
for (String s : cells)
|
||
|
range.add (new Address (s));
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public String toString ()
|
||
|
{
|
||
|
if (from == null || to == null)
|
||
|
{
|
||
|
StringBuilder text = new StringBuilder ();
|
||
|
for (Address address : range)
|
||
|
text.append (address.text + ",");
|
||
|
if (text.length () > 0)
|
||
|
text.deleteCharAt (text.length () - 1);
|
||
|
return text.toString ();
|
||
|
}
|
||
|
return String.format (" %s -> %s", from.text, to.text);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public Iterator<Address> iterator ()
|
||
|
{
|
||
|
return range.iterator ();
|
||
|
}
|
||
|
}
|