| Class | Line # | Actions | |||||
|---|---|---|---|---|---|---|---|
| InstanceId | 32 | 13 | 0% | 11 | 18 |
| 1 | /* | |
| 2 | * See the NOTICE file distributed with this work for additional | |
| 3 | * information regarding copyright ownership. | |
| 4 | * | |
| 5 | * This is free software; you can redistribute it and/or modify it | |
| 6 | * under the terms of the GNU Lesser General Public License as | |
| 7 | * published by the Free Software Foundation; either version 2.1 of | |
| 8 | * the License, or (at your option) any later version. | |
| 9 | * | |
| 10 | * This software is distributed in the hope that it will be useful, | |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 13 | * Lesser General Public License for more details. | |
| 14 | * | |
| 15 | * You should have received a copy of the GNU Lesser General Public | |
| 16 | * License along with this software; if not, write to the Free | |
| 17 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | |
| 18 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org. | |
| 19 | */ | |
| 20 | package org.xwiki.instance; | |
| 21 | ||
| 22 | import java.util.UUID; | |
| 23 | ||
| 24 | /** | |
| 25 | * Represents an XWiki instance using a unique id. | |
| 26 | * | |
| 27 | * Note that we need this class so that Hibernate can persist and read the id. | |
| 28 | * | |
| 29 | * @version $Id: dadc5b69597774cc7163349cf1fd80999862a158 $ | |
| 30 | * @since 5.2M2 | |
| 31 | */ | |
| 32 | public class InstanceId | |
| 33 | { | |
| 34 | /** | |
| 35 | * @see #getInstanceId() | |
| 36 | */ | |
| 37 | private UUID uuid; | |
| 38 | ||
| 39 | /** | |
| 40 | * Default constructor. It is need for Hibernate. | |
| 41 | */ | |
| 42 | 0 | public InstanceId() |
| 43 | { | |
| 44 | } | |
| 45 | ||
| 46 | /** | |
| 47 | * @param id the unique id of this instance | |
| 48 | */ | |
| 49 | 5 | public InstanceId(String id) |
| 50 | { | |
| 51 | 5 | setInstanceId(id); |
| 52 | } | |
| 53 | ||
| 54 | /** | |
| 55 | * @return the unique id of this instance | |
| 56 | */ | |
| 57 | 5 | public String getInstanceId() |
| 58 | { | |
| 59 | 5 | return this.uuid.toString(); |
| 60 | } | |
| 61 | ||
| 62 | /** | |
| 63 | * @param id the unique id represented as a String | |
| 64 | */ | |
| 65 | 6 | private void setInstanceId(String id) |
| 66 | { | |
| 67 | 6 | this.uuid = UUID.fromString(id); |
| 68 | } | |
| 69 | ||
| 70 | 4 | @Override |
| 71 | public String toString() | |
| 72 | { | |
| 73 | 4 | return this.uuid.toString(); |
| 74 | } | |
| 75 | ||
| 76 | 0 | @Override |
| 77 | public int hashCode() | |
| 78 | { | |
| 79 | 0 | return this.uuid.hashCode(); |
| 80 | } | |
| 81 | ||
| 82 | 0 | @Override |
| 83 | public boolean equals(Object o) | |
| 84 | { | |
| 85 | 0 | if (this == o) { |
| 86 | 0 | return true; |
| 87 | } | |
| 88 | ||
| 89 | 0 | if (o == null || !(o instanceof InstanceId)) { |
| 90 | 0 | return false; |
| 91 | } | |
| 92 | ||
| 93 | 0 | InstanceId instanceId = (InstanceId) o; |
| 94 | ||
| 95 | 0 | if (uuid == null) { |
| 96 | 0 | return instanceId.uuid == null; |
| 97 | } | |
| 98 | ||
| 99 | 0 | return uuid.equals(instanceId.uuid); |
| 100 | } | |
| 101 | } |