00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2013, Yujin Robot. 00005 * 00006 * All rights reserved. 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions 00009 * are met: 00010 * 00011 * * Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * * Redistributions in binary form must reproduce the above 00014 * copyright notice, this list of conditions and the following 00015 * disclaimer in the documentation and/or other materials provided 00016 * with the distribution. 00017 * * Neither the name of Willow Garage, Inc. nor the names of its 00018 * contributors may be used to endorse or promote products derived 00019 * from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00022 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00023 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00024 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00025 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00026 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00027 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00028 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00031 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00032 * POSSIBILITY OF SUCH DAMAGE. 00033 */ 00034 00035 package com.github.rosjava.android_remocons.common_tools.master; 00036 00037 import java.util.Map; 00038 00044 public class MasterId implements java.io.Serializable { 00045 private static final long serialVersionUID = -1185642483404745956L; 00046 00047 private String masterUri; 00048 private String wifi; 00049 private String wifiEncryption; 00050 private String wifiPassword; 00051 00052 public MasterId() { 00053 } 00054 00055 public MasterId(String masterUri, String wifi, String wifiEncryption, String wifiPassword) { 00056 this.masterUri = masterUri; 00057 this.wifi = wifi; 00058 this.wifiEncryption = wifiEncryption; 00059 this.wifiPassword = wifiPassword; 00060 } 00061 00062 public MasterId(Map<String, Object> map) { 00063 if (map.containsKey("URL")) { 00064 this.masterUri = map.get("URL").toString(); 00065 } 00066 if (map.containsKey("WIFI")) { 00067 this.wifi = map.get("WIFI").toString(); 00068 } 00069 if (map.containsKey("WIFIENC")) { 00070 this.wifiEncryption = map.get("WIFIENC").toString(); 00071 } 00072 if (map.containsKey("WIFIPW")) { 00073 this.wifiPassword = map.get("WIFIPW").toString(); 00074 } 00075 } 00076 00077 public MasterId(String masterUri) { 00078 this.masterUri = masterUri; 00079 } 00080 00081 public String getMasterUri() { 00082 return masterUri; 00083 } 00084 00085 public String getWifi() { 00086 return wifi; 00087 } 00088 00089 public String getWifiEncryption() { 00090 return wifiEncryption; 00091 } 00092 00093 public String getWifiPassword() { 00094 return wifiPassword; 00095 } 00096 00097 @Override 00098 public String toString() { 00099 String str = getMasterUri() == null ? "" : getMasterUri(); 00100 if (getWifi() != null) { 00101 str = str + " On Wifi: " + getWifi(); 00102 } 00103 return str; 00104 } 00105 00106 //TODO: not needed? 00107 private boolean nullSafeEquals(Object a, Object b) { 00108 if (a == b) { //Handles case where both are null. 00109 return true; 00110 } 00111 if (a == null || b == null) { 00112 return false; 00113 } 00114 //Non-are null 00115 return a.equals(b); 00116 } 00117 00118 @Override 00119 public boolean equals(Object o) { 00120 00121 // Return true if the objects are identical. 00122 // (This is just an optimization, not required for correctness.) 00123 if (this == o) { 00124 return true; 00125 } 00126 // Return false if the other object has the wrong type. 00127 // This type may be an interface depending on the interface's specification. 00128 if (!(o instanceof MasterId)) { 00129 return false; 00130 } 00131 // Cast to the appropriate type. 00132 // This will succeed because of the instanceof, and lets us access private fields. 00133 MasterId lhs = (MasterId) o; 00134 return nullSafeEquals(this.masterUri, lhs.masterUri) 00135 && nullSafeEquals(this.wifi, lhs.wifi) 00136 && nullSafeEquals(this.wifiEncryption, lhs.wifiEncryption) 00137 && nullSafeEquals(this.wifiPassword, lhs.wifiPassword); 00138 } 00139 00140 @Override 00141 public int hashCode() { 00142 // Start with a non-zero constant. 00143 int result = 17; 00144 // Include a hash for each field checked by equals(). 00145 result = 31 * result + (masterUri == null ? 0 : masterUri.hashCode()); 00146 result = 31 * result + (wifi == null ? 0 : wifi.hashCode()); 00147 result = 31 * result + (wifiEncryption == null ? 0 : wifiEncryption.hashCode()); 00148 result = 31 * result + (wifiPassword == null ? 0 : wifiPassword.hashCode()); 00149 return result; 00150 } 00151 }