我正在将一些Java代码转换为C#。我的部分代码使用Google Guava TreeMultiMap提供了一种机制,使其具有与按键排序的字典等效的机制,并允许重复的空键。
是否有可用的等效项或库来匹配此项,Dictionary似乎不支持重复项,Lookup类似乎不匹配,因为我需要继续添加(Lookup是不可变的)并且我需要添加空值并保持排序。
这就是我正在做的事情:
//declaration section
Multimap<Location, Interconnect> interconnects;
interconnects = TreeMultimap.create(Ordering.natural(),
Interconnect.ORDER_NATURAL_NULLCHECK);
//comparator provider
static final Ordering<Interconnect> ORDER_NATURAL_NULLCHECK = new Ordering<Interconnect>() {
@Override
public int compare(@Nullable final Interconnect arg0,
@Nullable final Interconnect arg1) {
return Ordering.natural().nullsFirst().compare(arg0, arg1);
}
};
//and I can do kind of the following quite happily:
interconnects.put(new Location(), null);
interconnects.put(new Location(), null);
interconnects.put(new Location(), null);
interconnects.put(new Location(), new Interconnect("A"));
interconnects.put(new Location(), new Interconnect("A");