Package ru.ispras.microtesk.mmu.basis
Class AddressView<A>
- java.lang.Object
-
- ru.ispras.microtesk.mmu.basis.AddressView<A>
-
- Type Parameters:
A
- address type.
public final class AddressView<A> extends java.lang.Object
AddressView
implements an address view, i.e. a set of methods for composing/decomposing address into fields.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description A
getAddress(A tag, A index, A offset)
Returns the address to the given tag, index and offset.A
getAddress(java.util.List<A> fields)
Returns the address for the given fields.A
getField(A address, int i)
Returns the field of the address.java.util.List<A>
getFields(A address)
Returns the fields of the address.A
getIndex(A address)
Returns the index of the given address (fields[1]
).A
getOffset(A address)
Returns the offset of the given address (fields[2]
).A
getTag(A address)
Returns the tag of the given address (fields[0]
).
-
-
-
Constructor Detail
-
AddressView
public AddressView(Function<A,java.util.List<A>> split, Function<java.util.List<A>,A> merge)
Constructs an address view.- Parameters:
split
- the address split functor (it splits an address into the fields).merge
- the address merge functor (it merges fields to produce the address).- Throws:
java.lang.IllegalArgumentException
- ifsplit
ormerge
is null.
-
-
Method Detail
-
getFields
public java.util.List<A> getFields(A address)
Returns the fields of the address.- Parameters:
address
- the address.- Returns:
- the list of fields.
- Throws:
java.lang.IllegalArgumentException
- ifaddress
is null.
-
getField
public A getField(A address, int i)
Returns the field of the address.- Parameters:
address
- the address.i
- the field index.- Returns:
- the list of fields.
- Throws:
java.lang.IllegalArgumentException
- ifaddress
is null.java.lang.IndexOutOfBoundsException
- ifi
is out of bounds.
-
getAddress
public A getAddress(java.util.List<A> fields)
Returns the address for the given fields.- Parameters:
fields
- the fields.- Returns:
- the address.
- Throws:
java.lang.IllegalArgumentException
- iffields
is null.
-
getAddress
public A getAddress(A tag, A index, A offset)
Returns the address to the given tag, index and offset.- Parameters:
tag
- the tag.index
- the index.offset
- the offset.- Returns:
- the address.
- Throws:
java.lang.IllegalArgumentException
- ifindex
,tag
oroffset
is null.
-
getTag
public A getTag(A address)
Returns the tag of the given address (fields[0]
).- Parameters:
address
- the address.- Returns:
- the tag.
- Throws:
java.lang.IllegalArgumentException
- ifaddress
is null.
-
getIndex
public A getIndex(A address)
Returns the index of the given address (fields[1]
).- Parameters:
address
- the address.- Returns:
- the index.
- Throws:
java.lang.IllegalArgumentException
- ifaddress
is null.
-
-