1 package org.apache.maven.repository.metadata;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.artifact.Artifact;
23 import org.apache.maven.artifact.ArtifactScopeEnum;
24
25
26
27
28
29
30
31 public class MetadataTreeNode
32 {
33 ArtifactMetadata md;
34
35 MetadataTreeNode parent;
36
37
38 int nChildren = 8;
39
40 MetadataTreeNode[] children;
41
42 public int getNChildren()
43 {
44 return nChildren;
45 }
46
47 public void setNChildren( int children )
48 {
49 nChildren = children;
50 }
51
52
53 public MetadataTreeNode()
54 {
55 }
56
57 public MetadataTreeNode( ArtifactMetadata md, MetadataTreeNode parent, boolean resolved, ArtifactScopeEnum scope )
58 {
59 if ( md != null )
60 {
61 md.setArtifactScope( ArtifactScopeEnum.checkScope( scope ) );
62 md.setResolved( resolved );
63 }
64
65 this.md = md;
66 this.parent = parent;
67 }
68
69 public MetadataTreeNode( Artifact af, MetadataTreeNode parent, boolean resolved, ArtifactScopeEnum scope )
70 {
71 this( new ArtifactMetadata( af ), parent, resolved, scope );
72 }
73
74
75 public void addChild( int index, MetadataTreeNode kid )
76 {
77 if ( kid == null )
78 {
79 return;
80 }
81
82 if ( children == null )
83 {
84 children = new MetadataTreeNode[nChildren];
85 }
86
87 children[index % nChildren] = kid;
88 }
89
90
91 @Override
92 public String toString()
93 {
94 return md == null ? "no metadata" : md.toString();
95 }
96
97
98 public String graphHash()
99 throws MetadataResolutionException
100 {
101 if ( md == null )
102 {
103 throw new MetadataResolutionException( "treenode without metadata, parent: "
104 + ( parent == null ? "null" : parent.toString() ) );
105 }
106
107 return md.groupId + ":" + md.artifactId;
108 }
109
110
111 public boolean hasChildren()
112 {
113 return children != null;
114 }
115
116 public ArtifactMetadata getMd()
117 {
118 return md;
119 }
120
121 public void setMd( ArtifactMetadata md )
122 {
123 this.md = md;
124 }
125
126 public MetadataTreeNode getParent()
127 {
128 return parent;
129 }
130
131 public void setParent( MetadataTreeNode parent )
132 {
133 this.parent = parent;
134 }
135
136 public MetadataTreeNode[] getChildren()
137 {
138 return children;
139 }
140
141 public void setChildren( MetadataTreeNode[] children )
142 {
143 this.children = children;
144 }
145
146
147
148 }