1   package org.apache.commons.graph.model;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import static java.lang.String.format;
23  
24  import org.apache.commons.graph.LabeledVertex;
25  
26  public class BaseLabeledVertex
27      implements LabeledVertex
28  {
29  
30      private final String label;
31  
32      public BaseLabeledVertex( String label )
33      {
34          this.label = label;
35      }
36  
37      /**
38       * {@inheritDoc}
39       */
40      public final String getLabel()
41      {
42          return label;
43      }
44  
45      /**
46       * {@inheritDoc}
47       */
48      @Override
49      public int hashCode()
50      {
51          final int prime = 31;
52          int result = 1;
53          result = prime * result + ( ( label == null ) ? 0 : label.hashCode() );
54          return result;
55      }
56  
57      /**
58       * {@inheritDoc}
59       */
60      @Override
61      public boolean equals( Object obj )
62      {
63          if ( this == obj )
64          {
65              return true;
66          }
67  
68          if ( obj == null )
69          {
70              return false;
71          }
72  
73          if ( getClass() != obj.getClass() )
74          {
75              return false;
76          }
77  
78          BaseLabeledVertex other = (BaseLabeledVertex) obj;
79          if ( label == null )
80          {
81              if ( other.getLabel() != null )
82              {
83                  return false;
84              }
85          }
86          else if ( !label.equals( other.getLabel() ) )
87          {
88              return false;
89          }
90  
91          return true;
92      }
93  
94      /**
95       * {@inheritDoc}
96       */
97      @Override
98      public String toString()
99      {
100         return format( "{ %s }", label );
101     }
102 
103 }