View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
4   //  ------------------------------------------------------------------------
5   //  All rights reserved. This program and the accompanying materials
6   //  are made available under the terms of the Eclipse Public License v1.0
7   //  and Apache License v2.0 which accompanies this distribution.
8   //
9   //      The Eclipse Public License is available at
10  //      http://www.eclipse.org/legal/epl-v10.html
11  //
12  //      The Apache License v2.0 is available at
13  //      http://www.opensource.org/licenses/apache2.0.php
14  //
15  //  You may elect to redistribute this code under either of these licenses.
16  //  ========================================================================
17  //
18  
19  package org.eclipse.jetty.start.graph;
20  
21  /**
22   * Represents a selection criteria.
23   * <p>
24   * Each <code>Selection</code> can be used [0..n] times in the graph. The <code>Selection</code> must contain a unique
25   * 'criteria' description that how selection was determined.
26   */
27  public class Selection
28  {
29      private final boolean explicit;
30      private final String criteria;
31  
32      public Selection(String criteria)
33      {
34          this(criteria,true);
35      }
36  
37      /**
38       * The Selection criteria
39       * 
40       * @param criteria
41       *            the selection criteria
42       * @param explicit
43       *            true if explicitly selected, false if transitively selected.
44       */
45      public Selection(String criteria, boolean explicit)
46      {
47          this.criteria = criteria;
48          this.explicit = explicit;
49      }
50  
51      public Selection asTransitive()
52      {
53          if (this.explicit)
54          {
55              return new Selection(criteria,false);
56          }
57          return this;
58      }
59  
60      @Override
61      public boolean equals(Object obj)
62      {
63          if (this == obj)
64          {
65              return true;
66          }
67          if (obj == null)
68          {
69              return false;
70          }
71          if (getClass() != obj.getClass())
72          {
73              return false;
74          }
75          Selection other = (Selection)obj;
76          if (explicit != other.explicit)
77          {
78              return false;
79          }
80          if (criteria == null)
81          {
82              if (other.criteria != null)
83              {
84                  return false;
85              }
86          }
87          else if (!criteria.equals(other.criteria))
88          {
89              return false;
90          }
91          return true;
92      }
93  
94      /**
95       * Get the criteria for this selection
96       * @return the criteria
97       */
98      public String getCriteria()
99      {
100         return criteria;
101     }
102 
103     @Override
104     public int hashCode()
105     {
106         final int prime = 31;
107         int result = 1;
108         result = (prime * result) + (explicit ? 1231 : 1237);
109         result = (prime * result) + ((criteria == null) ? 0 : criteria.hashCode());
110         return result;
111     }
112 
113     public boolean isExplicit()
114     {
115         return explicit;
116     }
117 
118     @Override
119     public String toString()
120     {
121         StringBuilder str = new StringBuilder();
122         if (!explicit)
123         {
124             str.append("<transitive from> ");
125         }
126         str.append(criteria);
127         return str.toString();
128     }
129 }