Top Description Inners Fields Constructors Methods
org.jparsec

pack-priv final Class Operators

extends Object
Class Inheritance
Imports
java.util.ArrayList, .Arrays, .Collection, .Comparator, .HashMap, .Map, org.jparsec.internal.annotations.Private, org.jparsec.internal.util.Lists

Helper class for creating parsers and lexers for operators.
Author
Ben Yu

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
Operators.Suite

A suite is a list of overlapping operators, where some operators are prefixes of other operators.

private static class
Operators.Suites

A list of suites in the reverse order of the suites.

Field Summary

Modifier and TypeField and Description
private static final Comparator<String>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv static Lexicon
lexicon(final Collection<String> operatorNames)

Gets a Lexicon instance with Tokens#reserved(String) as each operator's value and a lexer that strives to try the shortest operator first.

pack-priv static String[]
sort(String... names)

Sorts names into a new array by putting short string first, unless a shorter string is a prefix of a longer string, in which case, the longer string is before the prefix string.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

LONGER_STRING_FIRSTback to summary
private static final Comparator<String> LONGER_STRING_FIRST

Constructor Detail

Operatorsback to summary
pack-priv Operators()

Method Detail

lexiconback to summary
pack-priv static Lexicon lexicon(final Collection<String> operatorNames)

Gets a Lexicon instance with Tokens#reserved(String) as each operator's value and a lexer that strives to try the shortest operator first.

Safely speaking, we can always start from the longest operator and falls back to shorter ones. Yet shorter operators are more often used than longer ones and the scanning of them is faster. However, scanning shorter operators first has the chance that a "==" is mistakenly scanned as "=" followed by another "=". In order to avoid this, we analyze the prefix relationship and make sure that prefixes are scanned after prefixes.

sortback to summary
pack-priv static String[] sort(String... names)

Sorts names into a new array by putting short string first, unless a shorter string is a prefix of a longer string, in which case, the longer string is before the prefix string.

Annotations
@Private
org.jparsec back to summary

private final Class Operators.Suite

extends Object
Class Inheritance

A suite is a list of overlapping operators, where some operators are prefixes of other operators. If operator foo is a prefix of operator bar, it is listed after bar.

For example ["==", "="]. Empty strings are ignored.

Upon a new string is added, We scan from the end of the list until a string is found to contain it, in which case, the new string is added right after the position.

With the critical requirement that longer strings are added before shorter ones, prefixes are always inserted later than prefixees.

Field Summary

Modifier and TypeField and Description
pack-priv final ArrayList<String>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

listback to summary
pack-priv final ArrayList<String> list

Constructor Detail

Suiteback to summary
pack-priv Suite(String s)

Method Detail

addback to summary
pack-priv boolean add(String v)
org.jparsec back to summary

private final Class Operators.Suites

extends Object
Class Inheritance

A list of suites in the reverse order of the suites. Suite a is defined to be bigger than suite b if the first element of a is longer than that of b.

Field Summary

Modifier and TypeField and Description
private final ArrayList<Operators.Suite>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv void
add(String v)

Scans the list of suites by adding v to the first suite that claims it as a prefix.

pack-priv String[]
toArray()

Collapses the names in each suite by traversing the suites in reverse order, so that smaller suites are collapsed first and generally shorter operators will be placed before longer ones unless it is contained by a longer operator.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

listback to summary
private final ArrayList<Operators.Suite> list

Constructor Detail

Suitesback to summary
private Suites()

Method Detail

addback to summary
pack-priv void add(String v)

Scans the list of suites by adding v to the first suite that claims it as a prefix. If no suite claims it as prefix, it is added as a standalone Suite at the end of the list.

toArrayback to summary
pack-priv String[] toArray()

Collapses the names in each suite by traversing the suites in reverse order, so that smaller suites are collapsed first and generally shorter operators will be placed before longer ones unless it is contained by a longer operator.