Skip to content

Commit

Permalink
Sort entries in SelectorValue.
Browse files Browse the repository at this point in the history
This makes query output independent of the insertion order of the dictionary.

--
MOS_MIGRATED_REVID=108061190
  • Loading branch information
hanwen authored and lberki committed Nov 18, 2015
1 parent e6180d3 commit d783596
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.google.common.collect.Iterables;

import java.util.Map;
import java.util.TreeMap;

/**
* The value passed to a select({...}) statement, e.g.:
Expand All @@ -30,14 +31,15 @@
* </pre>
*/
public final class SelectorValue {
// TODO(build-team): Selectors are currently split between .packages and .syntax . They should
// TODO(bazel-team): Selectors are currently split between .packages and .syntax . They should
// really all be in .packages, but then we'd need to figure out a way how to extend binary
// operators, which is a non-trivial problem.
private final Map<?, ?> dictionary;
private final Class<?> type;

public SelectorValue(Map<?, ?> dictionary) {
this.dictionary = dictionary;
// Put the dict through a sorting to avoid depending on insertion order.
this.dictionary = new TreeMap<>(dictionary);
this.type = dictionary.isEmpty() ? null : Iterables.get(dictionary.values(), 0).getClass();
}

Expand Down

0 comments on commit d783596

Please sign in to comment.