View Javadoc

1   /**
2    *
3    * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
4    *
5    * ====================================================================
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   * ====================================================================
18   */
19  package org.jclouds.vcloud.domain.network;
20  
21  import static com.google.common.base.Preconditions.checkNotNull;
22  
23  import java.util.List;
24  
25  import javax.annotation.Nullable;
26  
27  import org.jclouds.vcloud.domain.network.firewall.FirewallRule;
28  
29  import com.google.common.collect.Iterables;
30  import com.google.common.collect.Lists;
31  
32  /**
33   * The FirewallService element defines the firewall service capabilities of a network.
34   */
35  public class FirewallService {
36     private final boolean enabled;
37  
38     List<FirewallRule> firewallRules = Lists.newArrayList();
39  
40     public FirewallService(boolean enabled, Iterable<? extends FirewallRule> firewallRules) {
41        this.enabled = enabled;
42        Iterables.addAll(this.firewallRules, checkNotNull(firewallRules, "firewallRules"));
43     }
44  
45     /**
46      * @return Firewall rules for the network
47      * 
48      * @since vcloud api 0.8
49      */
50     public List<? extends FirewallRule> getFirewallRules() {
51        return firewallRules;
52     }
53  
54     /**
55      * @return true if the service is enabled
56      * 
57      * @since vcloud api 0.9
58      */
59     @Nullable
60     public boolean isEnabled() {
61        return enabled;
62     }
63  
64     @Override
65     public int hashCode() {
66        final int prime = 31;
67        int result = 1;
68        result = prime * result + (enabled ? 1231 : 1237);
69        result = prime * result + ((firewallRules == null) ? 0 : firewallRules.hashCode());
70        return result;
71     }
72  
73     @Override
74     public boolean equals(Object obj) {
75        if (this == obj)
76           return true;
77        if (obj == null)
78           return false;
79        if (getClass() != obj.getClass())
80           return false;
81        FirewallService other = (FirewallService) obj;
82        if (enabled != other.enabled)
83           return false;
84        if (firewallRules == null) {
85           if (other.firewallRules != null)
86              return false;
87        } else if (!firewallRules.equals(other.firewallRules))
88           return false;
89        return true;
90     }
91  
92     @Override
93     public String toString() {
94        return "[enabled=" + enabled + ", firewallRules=" + firewallRules + "]";
95     }
96  
97  }