Class LookaheadTokenMultiplexer<K,D,T,L>
- Type Parameters:
K
- the type of keysD
- the type of source document identifiersT
- the type of token typesL
- the type of lookahead data
- All Implemented Interfaces:
LookaheadTokenSource<D,
,T, L> Closeable
,AutoCloseable
,Supplier<Token<D,
T>>
Lookahead data is transferred automatically between sources upon switching.
-
Constructor Summary
ConstructorsConstructorDescriptionLookaheadTokenMultiplexer
(K key, LookaheadTokenSource<D, T, L> channel) Creates a new instance with one entry. -
Method Summary
Modifier and TypeMethodDescriptionget()
Returns the currently selected channel.Returns the key for the currently selected channel.Adds an entry to this multiplexer.Clear the internal lookahead buffer and return its contents.void
Selects a channel by key.void
takeOverLookahead
(L lookaheadData) Fill the internal lookahead buffer with data.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface eu.bandm.tools.lexic.LookaheadTokenSource
close, forgetLookahead, removeTypes, removeTypes
-
Constructor Details
-
LookaheadTokenMultiplexer
Creates a new instance with one entry.The given channel is also initially selected.
- Parameters:
key
- the key for selecting the given channelchannel
- the channel associated with the key
-
-
Method Details
-
put
Adds an entry to this multiplexer.Keys cannot be reused; existing entries are immutable.
The currently selected channel is not changed.
- Parameters:
key
- the key for selecting the given channelchannel
- the channel associated with the key- Returns:
this
for convenient chained method calls- Throws:
NullPointerException
- ifkey
orchannel
is nullIllegalArgumentException
- ifkey
is already in use
-
getCurrentKey
Returns the key for the currently selected channel.- Returns:
- the key for the currently selected channel
-
getCurrentChannel
Returns the currently selected channel.- Returns:
- the currently selected channel
-
select
Selects a channel by key.If the newly selected channel is not the same as the previously selected one,
LookaheadTokenSource.transferLookahead(eu.bandm.tools.lexic.LookaheadTokenSource<?, ?, ? extends L>, eu.bandm.tools.lexic.LookaheadTokenSource<?, ?, ? super L>)
is called.- Parameters:
key
- the key for the channel to select- Throws:
IllegalArgumentException
- if there is no entry for the given key- See Also:
-
get
This method delegates to the currently selected channel.
-
relinquishLookahead
Clear the internal lookahead buffer and return its contents.This method delegates to the currently selected channel.
- Specified by:
relinquishLookahead
in interfaceLookaheadTokenSource<K,
D, T> - Returns:
- the former contents of the internal lookahead buffer
-
takeOverLookahead
Fill the internal lookahead buffer with data.The buffer must be empty before this method is invoked. After return, the given data will be consumed from the buffer before the usual input is considered.
This method delegates to the currently selected channel.
- Specified by:
takeOverLookahead
in interfaceLookaheadTokenSource<K,
D, T> - Parameters:
lookaheadData
- the lookahead data to fill in
-