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


android_apps
Author(s): Daniel Stonier , Kazuto Murase
autogenerated on Fri Aug 28 2015 10:04:40