|
Lines 599-605
Link Here
|
| 599 |
.getParameterizedCommand(), trigger); |
599 |
.getParameterizedCommand(), trigger); |
| 600 |
|
600 |
|
| 601 |
} else if (match instanceof Collection) { |
601 |
} else if (match instanceof Collection) { |
| 602 |
bindings.addAll(resolveConflicts((Collection) match)); |
602 |
bindings.addAll((Collection)match); |
| 603 |
bindingsByTrigger.put(trigger, bindings); |
603 |
bindingsByTrigger.put(trigger, bindings); |
| 604 |
|
604 |
|
| 605 |
final Iterator matchItr = bindings.iterator(); |
605 |
final Iterator matchItr = bindings.iterator(); |
|
Lines 1927-2004
Link Here
|
| 1927 |
|
1927 |
|
| 1928 |
/** |
1928 |
/** |
| 1929 |
* <p> |
1929 |
* <p> |
| 1930 |
* Attempts to resolve the conflicts for the given bindings -- irrespective |
|
|
| 1931 |
* of the currently active contexts. This means that type and scheme will be |
| 1932 |
* considered. |
| 1933 |
* </p> |
| 1934 |
* <p> |
| 1935 |
* This method completes in <code>O(n)</code>, where <code>n</code> is |
| 1936 |
* the number of bindings. |
| 1937 |
* </p> |
| 1938 |
* |
| 1939 |
* @param bindings |
| 1940 |
* The bindings which all match the same trigger sequence; must |
| 1941 |
* not be <code>null</code>, and should contain at least two |
| 1942 |
* items. This collection should only contain instances of |
| 1943 |
* <code>Binding</code> (i.e., no <code>null</code> values). |
| 1944 |
* @return The collection of bindings which match the current scheme. |
| 1945 |
*/ |
| 1946 |
private final Collection resolveConflicts(final Collection bindings) { |
| 1947 |
final Collection matches = new ArrayList(); |
| 1948 |
final Iterator bindingItr = bindings.iterator(); |
| 1949 |
Binding bestMatch = (Binding) bindingItr.next(); |
| 1950 |
matches.add(bestMatch); |
| 1951 |
|
| 1952 |
/* |
| 1953 |
* Iterate over each binding and compares it with the best match. If a |
| 1954 |
* better match is found, then replace the best match and clear the |
| 1955 |
* collection. If the current binding is equivalent, then simply add it |
| 1956 |
* to the collection of matches. If the current binding is worse, then |
| 1957 |
* do nothing. |
| 1958 |
*/ |
| 1959 |
while (bindingItr.hasNext()) { |
| 1960 |
final Binding current = (Binding) bindingItr.next(); |
| 1961 |
|
| 1962 |
/* |
| 1963 |
* SCHEME: Test whether the current is in a child scheme. Bindings |
| 1964 |
* defined in a child scheme will take priority over bindings |
| 1965 |
* defined in a parent scheme -- assuming that consulting their |
| 1966 |
* contexts led to a conflict. |
| 1967 |
*/ |
| 1968 |
final String currentSchemeId = current.getSchemeId(); |
| 1969 |
final String bestSchemeId = bestMatch.getSchemeId(); |
| 1970 |
final int compareTo = compareSchemes(bestSchemeId, currentSchemeId); |
| 1971 |
if (compareTo > 0) { |
| 1972 |
bestMatch = current; |
| 1973 |
matches.clear(); |
| 1974 |
matches.add(current); |
| 1975 |
} |
| 1976 |
if (compareTo != 0) { |
| 1977 |
continue; |
| 1978 |
} |
| 1979 |
|
| 1980 |
/* |
| 1981 |
* TYPE: Test for type superiority. |
| 1982 |
*/ |
| 1983 |
if (current.getType() > bestMatch.getType()) { |
| 1984 |
bestMatch = current; |
| 1985 |
matches.clear(); |
| 1986 |
matches.add(current); |
| 1987 |
continue; |
| 1988 |
} else if (bestMatch.getType() > current.getType()) { |
| 1989 |
continue; |
| 1990 |
} |
| 1991 |
|
| 1992 |
// The bindings are equivalent. |
| 1993 |
matches.add(current); |
| 1994 |
} |
| 1995 |
|
| 1996 |
// Return all of the matches. |
| 1997 |
return matches; |
| 1998 |
} |
| 1999 |
|
| 2000 |
/** |
| 2001 |
* <p> |
| 2002 |
* Attempts to resolve the conflicts for the given bindings. |
1930 |
* Attempts to resolve the conflicts for the given bindings. |
| 2003 |
* </p> |
1931 |
* </p> |
| 2004 |
* <p> |
1932 |
* <p> |