[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 | /** |
---|
| 37 | * <p> |
---|
| 38 | * instantiates a new server element |
---|
| 39 | * </p> |
---|
| 40 | * |
---|
| 41 | * @param id the id of the server |
---|
| 42 | * @param name the name of the server |
---|
| 43 | * @param port the port on the server |
---|
| 44 | * (must be between 0 and 65536, otherwise default 80 is used) |
---|
| 45 | */ |
---|
| 46 | HtmlServer(String id, String name, int port) { |
---|
| 47 | super(id, null); |
---|
| 48 | |
---|
| 49 | if (name == null) { |
---|
| 50 | throw new IllegalArgumentException("name must not be null"); |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | this.name = name; |
---|
| 54 | |
---|
| 55 | if ((0 < port) && (port < 65536)) { |
---|
| 56 | this.port = port; |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | /** |
---|
| 62 | * <p> |
---|
| 63 | * returns the name of the server |
---|
| 64 | * </p> |
---|
| 65 | * |
---|
| 66 | * @return the name |
---|
| 67 | */ |
---|
| 68 | String getName() { |
---|
| 69 | return name; |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | /** |
---|
| 73 | * <p> |
---|
| 74 | * returns the port on the server |
---|
| 75 | * </p> |
---|
| 76 | * |
---|
| 77 | * @return the port |
---|
| 78 | */ |
---|
| 79 | int getPort() { |
---|
| 80 | return port; |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | /* (non-Javadoc) |
---|
[1075] | 84 | * @see java.lang.Object#equals(java.lang.Object) |
---|
[1069] | 85 | */ |
---|
| 86 | @Override |
---|
[1075] | 87 | public boolean equals(Object obj) { |
---|
[1069] | 88 | if (this == obj) { |
---|
| 89 | return true; |
---|
| 90 | } |
---|
| 91 | else if (obj instanceof HtmlServer) { |
---|
| 92 | return equals((HtmlServer) obj); |
---|
| 93 | } |
---|
| 94 | else { |
---|
| 95 | return false; |
---|
| 96 | } |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | /* (non-Javadoc) |
---|
| 100 | * @see de.ugoe.cs.autoquest.htmlmonitor.HtmlGUIElement#equals(de.ugoe.cs.autoquest.htmlmonitor.HtmlGUIElement) |
---|
| 101 | */ |
---|
| 102 | public boolean equals(HtmlServer other) { |
---|
| 103 | if (this == other) { |
---|
| 104 | return true; |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | return (name.equals(other.name) && (port == other.port)); |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | /* (non-Javadoc) |
---|
| 111 | * @see java.lang.Object#hashCode() |
---|
| 112 | */ |
---|
| 113 | @Override |
---|
| 114 | public int hashCode() { |
---|
| 115 | return name.hashCode() + port; |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | } |
---|