Home | History | Annotate | Download | only in message
      1 /*
      2  * Copyright (C) 2009 Google Inc.  All rights reserved.
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.google.polo.pairing.message;
     18 
     19 /**
     20  * Object implementing the internal representation of the protocol message
     21  * 'PAIRING_REQUEST'.
     22  */
     23 public class PairingRequestMessage extends PoloMessage {
     24 
     25   /**
     26    * The service name being requested for pairing.
     27    */
     28   private final String mServiceName;
     29 
     30   /**
     31    * Client name.
     32    */
     33   private final String mClientName;
     34 
     35   public PairingRequestMessage(String serviceName) {
     36     this(serviceName, null);
     37   }
     38 
     39   public PairingRequestMessage(String serviceName, String clientName) {
     40     super(PoloMessage.PoloMessageType.PAIRING_REQUEST);
     41     mServiceName = serviceName;
     42     mClientName = clientName;
     43   }
     44 
     45   public String getServiceName() {
     46     return mServiceName;
     47   }
     48 
     49   public String getClientName() {
     50     return mClientName;
     51   }
     52 
     53   public boolean hasClientName() {
     54     return mClientName != null;
     55   }
     56 
     57   @Override
     58   public String toString() {
     59     return new StringBuilder()
     60         .append("[")
     61         .append(getType())
     62         .append(" service_name=")
     63         .append(mServiceName)
     64         .append(", client_name=")
     65         .append(mClientName)
     66         .append("]").toString();
     67   }
     68 
     69   @Override
     70   public boolean equals(Object obj) {
     71     if (this == obj) {
     72       return true;
     73     }
     74 
     75     if (!(obj instanceof PairingRequestMessage)) {
     76       return false;
     77     }
     78 
     79     PairingRequestMessage other = (PairingRequestMessage) obj;
     80 
     81     if (mServiceName == null) {
     82       if (other.mServiceName != null) {
     83         return false;
     84       }
     85     } else if (!mServiceName.equals(other.mServiceName)) {
     86       return false;
     87     } else if (mClientName == null) {
     88       if (other.mClientName != null) {
     89         return false;
     90       }
     91     } else if (!mClientName.equals(other.mClientName)) {
     92       return false;
     93     }
     94 
     95     return true;
     96   }
     97 
     98 }
     99