Class AbstractMemoryContext<CellType>
java.lang.Object
net.emustudio.emulib.plugin.memory.AbstractMemoryContext<CellType>
- Type Parameters:
CellType- the memory cell type
- All Implemented Interfaces:
Context, MemoryContext<CellType>
@ThreadSafe
public abstract class AbstractMemoryContext<CellType>
extends Object
implements MemoryContext<CellType>
This class implements some fundamental functionality of MemoryContext
interface, that can be useful in the programming of the own memory context.
-
Nested Class Summary
Nested classes/interfaces inherited from interface MemoryContext
MemoryContext.MemoryListener -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Set<MemoryContext.MemoryListener> List of all memory listeners. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructs new abstract memory context. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a listener onto listeners listbooleanDetermine if notifications of memory changes are globally enabled or disabled.voidnotifyMemoryContentChanged(int location) Notify all listeners that memory content has changed at given positions.voidnotifyMemoryContentChanged(int fromLocation, int toLocation) Notify all listeners that memory content has changed at given positions.voidNotify listeners that memory size has changed.voidRemoves the listener from listeners listvoidsetMemoryNotificationsEnabled(boolean enabled) Enable/disable notifications of memory changes globally.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface MemoryContext
clear, getCellTypeClass, getSize, peek, read, read, write, write, write
-
Field Details
-
listeners
List of all memory listeners. The listeners are objects implementing the IMemoryListener interface. Methods within the listeners are called on some events that happen inside memory (e.g. value change).
-
-
Constructor Details
-
AbstractMemoryContext
protected AbstractMemoryContext()Constructs new abstract memory context.
-
-
Method Details
-
areMemoryNotificationsEnabled
public boolean areMemoryNotificationsEnabled()Description copied from interface:MemoryContextDetermine if notifications of memory changes are globally enabled or disabled.- Specified by:
areMemoryNotificationsEnabledin interfaceMemoryContext<CellType>- Returns:
- true if notifications are enabled, false if disabled.
-
setMemoryNotificationsEnabled
public void setMemoryNotificationsEnabled(boolean enabled) Description copied from interface:MemoryContextEnable/disable notifications of memory changes globally.Enabled by default. Usually it is disabled by CPU when in a "running" state.
- Specified by:
setMemoryNotificationsEnabledin interfaceMemoryContext<CellType>- Parameters:
enabled- - true if enabled, false if disabled.
-
addMemoryListener
Adds a listener onto listeners list- Specified by:
addMemoryListenerin interfaceMemoryContext<CellType>- Parameters:
listener- listener object
-
removeMemoryListener
Removes the listener from listeners list- Specified by:
removeMemoryListenerin interfaceMemoryContext<CellType>- Parameters:
listener- listener object
-
notifyMemoryContentChanged
public void notifyMemoryContentChanged(int fromLocation, int toLocation) Notify all listeners that memory content has changed at given positions.This method should be called by a memory context, whenever a
write()is invoked.- Parameters:
fromLocation- from locationtoLocation- to location
-
notifyMemoryContentChanged
public void notifyMemoryContentChanged(int location) Notify all listeners that memory content has changed at given positions.This method should be called by a memory context, whenever a
write()is invoked.- Parameters:
location- memory location
-
notifyMemorySizeChanged
public void notifyMemorySizeChanged()Notify listeners that memory size has changed.
-