View Javadoc

1   package org.apache.maven.repository;
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 java.util.ArrayList;
23  import java.util.List;
24  
25  /**
26   * MetadataGraph node - as it's a directed graph - holds adjacency lists for incident and exident nodes
27   *
28   * @author Oleg Gusakov
29   * @version $Id: MetadataGraphNode.java 958295 2010-06-26 23:16:18Z hboutemy $
30   *
31   */
32  public class MetadataGraphNode
33  {
34      /** node payload */
35      MavenArtifactMetadata metadata;
36  
37      /** nodes, incident to this (depend on me) */
38      List<MetadataGraphNode> inNodes;
39  
40      /** nodes, exident to this (I depend on) */
41      List<MetadataGraphNode> exNodes;
42  
43      public MetadataGraphNode()
44      {
45          inNodes = new ArrayList<MetadataGraphNode>(4);
46          exNodes = new ArrayList<MetadataGraphNode>(8);
47      }
48  
49      public MetadataGraphNode( MavenArtifactMetadata metadata )
50      {
51          this();
52          this.metadata = metadata;
53      }
54  
55      public MetadataGraphNode addIncident( MetadataGraphNode node )
56      {
57          inNodes.add( node );
58          return this;
59      }
60  
61      public MetadataGraphNode addExident( MetadataGraphNode node )
62      {
63          exNodes.add( node );
64          return this;
65      }
66  
67      @Override
68      public boolean equals( Object obj )
69      {
70          if ( obj == null )
71          {
72              return false;
73          }
74  
75          if ( MetadataGraphNode.class.isAssignableFrom( obj.getClass() ) )
76          {
77              MetadataGraphNode node2 = (MetadataGraphNode) obj;
78  
79              if ( node2.metadata == null )
80              {
81                  return metadata == null;
82              }
83  
84              return metadata == null ? false : metadata.toString().equals( node2.metadata.toString() );
85          }
86          else
87          {
88              return super.equals( obj );
89          }
90      }
91  
92      @Override
93      public int hashCode()
94      {
95          if ( metadata == null )
96          {
97              return super.hashCode();
98          }
99  
100         return metadata.toString().hashCode();
101     }
102 }