View Javadoc

1   package net.sf.josceleton.core.impl.entity;
2   
3   import net.sf.josceleton.commons.exception.InvalidArgumentException;
4   import net.sf.josceleton.core.api.entity.User;
5   
6   class UserImpl implements User {
7   
8   	private final int uniqueId;
9   	
10  	private final int osceletonId;
11  	
12  	
13  //	@Inject UserImpl(@Assisted("uniqueId") final int uniqueId, @Assisted("osceletonId") final int osceletonId) {
14  	UserImpl(final int uniqueId, final int osceletonId) {
15  		if(uniqueId < 1) {
16  			throw InvalidArgumentException.newInstance("uniqueId", Integer.valueOf(uniqueId), "< 1");
17  		}
18  		if(osceletonId < 1) {
19  			throw InvalidArgumentException.newInstance("osceletonId", Integer.valueOf(osceletonId), "< 1");
20  		}
21  		if(uniqueId < osceletonId) { // internal (unique) ID must always be >= than (ID-reusing) osceleton ID
22  			throw InvalidArgumentException.newInstance("uniqueId, osceletonId", uniqueId + ", " + osceletonId,
23  					"uniqueId >= osceletonId");
24  		}
25  		
26  		this.uniqueId = uniqueId;
27  		this.osceletonId = osceletonId;
28  		
29  		
30  	}
31  
32  	/** {@inheritDoc} from {@link User} */
33  	@Override public final int getUniqueId() {
34  		return this.uniqueId;
35  	}
36  
37  	/** {@inheritDoc} from {@link User} */
38  	@Override public final int getOsceletonId() {
39  		return this.osceletonId;
40  	}
41  
42  	@Override public final boolean equals(final Object other) {
43  		if(this == other) { return true; }
44  		if((other instanceof User) == false) { return false; }
45  		final User that = (User) other;
46  		return this.getOsceletonId() == that.getOsceletonId() && this.getUniqueId() == that.getUniqueId();
47  	}
48  	
49  	@Override public final int hashCode() {
50  		return this.uniqueId;
51  	}
52  	
53  	@Override public final String toString() {
54  		return "UserImpl[uniqueId=" + this.uniqueId + ", osceletonId=" + this.osceletonId + "]";
55  	}
56  	
57  }