[1069] | 1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany |
---|
| 2 | // |
---|
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
---|
| 4 | // you may not use this file except in compliance with the License. |
---|
| 5 | // You may obtain a copy of the License at |
---|
| 6 | // |
---|
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
---|
| 8 | // |
---|
| 9 | // Unless required by applicable law or agreed to in writing, software |
---|
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
---|
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
| 12 | // See the License for the specific language governing permissions and |
---|
| 13 | // limitations under the License. |
---|
| 14 | |
---|
| 15 | package de.ugoe.cs.autoquest.htmlmonitor; |
---|
| 16 | |
---|
| 17 | /** |
---|
| 18 | * <p> |
---|
| 19 | * represents a web server including a port. |
---|
| 20 | * </p> |
---|
| 21 | * |
---|
| 22 | * @author Patrick Harms |
---|
| 23 | */ |
---|
| 24 | class HtmlServer extends HtmlGUIElement { |
---|
| 25 | |
---|
| 26 | /** |
---|
| 27 | * the name of the represented server |
---|
| 28 | */ |
---|
| 29 | private String name; |
---|
| 30 | |
---|
| 31 | /** |
---|
| 32 | * the port of the server (default is 80) |
---|
| 33 | */ |
---|
| 34 | private int port = 80; |
---|
| 35 | |
---|
| 36 | /** |
---|
[1089] | 37 | * the hash code of this document |
---|
| 38 | */ |
---|
| 39 | private int hashCode; |
---|
| 40 | |
---|
| 41 | /** |
---|
[1069] | 42 | * <p> |
---|
| 43 | * instantiates a new server element |
---|
| 44 | * </p> |
---|
| 45 | * |
---|
| 46 | * @param id the id of the server |
---|
| 47 | * @param name the name of the server |
---|
| 48 | * @param port the port on the server |
---|
| 49 | * (must be between 0 and 65536, otherwise default 80 is used) |
---|
| 50 | */ |
---|
| 51 | HtmlServer(String id, String name, int port) { |
---|
| 52 | super(id, null); |
---|
| 53 | |
---|
| 54 | if (name == null) { |
---|
| 55 | throw new IllegalArgumentException("name must not be null"); |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | this.name = name; |
---|
| 59 | |
---|
| 60 | if ((0 < port) && (port < 65536)) { |
---|
| 61 | this.port = port; |
---|
| 62 | } |
---|
| 63 | |
---|
[1089] | 64 | this.hashCode = this.name.hashCode() + this.port; |
---|
[1069] | 65 | } |
---|
| 66 | |
---|
| 67 | /** |
---|
| 68 | * <p> |
---|
| 69 | * returns the name of the server |
---|
| 70 | * </p> |
---|
| 71 | * |
---|
| 72 | * @return the name |
---|
| 73 | */ |
---|
| 74 | String getName() { |
---|
| 75 | return name; |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | /** |
---|
| 79 | * <p> |
---|
| 80 | * returns the port on the server |
---|
| 81 | * </p> |
---|
| 82 | * |
---|
| 83 | * @return the port |
---|
| 84 | */ |
---|
| 85 | int getPort() { |
---|
| 86 | return port; |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | /* (non-Javadoc) |
---|
[1075] | 90 | * @see java.lang.Object#equals(java.lang.Object) |
---|
[1069] | 91 | */ |
---|
| 92 | @Override |
---|
[1075] | 93 | public boolean equals(Object obj) { |
---|
[1069] | 94 | if (this == obj) { |
---|
| 95 | return true; |
---|
| 96 | } |
---|
| 97 | else if (obj instanceof HtmlServer) { |
---|
| 98 | return equals((HtmlServer) obj); |
---|
| 99 | } |
---|
| 100 | else { |
---|
| 101 | return false; |
---|
| 102 | } |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | /* (non-Javadoc) |
---|
| 106 | * @see de.ugoe.cs.autoquest.htmlmonitor.HtmlGUIElement#equals(de.ugoe.cs.autoquest.htmlmonitor.HtmlGUIElement) |
---|
| 107 | */ |
---|
| 108 | public boolean equals(HtmlServer other) { |
---|
| 109 | if (this == other) { |
---|
| 110 | return true; |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | return (name.equals(other.name) && (port == other.port)); |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | /* (non-Javadoc) |
---|
| 117 | * @see java.lang.Object#hashCode() |
---|
| 118 | */ |
---|
| 119 | @Override |
---|
| 120 | public int hashCode() { |
---|
[1089] | 121 | return hashCode; |
---|
[1069] | 122 | } |
---|
| 123 | |
---|
| 124 | } |
---|