View Javadoc

1   /**
2    * 
3    */
4   package org.ximtec.igesture.core.composite;
5   
6   import java.util.Iterator;
7   import java.util.Set;
8   
9   import org.ximtec.igesture.core.DefaultDataObject;
10  
11  /**
12   * @author Bjorn Puype, bpuype@gmail.com
13   *
14   */
15  public class DefaultConstraintEntry extends DefaultDataObject{
16  
17  	private String gesture;
18  	private int user = -1;
19  	private String deviceType = null;
20  	private Set<String> devices = null;
21  	
22  	/**
23  	 * Constructor, all users and all device are allowed to perform this gesture
24  	 * @param gesture	the gesture
25  	 */
26  	public DefaultConstraintEntry(String gesture)
27  	{
28  		this.gesture = gesture;
29  	}
30  	
31  	/**
32  	 * Constructor, all devices are allowed to perform this gesture
33  	 * @param gesture	the gesture
34  	 * @param user		the user that performs the gesture
35  	 */
36  	public DefaultConstraintEntry(String gesture, int user)
37  	{
38  		this.gesture = gesture;
39  		this.user = user;
40  	}
41  	
42  	/**
43  	 * Constructor, all users are allowed to perform this gesture
44  	 * @param gesture	the gesture
45  	 * @param deviceType	the device type used to perform the gestures
46  	 * @param devices	the specific devices that may be used to perform the gesture, specify null to allow all devices that are of type deviceType
47  	 */
48  	public DefaultConstraintEntry(String gesture, String deviceType, Set<String> devices)
49  	{
50  		this.gesture = gesture;
51  		if(deviceType != null && deviceType != "")
52  		{
53  			this.deviceType = deviceType;
54  			if(devices != null && !devices.isEmpty())
55  				this.devices = devices;
56  		}
57  	}
58  	
59  	/**
60  	 * Constructor
61  	 * @param gesture	the gesture
62  	 * @param user		the user that performs the gesture
63  	 * @param deviceType	the device type used to perform the gestures
64  	 * @param devices	the specific devices that may be used to perform the gesture, specify null to allow all devices that are of type deviceType
65  	 */
66  	public DefaultConstraintEntry(String gesture, int user, String deviceType, Set<String> devices)
67  	{
68  		this(gesture,deviceType,devices);
69  		this.user = user;
70  	}
71  
72  	/**
73  	 * @return the gesture
74  	 */
75  	public String getGesture() {
76  		return gesture;
77  	}
78  
79  	/**
80  	 * @return the user
81  	 */
82  	public int getUser() {
83  		return user;
84  	}
85  
86  	/**
87  	 * @return the device type
88  	 */
89  	public String getDeviceType() {
90  		return deviceType;
91  	}
92  
93  	/**
94  	 * @return the specific devices
95  	 */
96  	public Set<String> getDevices() {
97  		return devices;
98  	}
99  	
100 	public String toString()
101 	{
102 		StringBuilder builder = new StringBuilder("Gesture: ");
103 		builder.append(gesture);
104 		
105 		builder.append(", User: ");
106 		if(user == -1)
107 			builder.append("any");
108 		else
109 			builder.append(user);	
110 		
111 		builder.append(", Device Type: ");
112 		if(deviceType != null)
113 		{ 
114 			builder.append(deviceType);
115 			builder.append(", Device ID(s): ");
116 			if(devices != null && !devices.isEmpty())
117 			{
118 				for (Iterator iterator = devices.iterator(); iterator.hasNext();) {
119 					String id = (String) iterator.next();
120 					builder.append(id);
121 					if(iterator.hasNext())
122 						builder.append(" - ");
123 				}
124 			}
125 			else
126 				builder.append("any");				
127 		}
128 		else
129 			builder.append("any");
130 		
131 		return builder.toString();
132 	}
133 	
134 	
135 }