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
17package com.google.polo.pairing.message;
18
19/**
20 * Object implementing the internal representation of the protocol message
21 * 'CONFIGURATION'.
22 */
23public class ConfigurationMessage extends PoloMessage {
24
25  /**
26   * The encoding component of the message.
27   */
28  private EncodingOption mEncoding;
29
30  /**
31   * The client role component of the message.
32   */
33  private OptionsMessage.ProtocolRole mClientRole;
34
35  public ConfigurationMessage(EncodingOption enc,
36      OptionsMessage.ProtocolRole role) {
37    super(PoloMessage.PoloMessageType.CONFIGURATION);
38    mEncoding = enc;
39    mClientRole = role;
40  }
41
42  public EncodingOption getEncoding() {
43    return mEncoding;
44  }
45
46  public OptionsMessage.ProtocolRole getClientRole() {
47    return mClientRole;
48  }
49
50  @Override
51  public String toString() {
52    StringBuilder ret = new StringBuilder();
53    ret.append("[");
54    ret.append(getType());
55    ret.append(" encoding=");
56    ret.append(mEncoding);
57    ret.append(", client_role=");
58    ret.append(mClientRole);
59    ret.append("]");
60    return ret.toString();
61  }
62
63  @Override
64  public boolean equals(Object obj) {
65    if (this == obj) {
66      return true;
67    }
68
69    if (!(obj instanceof ConfigurationMessage)) {
70      return false;
71    }
72
73    ConfigurationMessage other = (ConfigurationMessage) obj;
74
75    if (mEncoding == null) {
76      if (other.mEncoding != null) {
77        return false;
78      }
79    } else if (!mEncoding.equals(other.mEncoding)) {
80      return false;
81    }
82
83    if (mClientRole == null) {
84      if (other.mClientRole != null) {
85        return false;
86      }
87    } else if (!mClientRole.equals(other.mClientRole)) {
88      return false;
89    }
90
91    return true;
92  }
93
94}
95