001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 * 019 */ 020package org.apache.directory.api.ldap.model.message; 021 022 023/** 024 * The base request message class. 025 * 026 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 027 */ 028public class AbstractRequest extends AbstractMessage implements Request 029{ 030 static final long serialVersionUID = -4511116249089399040L; 031 032 /** Flag indicating whether or not this request returns a response. */ 033 private final boolean hasResponse; 034 035 036 /** 037 * Subclasses must provide these parameters via a super constructor call. 038 * 039 * @param id the sequential message identifier 040 * @param type the request type enum 041 * @param hasResponse flag indicating if this request generates a response 042 */ 043 protected AbstractRequest( final int id, final MessageTypeEnum type, boolean hasResponse ) 044 { 045 super( id, type ); 046 047 this.hasResponse = hasResponse; 048 } 049 050 051 /** 052 * Indicator flag used to determine whether or not this type of request 053 * produces a reply. 054 * 055 * @return true if any reply is generated, false if no response is generated 056 */ 057 public boolean hasResponse() 058 { 059 return hasResponse; 060 } 061 062 063 /** 064 * {@inheritDoc} 065 */ 066 @Override 067 public boolean equals( Object obj ) 068 { 069 if ( obj == this ) 070 { 071 return true; 072 } 073 074 if ( ( obj == null ) || !( obj instanceof Request ) ) 075 { 076 return false; 077 } 078 079 if ( hasResponse != ( ( Request ) obj ).hasResponse() ) 080 { 081 return false; 082 } 083 return super.equals( obj ); 084 } 085 086 087 /** 088 * @see Object#hashCode() 089 * @return the instance's hash code 090 */ 091 @Override 092 public int hashCode() 093 { 094 int hash = 37; 095 hash = hash * 17 + ( hasResponse ? 0 : 1 ); 096 hash = hash * 17 + super.hashCode(); 097 098 return hash; 099 } 100}