adding new instanceof pattern

This commit is contained in:
Denis Molony 2021-09-28 19:17:10 +10:00
parent fb748df4ae
commit 6dfc72b2d2
6 changed files with 31 additions and 36 deletions

View File

@ -49,8 +49,8 @@ public class DefaultAppleFileSource implements AppleFileSource
{
this (title, file, owner);
this.blocks = blocks;
if (file instanceof DefaultDataSource)
((DefaultDataSource) file).buffer = owner.getDisk ().readBlocks (blocks);
if (file instanceof DefaultDataSource dds)
dds.buffer = owner.getDisk ().readBlocks (blocks);
}
// ---------------------------------------------------------------------------------//
@ -58,8 +58,8 @@ public class DefaultAppleFileSource implements AppleFileSource
// ---------------------------------------------------------------------------------//
{
this.blocks = blocks;
if (file instanceof DefaultDataSource)
((DefaultDataSource) file).buffer = owner.getDisk ().readBlocks (blocks);
if (file instanceof DefaultDataSource dds)
dds.buffer = owner.getDisk ().readBlocks (blocks);
}
// ---------------------------------------------------------------------------------//

View File

@ -158,9 +158,9 @@ class AppleDiskTab extends AbstractTab
// check for multi-volume disk (only search the current branch)
FormattedDisk fd = ((AppleFileSource) rootNode.getUserObject ()).getFormattedDisk ();
if (fd instanceof HybridDisk)
if (fd instanceof HybridDisk hd)
{
int volume = ((HybridDisk) fd).getCurrentDiskNo ();
int volume = hd.getCurrentDiskNo ();
rootNode = (DefaultMutableTreeNode) rootNode.getChildAt (volume);
}
@ -169,8 +169,8 @@ class AppleDiskTab extends AbstractTab
{
DefaultMutableTreeNode node = (DefaultMutableTreeNode) children.nextElement ();
Object userObject = node.getUserObject ();
if (userObject instanceof AppleFileSource
&& nodeName.equals (((AppleFileSource) userObject).getUniqueName ()))
if (userObject instanceof AppleFileSource afs
&& nodeName.equals (afs.getUniqueName ()))
return node;
}
return null;

View File

@ -738,7 +738,7 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL
interleave3Item.setSelected (disk.getDisk ().getInterleave () == 3);
}
boolean isDataDisk = (disk instanceof DataDisk);
boolean isDataDisk = disk instanceof DataDisk;
sector256Item.setEnabled (isDataDisk);
sector512Item.setEnabled (isDataDisk);

View File

@ -364,9 +364,9 @@ public class OutputPanel extends JTabbedPane
removeImage ();
else
{
if (dataSource instanceof HiResImage)
if (dataSource instanceof HiResImage hri)
{
((HiResImage) dataSource).checkPalette ();
hri.checkPalette ();
image = dataSource.getImage ();
if (((HiResImage) dataSource).isAnimation ())
{

View File

@ -202,11 +202,6 @@ public final class Utility
public static int signedShort (byte[] buffer, int ptr)
// ---------------------------------------------------------------------------------//
{
// if (ptr >= buffer.length)
// {
// System.out.println ("Index out of range (signed short): " + ptr);
// return 0;
// }
try
{
return (short) ((buffer[ptr] & 0xFF) | ((buffer[ptr + 1] & 0xFF) << 8));