added contains() to AppleFileSource

This commit is contained in:
Denis Molony 2016-02-26 08:49:22 +11:00
parent 922956086c
commit 1b1726a5e0
10 changed files with 86 additions and 40 deletions

View File

@ -29,4 +29,6 @@ public interface AppleFileSource
* Returns the actual FormattedDisk that owns this object.
*/
public FormattedDisk getFormattedDisk ();
public boolean contains (DiskAddress diskAddress);
}

View File

@ -81,6 +81,15 @@ public class DirectoryEntry implements AppleFileSource
}
}
@Override
public boolean contains (DiskAddress da)
{
for (DiskAddress sector : blocks)
if (sector.compareTo (da) == 0)
return true;
return false;
}
public String line ()
{
int blocks = ((rc & 0xF0) >> 3) + (((rc & 0x0F) + 7) / 8);

View File

@ -29,7 +29,6 @@ public abstract class AbstractFormattedDisk implements FormattedDisk
protected ActionListener actionListenerList;
protected JTree catalogTree;
protected Path originalPath;
// protected String originalName;
protected List<SectorType> sectorTypesList = new ArrayList<SectorType> ();
protected List<AppleFileSource> fileEntries = new ArrayList<AppleFileSource> ();
@ -40,7 +39,6 @@ public abstract class AbstractFormattedDisk implements FormattedDisk
public final SectorType emptySector = new SectorType ("Unused (empty)", Color.white);
public final SectorType usedSector = new SectorType ("Unused (data)", Color.yellow);
// public final SectorType dosSector = new SectorType ("DOS", Color.lightGray);
protected int falsePositives;
protected int falseNegatives;
@ -304,6 +302,10 @@ public abstract class AbstractFormattedDisk implements FormattedDisk
@Override
public String getSectorFilename (DiskAddress da)
{
for (AppleFileSource entry : fileEntries)
if (entry.contains (da))
return (entry).getUniqueName ();
return "unknown";
}

View File

@ -50,16 +50,19 @@ public class DefaultAppleFileSource implements AppleFileSource
((DefaultDataSource) file).buffer = owner.getDisk ().readSectors (blocks);
}
@Override
public DataSource getDataSource ()
{
return file;
}
@Override
public FormattedDisk getFormattedDisk ()
{
return owner;
}
@Override
public List<DiskAddress> getSectors ()
{
return blocks;
@ -81,8 +84,18 @@ public class DefaultAppleFileSource implements AppleFileSource
return title;
}
@Override
public String getUniqueName ()
{
return title;
}
@Override
public boolean contains (DiskAddress diskAddress)
{
for (DiskAddress da : blocks)
if (da.compareTo (diskAddress) == 0)
return true;
return false;
}
}

View File

@ -257,7 +257,8 @@ abstract class AbstractCatalogEntry implements AppleFileSource
return appleFile;
}
boolean contains (DiskAddress da)
@Override
public boolean contains (DiskAddress da)
{
for (DiskAddress sector : tsSectors)
if (sector.compareTo (da) == 0)

View File

@ -337,14 +337,14 @@ public class DosDisk extends AbstractFormattedDisk
return super.getFormattedSector (da);
}
@Override
public String getSectorFilename (DiskAddress da)
{
for (AppleFileSource ce : fileEntries)
if (((CatalogEntry) ce).contains (da))
return ((CatalogEntry) ce).name;
return null;
}
// @Override
// public String getSectorFilename (DiskAddress da)
// {
// for (AppleFileSource ce : fileEntries)
// if (((CatalogEntry) ce).contains (da))
// return ((CatalogEntry) ce).name;
// return null;
// }
@Override
public List<DiskAddress> getFileSectors (int fileNo)

View File

@ -37,7 +37,8 @@ abstract class CatalogEntry implements AppleFileSource
blocks.add (disk.getDiskAddress (i));
}
boolean contains (DiskAddress da)
@Override
public boolean contains (DiskAddress da)
{
for (DiskAddress sector : blocks)
if (sector.compareTo (da) == 0)

View File

@ -48,6 +48,15 @@ class PascalCodeObject implements AppleFileSource
return blocks;
}
@Override
public boolean contains (DiskAddress da)
{
for (DiskAddress sector : blocks)
if (sector.compareTo (da) == 0)
return true;
return false;
}
@Override
public String getUniqueName ()
{

View File

@ -48,4 +48,13 @@ abstract class CatalogEntry implements AppleFileSource
{
return parentDisk;
}
@Override
public boolean contains (DiskAddress da)
{
for (DiskAddress sector : dataBlocks)
if (sector.compareTo (da) == 0)
return true;
return false;
}
}

View File

@ -234,14 +234,14 @@ public class ProdosDisk extends AbstractFormattedDisk
return super.getFormattedSector (da);
}
@Override
public String getSectorFilename (DiskAddress da)
{
for (AppleFileSource fe : fileEntries)
if (((FileEntry) fe).contains (da))
return ((FileEntry) fe).getUniqueName ();
return null;
}
// @Override
// public String getSectorFilename (DiskAddress da)
// {
// for (AppleFileSource fe : fileEntries)
// if (((FileEntry) fe).contains (da))
// return ((FileEntry) fe).getUniqueName ();
// return null;
// }
@Override
public List<DiskAddress> getFileSectors (int fileNo)