View Javadoc

1   package net.sf.josceleton.core.api.entity.joint;
2   
3   import net.sf.josceleton.core.api.entity.joint.JointParts.Ankle;
4   import net.sf.josceleton.core.api.entity.joint.JointParts.Ankles;
5   import net.sf.josceleton.core.api.entity.joint.JointParts.Elbow;
6   import net.sf.josceleton.core.api.entity.joint.JointParts.Elbows;
7   import net.sf.josceleton.core.api.entity.joint.JointParts.Feet;
8   import net.sf.josceleton.core.api.entity.joint.JointParts.Foot;
9   import net.sf.josceleton.core.api.entity.joint.JointParts.Hand;
10  import net.sf.josceleton.core.api.entity.joint.JointParts.Hands;
11  import net.sf.josceleton.core.api.entity.joint.JointParts.Head;
12  import net.sf.josceleton.core.api.entity.joint.JointParts.Hip;
13  import net.sf.josceleton.core.api.entity.joint.JointParts.Hips;
14  import net.sf.josceleton.core.api.entity.joint.JointParts.Knee;
15  import net.sf.josceleton.core.api.entity.joint.JointParts.Knees;
16  import net.sf.josceleton.core.api.entity.joint.JointParts.LeftAnkle;
17  import net.sf.josceleton.core.api.entity.joint.JointParts.LeftElbow;
18  import net.sf.josceleton.core.api.entity.joint.JointParts.LeftFoot;
19  import net.sf.josceleton.core.api.entity.joint.JointParts.LeftHand;
20  import net.sf.josceleton.core.api.entity.joint.JointParts.LeftHip;
21  import net.sf.josceleton.core.api.entity.joint.JointParts.LeftJoint;
22  import net.sf.josceleton.core.api.entity.joint.JointParts.LeftKnee;
23  import net.sf.josceleton.core.api.entity.joint.JointParts.LeftShoulder;
24  import net.sf.josceleton.core.api.entity.joint.JointParts.Neck;
25  import net.sf.josceleton.core.api.entity.joint.JointParts.RightAnkle;
26  import net.sf.josceleton.core.api.entity.joint.JointParts.RightElbow;
27  import net.sf.josceleton.core.api.entity.joint.JointParts.RightFoot;
28  import net.sf.josceleton.core.api.entity.joint.JointParts.RightHand;
29  import net.sf.josceleton.core.api.entity.joint.JointParts.RightHip;
30  import net.sf.josceleton.core.api.entity.joint.JointParts.RightJoint;
31  import net.sf.josceleton.core.api.entity.joint.JointParts.RightKnee;
32  import net.sf.josceleton.core.api.entity.joint.JointParts.RightShoulder;
33  import net.sf.josceleton.core.api.entity.joint.JointParts.Shoulder;
34  import net.sf.josceleton.core.api.entity.joint.JointParts.Shoulders;
35  import net.sf.josceleton.core.api.entity.joint.JointParts.SymetricJoint;
36  import net.sf.josceleton.core.api.entity.joint.JointParts.Torso;
37  
38  final class JointImplProvider {
39  	
40  	private JointImplProvider() {
41  		// not instantiable
42  	}
43  	
44  	static class HeadImpl extends DefaultJoint implements Head {
45  		HeadImpl() { super("Head", OsceletonJointConstants.HEAD); } }
46  	static class NeckImpl extends DefaultJoint implements Neck {
47  		NeckImpl() { super("Neck", OsceletonJointConstants.NECK); } }
48  	static class TorsoImpl extends DefaultJoint implements Torso {
49  		TorsoImpl() { super("Torso", OsceletonJointConstants.TORSO); } }
50  
51  	private static class LeftShoulderImpl extends DefaultJoint implements LeftShoulder {
52  		LeftShoulderImpl() { super("Left Shoulder", OsceletonJointConstants.SHOULDER_LEFT); } }
53  	private static class RightShoulderImpl extends DefaultJoint implements RightShoulder {
54  		RightShoulderImpl() { super("Right Shoulder", OsceletonJointConstants.SHOULDER_RIGHT); } }
55  	static class ShouldersImpl extends DefaultSymetricJoint<Shoulder, LeftShoulder, RightShoulder>
56  		implements Shoulders { ShouldersImpl() { super(new LeftShoulderImpl(), new RightShoulderImpl()); } }
57  	
58  	private static class LeftElbowImpl extends DefaultJoint implements LeftElbow {
59  		LeftElbowImpl() { super("Left Elbow", OsceletonJointConstants.ELBOW_LEFT); } }
60  	private static class RightElbowImpl extends DefaultJoint implements RightElbow {
61  		RightElbowImpl() { super("Right Elbow", OsceletonJointConstants.ELBOW_RIGHT); } }
62  	static class ElbowsImpl extends DefaultSymetricJoint<Elbow, LeftElbow, RightElbow>
63  		implements Elbows { ElbowsImpl() { super(new LeftElbowImpl(), new RightElbowImpl()); } }
64  
65  	private static class LeftHandImpl extends DefaultJoint implements LeftHand { LeftHandImpl() {
66  		super("Left Hand", OsceletonJointConstants.HAND_LEFT); } }
67  	private static class RightHandImpl extends DefaultJoint implements RightHand {
68  		RightHandImpl() { super("Right Hand", OsceletonJointConstants.HAND_RIGHT); } }
69  	static class HandsImpl extends DefaultSymetricJoint<Hand, LeftHand, RightHand>
70  		implements Hands { HandsImpl() { super(new LeftHandImpl(), new RightHandImpl()); } }
71  	
72  	private static class LeftHipImpl extends DefaultJoint implements LeftHip {
73  		LeftHipImpl() { super("Left Hip", OsceletonJointConstants.HIP_LEFT); } }
74  	private static class RightHipImpl extends DefaultJoint implements RightHip {
75  		RightHipImpl() { super("Right Hip", OsceletonJointConstants.HIP_RIGHT); } }
76  	static class HipsImpl extends DefaultSymetricJoint<Hip, LeftHip, RightHip>
77  		implements Hips { HipsImpl() { super(new LeftHipImpl(), new RightHipImpl()); } }
78  	
79  	private static class LeftKneeImpl extends DefaultJoint implements LeftKnee {
80  		LeftKneeImpl() { super("Left Knee", OsceletonJointConstants.KNEE_LEFT); } }
81  	private static class RightKneeImpl extends DefaultJoint implements RightKnee {
82  		RightKneeImpl() { super("Right Knee", OsceletonJointConstants.KNEE_RIGHT); } }
83  	static class KneesImpl extends DefaultSymetricJoint<Knee, LeftKnee, RightKnee>
84  		implements Knees { KneesImpl() { super(new LeftKneeImpl(), new RightKneeImpl()); } }
85  	
86  	private static class LeftAnkleImpl extends DefaultJoint implements LeftAnkle {
87  		LeftAnkleImpl() { super("Left Ankle", OsceletonJointConstants.ANKLE_LEFT); } }
88  	private static class RightAnkleImpl extends DefaultJoint implements RightAnkle {
89  		RightAnkleImpl() { super("Right Ankle", OsceletonJointConstants.ANKLE_RIGHT); } }
90  	static class AnklesImpl extends DefaultSymetricJoint<Ankle, LeftAnkle, RightAnkle>
91  		implements Ankles { AnklesImpl() { super(new LeftAnkleImpl(), new RightAnkleImpl()); } }
92  	
93  	private static class LeftFootImpl extends DefaultJoint implements LeftFoot {
94  		LeftFootImpl() { super("Left Foot", OsceletonJointConstants.FOOT_LEFT); } }
95  	private static class RightFootImpl extends DefaultJoint implements RightFoot {
96  		RightFootImpl() { super("Right Foot", OsceletonJointConstants.FOOT_RIGHT); } }
97  	static class FeetImpl extends DefaultSymetricJoint<Foot, LeftFoot, RightFoot>
98  		implements Feet { FeetImpl() { super(new LeftFootImpl(), new RightFootImpl()); } }
99  	
100 	
101 	private abstract static class DefaultJoint implements Joint {
102 		
103 		private static final String TO_STRING_PREFIX = "Body ";
104 		private final String cachedToString;
105 		private final String label;
106 		private final String osceletonId;
107 		
108 		DefaultJoint(final String label, final String osceletonId) {
109 			this.label = label;
110 			this.osceletonId = osceletonId;
111 			this.cachedToString = TO_STRING_PREFIX + this.label;
112 		}
113 		
114 		@Override public final String getLabel() { return this.label; }
115 		@Override public final String getOsceletonId() { return this.osceletonId; }
116 		
117 		@Override public final String toString() {
118 			return this.cachedToString;
119 		}
120 		
121 		@Override public final boolean equals(final Object other) {
122 			if(this == other) { return true; }
123 			if((other instanceof Joint) == false) { return false; }
124 			final Joint that = (Joint) other;
125 			return this.getOsceletonId().equals(that.getOsceletonId()) && 
126 				   this.getLabel().equals(that.getLabel());
127 		}
128 		
129 		@Override public final int hashCode() {
130 			return this.osceletonId.hashCode();
131 		}
132 	}
133 	
134 	private static class DefaultSymetricJoint<J, LJ extends LeftJoint<J>, RJ extends RightJoint<J>>
135 		implements SymetricJoint<J, LJ, RJ> {
136 		
137 		private final LJ leftJoint;
138 		private final RJ rightJoint;
139 		private final String cachedToString;
140 		
141 		DefaultSymetricJoint(final LJ leftJoint, final RJ rightJoint) {
142 			this.leftJoint = leftJoint;
143 			this.rightJoint = rightJoint;
144 			this.cachedToString = "Sym[" + leftJoint + "/" + rightJoint + "]";
145 		}
146 		
147 		@Override public final LJ LEFT() { return this.leftJoint; }
148 		@Override public final RJ RIGHT() { return this.rightJoint; }
149 
150 		@Override public final String toString() {
151 			return this.cachedToString;
152 		}
153 		
154 		@Override public final boolean equals(final Object other) {
155 			if(this == other) { return true; }
156 			if((other instanceof SymetricJoint<?, ?, ?>) == false) { return false; }
157 			final SymetricJoint<?, ?, ?> that = (SymetricJoint<?, ?, ?>) other;
158 			return this.LEFT().equals(that.LEFT()) && 
159 				   this.RIGHT().equals(that.RIGHT());
160 		}
161 		
162 		@Override public final int hashCode() {
163 			return this.leftJoint.hashCode();
164 		}
165 	}
166 }