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   *
30   */
31  public class MetadataGraphNode
32  {
33      /** node payload */
34      MavenArtifactMetadata metadata;
35  
36      /** nodes, incident to this (depend on me) */
37      List<MetadataGraphNode> inNodes;
38  
39      /** nodes, exident to this (I depend on) */
40      List<MetadataGraphNode> exNodes;
41  
42      public MetadataGraphNode()
43      {
44          inNodes = new ArrayList<MetadataGraphNode>( 4 );
45          exNodes = new ArrayList<MetadataGraphNode>( 8 );
46      }
47  
48      public MetadataGraphNode( MavenArtifactMetadata metadata )
49      {
50          this();
51          this.metadata = metadata;
52      }
53  
54      public MetadataGraphNode addIncident( MetadataGraphNode node )
55      {
56          inNodes.add( node );
57          return this;
58      }
59  
60      public MetadataGraphNode addExident( MetadataGraphNode node )
61      {
62          exNodes.add( node );
63          return this;
64      }
65  
66      @Override
67      public boolean equals( Object obj )
68      {
69          if ( obj == null )
70          {
71              return false;
72          }
73  
74          if ( MetadataGraphNode.class.isAssignableFrom( obj.getClass() ) )
75          {
76              MetadataGraphNode node2 = (MetadataGraphNode) obj;
77  
78              if ( node2.metadata == null )
79              {
80                  return metadata == null;
81              }
82  
83              return metadata != null && metadata.toString().equals( node2.metadata.toString() );
84          }
85          else
86          {
87              return super.equals( obj );
88          }
89      }
90  
91      @Override
92      public int hashCode()
93      {
94          if ( metadata == null )
95          {
96              return super.hashCode();
97          }
98  
99          return metadata.toString().hashCode();
100     }
101 }