Last active
December 26, 2015 04:09
-
-
Save booknara/7091529 to your computer and use it in GitHub Desktop.
Object Key combining multiple variables for using a key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.daeheehan.cache; | |
public class UserProfileKey implements Comparable<UserProfileKey>{ | |
private String userId; | |
private String deviceId; | |
public UserProfileKey(String userId, String deviceId) { | |
this.userId = userId; | |
this.deviceId = deviceId; | |
} | |
public String getUserId() { | |
return userId; | |
} | |
public String getDeviceId() { | |
return deviceId; | |
} | |
public boolean isEmpty() { | |
if( userId == null || deviceId == null) { | |
return true; | |
} | |
return false; | |
} | |
@Override | |
public int hashCode() { | |
return userId.hashCode()+31 * deviceId.hashCode(); | |
} | |
@Override | |
public boolean equals(Object o) { | |
if(o==this) return true; | |
if(o==null || !(o instanceof UserProfileKey)) return false; | |
UserProfileKey cp= UserProfileKey.class.cast(o); | |
return userId.equals(cp.userId) && deviceId.equals(cp.deviceId); | |
} | |
public int compareTo(UserProfileKey cp) { | |
if(cp==this) return 0; | |
int i= userId.compareTo(cp.userId); | |
if(i!=0) return i; | |
return deviceId.compareTo(cp.deviceId); | |
} | |
@Override | |
public String toString() { | |
return "(" + userId +";" + deviceId + ")"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment