View Javadoc

1   package net.sf.josceleton.motion.impl.gesture.hitwall;
2   
3   import java.util.Collection;
4   
5   import net.sf.josceleton.commons.exception.InvalidArgumentException;
6   import net.sf.josceleton.core.api.entity.CoordinateUtil;
7   import net.sf.josceleton.core.api.entity.XyzDirection;
8   import net.sf.josceleton.core.api.entity.joint.Joint;
9   import net.sf.josceleton.motion.api.gesture.hitwall.HitWallConfig;
10  import net.sf.josceleton.motion.impl.gesture.AbstractJointableGestureConfig;
11  
12  import com.google.inject.Inject;
13  import com.google.inject.assistedinject.Assisted;
14  
15  /**
16   * @since 0.4
17   */
18  class HitWallConfigImpl extends AbstractJointableGestureConfig implements HitWallConfig {
19  	
20  	private final float coordinate;
21  	
22  	private final XyzDirection direction;
23  	
24  	private final boolean triggerOnLower;
25  	
26  	
27  	@Inject HitWallConfigImpl(
28  			@Assisted final Collection<Joint> relevantJoints,
29  			@Assisted final float coordinate,
30  			@Assisted final XyzDirection direction,
31  			@Assisted final boolean triggerOnLower) {
32  		super(relevantJoints);
33  		if(CoordinateUtil.isCorrectValue(coordinate, direction) == false) {
34  			throw InvalidArgumentException.newInstance("coordinate", Float.valueOf(coordinate),
35  					"Not within valid range of " + CoordinateUtil.getCorrectValueLabel(direction) + "!");
36  		}
37  		this.coordinate = coordinate;
38  		this.direction = direction;
39  		this.triggerOnLower = triggerOnLower;
40  	}
41  	
42  	
43  	@Override public final float getCoordinate() {
44  		return this.coordinate;
45  	}
46  
47  	@Override public final XyzDirection getDirection() {
48  		return this.direction;
49  	}
50  
51  	@Override public final boolean getTriggerOnLower() {
52  		return this.triggerOnLower;
53  	}
54  	
55  	@Override public final boolean equals(final Object other) {
56  		if(this == other) { return true; }
57  		if((other instanceof HitWallConfig) == false) { return false; }
58  		final HitWallConfig that = (HitWallConfig) other;
59  		return	this.getCoordinate() == that.getCoordinate() &&
60  				this.getDirection() == that.getDirection() &&
61  				this.getTriggerOnLower() == that.getTriggerOnLower() &&
62  				this.getRelevantJoints().equals(that.getRelevantJoints()); // MINOR DRY maybe move to superclass?
63  	}
64  	
65  	@Override public final int hashCode() {
66  		return this.direction.hashCode();
67  	}
68  	
69  	@Override public final String toString() {
70  		return "HitWallConfigImpl[coordinate=" + this.coordinate + ", direction=" + this.direction + ", " +
71  				"triggerOnLower=" + this.triggerOnLower + "]";
72  	}
73  
74  }