1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.jclouds.scriptbuilder.domain;
20
21 import static com.google.common.base.Preconditions.checkNotNull;
22
23 import java.util.List;
24
25 import com.google.common.collect.ImmutableList;
26 import com.google.common.collect.ImmutableList.Builder;
27
28
29
30
31
32
33 public class StatementList implements Statement {
34
35 public final List<Statement> statements;
36
37 public StatementList(Statement... statements) {
38 this.statements = ImmutableList.copyOf(checkNotNull(statements, "statements"));
39 }
40
41 public StatementList(Iterable<Statement> statements) {
42 this.statements = ImmutableList.copyOf(checkNotNull(statements, "statements"));
43 }
44
45 public String render(OsFamily family) {
46 StringBuilder statementsBuilder = new StringBuilder();
47 for (Statement statement : statements) {
48 statementsBuilder.append(statement.render(family));
49 }
50 return statementsBuilder.toString();
51 }
52
53 @Override
54 public Iterable<String> functionDependencies(OsFamily family) {
55 Builder<String> functions = ImmutableList.<String> builder();
56 for (Statement statement : statements) {
57 functions.addAll(statement.functionDependencies(family));
58 }
59 return functions.build();
60 }
61
62 @Override
63 public int hashCode() {
64 final int prime = 31;
65 int result = 1;
66 result = prime * result + ((statements == null) ? 0 : statements.hashCode());
67 return result;
68 }
69
70 @Override
71 public boolean equals(Object obj) {
72 if (this == obj)
73 return true;
74 if (obj == null)
75 return false;
76 if (getClass() != obj.getClass())
77 return false;
78 StatementList other = (StatementList) obj;
79 if (statements == null) {
80 if (other.statements != null)
81 return false;
82 } else if (!statements.equals(other.statements))
83 return false;
84 return true;
85 }
86
87 public List<Statement> getStatements() {
88 return statements;
89 }
90 }