Java でいくつかのコンパレーターを実装する必要があります。
私は多くの既知のクラス、、、、... 、A1
を持っています。これらはすべてクラスを拡張します。私がしたいのは、次のようなGuava に基づくコンパレータークラスです。A2
A3
An
A
Ordering
Ordering<A> sorterType1 = new Ordering<A>() {
// Here, provide a Set or something similar that keeps in memory
// the class types and the associated priority.
@Override
public int compare(A left, A right) {
// return -1 if class of left has an higher priority wrt class of right;
// return 0 if class of left has the same priority wrt class of right;
// return 1, otherwise.
}
多くの異なるコンパレーターを開発する必要があるため、各コンパレーターごとに異なるいくつかの優先度があるため、クラス型内に優先度を設定したくありません。私が見逃しているのは、コメントのある部分です。
コメント付きの部分の最も効果的かつ効率的な実装は何ですか?