11/*
22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33 *
4- * Copyright (c) 2010-2012 Oracle and/or its affiliates. All rights reserved.
4+ * Copyright (c) 2010-2015 Oracle and/or its affiliates. All rights reserved.
55 *
66 * The contents of this file are subject to the terms of either the GNU
77 * General Public License Version 2 only ("GPL") or the Common Development
3939 */
4040package org .glassfish .jersey .message .internal ;
4141
42- import javax .ws .rs .core .Response . Status ;
42+ import javax .ws .rs .core .Response ;
4343import javax .ws .rs .core .Response .Status .Family ;
4444import javax .ws .rs .core .Response .StatusType ;
4545
@@ -53,9 +53,9 @@ public final class Statuses {
5353
5454 private static final class StatusImpl implements StatusType {
5555
56- private int code ;
57- private String reason ;
58- private Family family ;
56+ private final int code ;
57+ private final String reason ;
58+ private final Family family ;
5959
6060 private StatusImpl (int code , String reason ) {
6161 this .code = code ;
@@ -82,17 +82,74 @@ public String toString() {
8282 public Family getFamily () {
8383 return family ;
8484 }
85+
86+ @ Override
87+ @ SuppressWarnings ("RedundantIfStatement" )
88+ public boolean equals (final Object o ) {
89+ if (this == o ) {
90+ return true ;
91+ }
92+ if (!(o instanceof StatusType )) {
93+ return false ;
94+ }
95+
96+ final StatusType status = (StatusType ) o ;
97+
98+ if (code != status .getStatusCode ()) {
99+ return false ;
100+ }
101+ if (family != status .getFamily ()) {
102+ return false ;
103+ }
104+ if (reason != null ? !reason .equals (status .getReasonPhrase ()) : status .getReasonPhrase () != null ) {
105+ return false ;
106+ }
107+
108+ return true ;
109+ }
110+
111+ @ Override
112+ public int hashCode () {
113+ int result = code ;
114+ result = 31 * result + (reason != null ? reason .hashCode () : 0 );
115+ result = 31 * result + family .hashCode ();
116+ return result ;
117+ }
85118 }
86119
120+ /**
121+ * Create a new status type instance.
122+ * <p>
123+ * For standard status codes listed in {@link javax.ws.rs.core.Response.Status} enum, the default reason phrase
124+ * is used. For any other status code an empty string is used as a reason phrase.
125+ * </p>
126+ *
127+ * @param code response status code.
128+ * @return new status type instance representing a given response status code.
129+ */
87130 public static StatusType from (int code ) {
88- StatusType result = Status .fromStatusCode (code );
131+ StatusType result = Response . Status .fromStatusCode (code );
89132 return (result != null ) ? result : new StatusImpl (code , "" );
90133 }
91134
135+ /**
136+ * Create a new status type instance with a custom reason phrase.
137+ *
138+ * @param code response status code.
139+ * @param reason custom response status reason phrase.
140+ * @return new status type instance representing a given response status code and custom reason phrase.
141+ */
92142 public static StatusType from (int code , String reason ) {
93143 return new StatusImpl (code , reason );
94144 }
95145
146+ /**
147+ * Create a new status type instance with a custom reason phrase.
148+ *
149+ * @param status response status type.
150+ * @param reason custom response status reason phrase.
151+ * @return new status type instance representing a given response status code and custom reason phrase.
152+ */
96153 public static StatusType from (StatusType status , String reason ) {
97154 return new StatusImpl (status .getStatusCode (), reason );
98155 }
@@ -101,5 +158,6 @@ public static StatusType from(StatusType status, String reason) {
101158 * Prevents instantiation.
102159 */
103160 private Statuses () {
161+ throw new AssertionError ("Instantiation not allowed." );
104162 }
105163}
0 commit comments