001 package org.apache.maven.repository;
002
003 /*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements. See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership. The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License. You may obtain a copy of the License at
011 *
012 * http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied. See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022 import java.util.ArrayList;
023 import java.util.List;
024
025 /**
026 * MetadataGraph node - as it's a directed graph - holds adjacency lists for incident and exident nodes
027 *
028 * @author Oleg Gusakov
029 *
030 */
031 public class MetadataGraphNode
032 {
033 /** node payload */
034 MavenArtifactMetadata metadata;
035
036 /** nodes, incident to this (depend on me) */
037 List<MetadataGraphNode> inNodes;
038
039 /** nodes, exident to this (I depend on) */
040 List<MetadataGraphNode> exNodes;
041
042 public MetadataGraphNode()
043 {
044 inNodes = new ArrayList<MetadataGraphNode>( 4 );
045 exNodes = new ArrayList<MetadataGraphNode>( 8 );
046 }
047
048 public MetadataGraphNode( MavenArtifactMetadata metadata )
049 {
050 this();
051 this.metadata = metadata;
052 }
053
054 public MetadataGraphNode addIncident( MetadataGraphNode node )
055 {
056 inNodes.add( node );
057 return this;
058 }
059
060 public MetadataGraphNode addExident( MetadataGraphNode node )
061 {
062 exNodes.add( node );
063 return this;
064 }
065
066 @Override
067 public boolean equals( Object obj )
068 {
069 if ( obj == null )
070 {
071 return false;
072 }
073
074 if ( MetadataGraphNode.class.isAssignableFrom( obj.getClass() ) )
075 {
076 MetadataGraphNode node2 = (MetadataGraphNode) obj;
077
078 if ( node2.metadata == null )
079 {
080 return metadata == null;
081 }
082
083 return metadata != null && metadata.toString().equals( node2.metadata.toString() );
084 }
085 else
086 {
087 return super.equals( obj );
088 }
089 }
090
091 @Override
092 public int hashCode()
093 {
094 if ( metadata == null )
095 {
096 return super.hashCode();
097 }
098
099 return metadata.toString().hashCode();
100 }
101 }