public class Util extends Object
Modifier and Type | Class and Description |
---|---|
static class |
Util.Multimap_LTree<A,B>
Employed for the central map from a "naturally" ordered arithmetic type (like
Rational, BigInteger, etc.) to Tp objects representing time points, allowing their
time-respecting traversal.
|
static class |
Util.Pairwise<T>
Visitor which performs the method
Util.Pairwise.first(Object)
for the first element of an Iterable; afterwards the methodUtil.Pairwise.pairwise(Object,Object)
for each pair of adjacent elements, and at last the method Util.Pairwise.last(Object) . |
static class |
Util.Triplewise<T>
Visitor which performs the method
Util.Triplewise.action(Object,Object,Object)
for triples of adjacent elements of an Iterable. |
Modifier and Type | Method and Description |
---|---|
static boolean |
checkClassParameter(MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> msg,
Part part,
String paramName)
Checks whether the "timless" parameter value really points to a class.
|
static <D> Function3<Comparator<? super D>,D,D,String> |
checkEqual()
Checks whether two time points are equal;
to be plugged into parseTpTops().
|
static <D> Function3<Comparator<? super D>,D,D,String> |
checkIncreasing()
Checks whether two time points are strictly increasing;
to be plugged into parseTpTops().
|
static <D> Function3<Comparator<? super D>,D,D,String> |
checkNotDecreasing()
Checks whether two time points are not decreasing;
to be plugged into parseTpTops().
|
static @Opt Class<?> |
classForName(@Opt String n)
Delivers the class for a given name, iff existing.
|
static BigInteger |
commonDivider(Iterable<Rational> s)
Calculates the greatest common divider of the denominators of the
given Rationals.
|
static Vox |
findVoice(Container ts,
@Opt MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> msg,
boolean generateErrors,
String voiceName)
Searches for the voice with the given name and generates messages if not found.
|
static @Opt Location<XMLDocumentIdentifier> |
firstLocation(Vox v)
Returns the location of the first event in a voice, in source text order.
|
static TpTop |
getLeftTpTop(Tp tp)
Returns the highest TpTop lower or equal to the given Tp.
|
static @Opt String |
getParamText(Event ev,
String trackname,
String separator,
LocationMap<Object,XMLDocumentIdentifier> locs)
Delivers the source text for a gvien parameter and a given event.
|
static Rational |
getRationalValue_lenient(Function<TpTop,Rational> tptop2rat,
Map<Tp,Rational> cache,
Tp tp,
Map<Rational,Tp> rat2tp)
Translates abstract tp values into numeric values and maintains a second,
backward cache.
|
static Rational |
getRationalValue(Function<TpTop,Rational> tptop2rat,
Map<Tp,Rational> cache,
Tp tp)
Central function for translating abstract tp values into numeric values
by calculating an equi-distant sub-division recursively.
|
static Rational |
getRationalValue(Function<TpTop,Rational> tptop2rat,
Map<Tp,Rational> cache,
Tp tp,
Map<Rational,Tp> rat2tp)
Translates abstract tp values into numeric values and maintains a second,
backward cache.
|
static Rational |
getRationalValue(Function<TpTop,Rational> tptop2rat,
Map<Tp,Rational> cache,
Tp tp,
MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> msg,
Map<Rational,Tp> rat2tp)
Translates abstract tp values into numeric values and maintains a second,
backward cache.
|
static Rational |
getRationalValue(Function<TpTop,Rational> tptop2rat,
Map<Tp,Rational> cache,
Tp tp,
Multimap<Rational,Tp> rat2tp)
Translates abstract tp values into numeric values and maintains a second,
backward cache.
|
static Rational |
getTpTopRelativeRational(Function<TpTop,Rational> tptop2rat,
Map<Tp,Rational> cache,
Tp tp)
Returns the distance of the given Tp to the next left TpTop, which is
in many cases its relative position in a measure, or sim.
|
static <E extends Event> |
haveParam(String pname,
Iterable<E> it)
Filter on Events which visits only those which have an (explicit, source level)
value for a given parameter name.
|
static <R,D> D |
highestLowerBound(SortedMap<R,D> map,
R key)
Returns the highest/largest key contained in the map which is lower or equal
to tke given value.
|
static <E extends Event,F> |
keysOnly(Map<E,F> map,
Iterable<E> it)
Filter on Events which visits only those which appear as key in the given map.
|
static @Opt Location<XMLDocumentIdentifier> |
lastLocation(Vox v)
Returns the location of the last event in a voice, in source text order.
|
static void |
memoAdjacency(Iterable<Event> evs,
Map<Event,Event> map,
Event last)
Stores the fact that two events are neighbours/adjacent into the Map.
|
static void |
memoEndTime_ignoring(Iterable<Event> evs,
Set<Event> ignore,
Map<Event,Tp> map,
Tp last)
Stores the start point of one event as the end point of its predecessor,
ignoring certain explicitly mentioned events.
|
static void |
memoEndTime(Iterable<Event> evs,
Map<Event,Tp> map,
Tp last)
Stores the start point of one event as the end point of its predecessor.
|
static boolean |
noUnknownVoices(TimeScape ts,
@Opt MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> msg,
boolean generateErrors,
String... voiceNames)
Checks whether no voice object exists with a name not explicitly given.
|
static void |
parseParamTrack(MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> msg,
Vox v,
String trackname,
String separator,
Translet.Parser<?> parser,
Modifiers react)
Applies a certain
Translet.Parser parser to the given parameter track. |
static <P> Translet.Parser<P> |
parserForName(@Opt String className,
String parsername)
Delivers the parser object for the members of a particular class.
|
static TimeScape |
parseTimeScape(File in,
Modifiers modifiers,
MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> msg)
Calls
parseTimeScape(InputStream,String,Modifiers,MessageReceiver)
with the canonical file name. |
static TimeScape |
parseTimeScape(InputStream in,
String inputFileName,
Modifiers modifiers,
MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> msg)
Applies tscore-raw-layer parser and delivers an tscore umod data model.
|
static TimeScape |
parseTimeScape(Reader in,
String inputFileName,
Modifiers modifiers,
MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> msg)
Applies tscore-raw-layer parser and delivers an tscore umod data model.
|
static <T> void |
parseTpTops(MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> msg,
Modifiers modifiers,
Part part,
Map<TpTop,T> values,
SortedMap<T,TpTop> representatives,
Translet.Parser<T> parser,
@Opt Function3<Comparator<? super T>,T,T,String> check_oneLine,
@Opt Function3<Comparator<? super T>,T,T,String> check_twoLines)
Parse all TpTops into some internal numeric format "T" and store them.
|
static <D,P> Map<String,D> |
partsToScores(TimeScape ts,
String topName,
@Opt String scoreNameTemplate,
MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> msg,
P parameters,
Function4<String,Part,MessageReceiver,P,D> constructorCall)
Translate every "PART" section in a time scape object
into one single score object each.
|
static <A,B> Iterable<B> |
range_respectingDomainOrder(Multimap<A,B> data)
|
static <A,B> Iterable<B> |
range_respectingDomainOrder(SortedMap<A,B> data)
|
static LocationMap<Object,XMLDocumentIdentifier> |
singletonMap(String data,
Location<XMLDocumentIdentifier> sourceLoc)
Constructs a
LocationMap which points from the given String
into the given location. |
(package private) @Opt Part |
thePart(TimeScape ts)
Deliver the only part of the timescape object, if any, otherwise null.
|
static <T> void |
unifyEventTimesByScalarValue(Map<T,Tp> representatives,
Function<Tp,T> tp2t,
Vox vox)
ATTENTION:
Different subdivisions are not unified automatically, e.g.
|
static <T> boolean |
veryFirstEventHasRequiredParameter(MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> msg,
Event firstEv,
Vox v,
Map<Event,T> map,
String pname)
Checks whether the very first event of a particular voice has a necessary parameter.
|
static Iterable<Event> |
voiceEvents(Vox v,
Iterable<? extends Tp> tps)
|
static <E extends Event> |
voiceFilter(Vox v,
Iterable<E> it)
An
Iterable.FilterIterable over any Event Iterable which visits
only those events of a given Vox . |
static boolean |
voicesExist(TimeScape ts,
@Opt MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> msg,
boolean generateErrors,
String... voiceNames)
Checks whether for each given voice name a voice object exists.
|
static void |
warnUnusedParams(MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> msg,
Vox v,
Set<String> analysed,
boolean errorNotWarn)
Emits a warning or an error if the source text of a voice contains parameters
which are not analysed.
|
@Opt @Opt Part thePart(TimeScape ts)
public static <D,P> Map<String,D> partsToScores(TimeScape ts, String topName, @Opt @Opt String scoreNameTemplate, MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> msg, @Opt P parameters, Function4<String,Part,MessageReceiver,P,D> constructorCall)
String.format(String,Object...)
)
to create the name from this explicit name and the name of the part in the score.
Assumes that the names for the parts in one score are used unambiguously.D
- the type of the created score objectp
- the type of the additional optional creation parametersts
- the time scape object (=tscore input file parse result)topName
- the name to use if only only PART section is present in the sourcescoreNameTemplate
- the string format template to combine "topName" and
the name, the part is given in the score, if more than one part is contained.msg
- passed to the constructorparameters
- passed to the constructorconstructorCall
- must be a constructor with the arguments
(1) name of the score to construct, (2) tscore part object to convert
(3) message receiver (4) further optional construction parameters of an
arbitrary type "P".public static TimeScape parseTimeScape(File in, Modifiers modifiers, MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> msg)
parseTimeScape(InputStream,String,Modifiers,MessageReceiver)
with the canonical file name.public static TimeScape parseTimeScape(InputStream in, String inputFileName, Modifiers modifiers, MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> msg)
in
- the input to be parsed.inputFileName
- to be used in error messagesmodifiers
- configuration data, partly relevant for raw parsing processmsg
- receiver of logging and error messagespublic static TimeScape parseTimeScape(Reader in, String inputFileName, Modifiers modifiers, MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> msg)
in
- the input to be parsed.inputFileName
- to be used in error messagesmodifiers
- configuration data, partly relevant for raw parsing processmsg
- receiver of logging and error messagespublic static final <D> Function3<Comparator<? super D>,D,D,String> checkIncreasing()
public static final <D> Function3<Comparator<? super D>,D,D,String> checkNotDecreasing()
public static final <D> Function3<Comparator<? super D>,D,D,String> checkEqual()
public static LocationMap<Object,XMLDocumentIdentifier> singletonMap(String data, Location<XMLDocumentIdentifier> sourceLoc)
LocationMap
which points from the given String
into the given location.
Auxiliary function, needed e.g. when some input to a parser/lexer is
locally synthesized.public static <T> void parseTpTops(MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> msg, Modifiers modifiers, Part part, Map<TpTop,T> values, SortedMap<T,TpTop> representatives, Translet.Parser<T> parser, @Opt @Opt Function3<Comparator<? super T>,T,T,String> check_oneLine, @Opt @Opt Function3<Comparator<? super T>,T,T,String> check_twoLines)
Location
but the first.
(Different to parameter values, which are stored into lists of tupels!)
Therefore the diagnosis/location info looks slightly different (even wrong)
in the rare case that tp-top source text is in more than one line, as in
T 1h 1h 59'59.0 0' 2'
values
- output parameter where the T-values will be stored.representatives
- backward map, stores one(1) TpTop for every computed T-value.parser
- Parser, generates possibly complicated error messagescheck_oneLine
- check for two top values following in ONE time line.
Typically a test for "strictly later".
Iff ==null, no such check is performed.check_twoLines
- check for last TpTop in one line and the first in the
next line.
Typically a test for "later or equal".
Iff ==null, no such check is performed.
FIXME use "PreImageMap values"instead of "values+representatives" ?!?!public static Rational getRationalValue(Function<TpTop,Rational> tptop2rat, Map<Tp,Rational> cache, Tp tp, MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> msg, Map<Rational,Tp> rat2tp)
Map
, since different Tps can yield only different Rational
values.
If this is violated, an error message is sent.
As alternatives see getRationalValue(Function,Map,Tp)
,
getRationalValue(Function,Map,Tp,Map)
.
and getRationalValue(Function,Map,Tp,Multimap)
.public static Rational getRationalValue(Function<TpTop,Rational> tptop2rat, Map<Tp,Rational> cache, Tp tp, Map<Rational,Tp> rat2tp)
Map
, since different Tps can yield only different Rational
values.
If this is violated, an IllegalArgumentException
is thrown.
As alternatives see getRationalValue(Function,Map,Tp,MessageReceiver,Map)
,
getRationalValue(Function,Map,Tp)
and
getRationalValue(Function,Map,Tp,Multimap)
.public static Rational getRationalValue_lenient(Function<TpTop,Rational> tptop2rat, Map<Tp,Rational> cache, Tp tp, Map<Rational,Tp> rat2tp)
Map
. If different Tps yield the same Rational
,
only the first is stored in the cache.
As alternatives see getRationalValue(Function,Map,Tp,MessageReceiver,Map)
,
getRationalValue(Function,Map,Tp)
and
getRationalValue(Function,Map,Tp,Multimap)
.public static Rational getRationalValue(Function<TpTop,Rational> tptop2rat, Map<Tp,Rational> cache, Tp tp, Multimap<Rational,Tp> rat2tp)
Multimap
, since different Tps can yield the same Rational
value.
As alternatives see getRationalValue(Function,Map,Tp,MessageReceiver,Map)
,
getRationalValue(Function,Map,Tp)
and
getRationalValue(Function,Map,Tp,Map)
.public static Rational getRationalValue(Function<TpTop,Rational> tptop2rat, Map<Tp,Rational> cache, Tp tp)
Map
(all Tp correspond to different Rational
values)
or a Multimap
(different Tps can yield the same Rational
value.)
As alternatives see getRationalValue(Function,Map,Tp,MessageReceiver,Map)
,
getRationalValue(Function,Map,Tp,Multimap)
and
getRationalValue(Function,Map,Tp,Map)
.tptop2rat
- translation for tptop objectscache
- tp
- the Tp to to translatepublic static TpTop getLeftTpTop(Tp tp)
public static Rational getTpTopRelativeRational(Function<TpTop,Rational> tptop2rat, Map<Tp,Rational> cache, Tp tp)
public static BigInteger commonDivider(Iterable<Rational> s)
public static <T> void unifyEventTimesByScalarValue(Map<T,Tp> representatives, Function<Tp,T> tp2t, Vox vox)
T 7 8 VOX a b c d e f VOX w x y zDivision by 4 in VOX a and by 2 in VOX w are not unified by default: the
Tp
s of Event d and y are different (while having possibly the same Rational
value, or sim.)
The following function must be applied to all vox-es to patch the "when" fields and
all access maps, if only one Tp object may represent a certain "T" value.@Opt public static @Opt String getParamText(Event ev, String trackname, String separator, LocationMap<Object,XMLDocumentIdentifier> locs)
public static void parseParamTrack(MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> msg, Vox v, String trackname, String separator, Translet.Parser<?> parser, Modifiers react)
Translet.Parser
parser to the given parameter track.
The parser must contain the store operations required to deliver the
results.msg
- The message receiver for error messages.v
- the voice to parsetrackname
- non-empty string.separator
- string for concatenating parameter values from several lines
in the source fileparser
- given as an expressionpublic static boolean checkClassParameter(MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> msg, Part part, String paramName)
@Opt public static @Opt Class<?> classForName(@Opt @Opt String n)
n
- the class name (completely qualified), may be null@Opt public static <P> Translet.Parser<P> parserForName(@Opt @Opt String className, String parsername)
className
- the class name (completely qualified), may be nullparserName
- the name of the static method which delivers the parser.
(in case of music: "memberParser")public static <A,B> Iterable<B> range_respectingDomainOrder(Multimap<A,B> data)
Iterator
over the range of a Multimap
which
visits the range values in the order of the corresponding domain values.
Assumes that domain HAS an order, and that this is realized technically
by using a SortedMap
as the "left" map when constructing the Multimap,
eg. by using Util.Multimap_LTree
.
This is currently NOT CHECKED. FIXMEpublic static <A,B> Iterable<B> range_respectingDomainOrder(SortedMap<A,B> data)
public static <E extends Event> Iterable<E> voiceFilter(Vox v, Iterable<E> it)
Iterable.FilterIterable
over any Event Iterable which visits
only those events of a given Vox
.public static <E extends Event> Iterable<E> haveParam(String pname, Iterable<E> it)
public static <E extends Event,F> Iterable<E> keysOnly(Map<E,F> map, Iterable<E> it)
public static void memoAdjacency(Iterable<Event> evs, Map<Event,Event> map, Event last)
public static void memoEndTime(Iterable<Event> evs, Map<Event,Tp> map, Tp last)
last
- to be stored as the end point of the very last eventpublic static void memoEndTime_ignoring(Iterable<Event> evs, Set<Event> ignore, Map<Event,Tp> map, Tp last)
last
- to be stored as the end point of the very last eventpublic static Vox findVoice(Container ts, @Opt @Opt MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> msg, boolean generateErrors, String voiceName)
container
- either TimeScape or Part. ATTENTION, in TimeScape only timeless
(meta-)data is contained. The "real" voices with events are only in Parts.generateErrors
- whether to generate error messages, not only warningspublic static boolean voicesExist(TimeScape ts, @Opt @Opt MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> msg, boolean generateErrors, String... voiceNames)
generateErrors
- whether to generate error messages, not only warningspublic static boolean noUnknownVoices(TimeScape ts, @Opt @Opt MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> msg, boolean generateErrors, String... voiceNames)
generateErrors
- whether to generate error messages, not only warnings@Opt public static @Opt Location<XMLDocumentIdentifier> firstLocation(Vox v)
@Opt public static @Opt Location<XMLDocumentIdentifier> lastLocation(Vox v)
public static void warnUnusedParams(MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> msg, Vox v, Set<String> analysed, boolean errorNotWarn)
msg
- drain of messagesv
- the voiceanalysed
- set of parameter names which have been considerederrorNotWarn
- whether to produce an error message, not just a warningpublic static <T> boolean veryFirstEventHasRequiredParameter(MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> msg, Event firstEv, Vox v, Map<Event,T> map, String pname)
msg
- the message receiver for the error casefirstEv
- the event to checkv
- the voice, for error message onlymap
- the parameter values, by events.pname
- the name of the parameter, for error message only.