View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.eclipse.aether.internal.impl;
20  
21  final class PrioritizedComponent<T> implements Comparable<PrioritizedComponent<?>> {
22  
23      private final T component;
24  
25      private final Class<?> type;
26  
27      private final float priority;
28  
29      private final int index;
30  
31      PrioritizedComponent(T component, Class<?> type, float priority, int index) {
32          this.component = component;
33          this.type = type;
34          this.priority = priority;
35          this.index = index;
36      }
37  
38      public T getComponent() {
39          return component;
40      }
41  
42      public Class<?> getType() {
43          return type;
44      }
45  
46      public float getPriority() {
47          return priority;
48      }
49  
50      public boolean isDisabled() {
51          return Float.isNaN(priority);
52      }
53  
54      public int compareTo(PrioritizedComponent<?> o) {
55          int rel = (isDisabled() ? 1 : 0) - (o.isDisabled() ? 1 : 0);
56          if (rel == 0) {
57              rel = Float.compare(o.priority, priority);
58              if (rel == 0) {
59                  rel = index - o.index;
60              }
61          }
62          return rel;
63      }
64  
65      @Override
66      public String toString() {
67          return priority + " (#" + index + "): " + component;
68      }
69  }