View Javadoc
1   package guru.mikelue.jdut.yaml.node;
2   
3   import java.util.Map;
4   
5   /**
6    * Represents the type of node
7    */
8   public enum NodeType {
9   	Config, Defines, Table, Code, Unknown;
10  
11  	/**
12  	 * Gets the type of node by object.
13  	 *
14  	 * @param unknownObject The object loaded by YAML
15  	 *
16  	 * @return The matched type of node
17  	 */
18  	public static NodeType getNodeType(Object unknownObject)
19  	{
20  		if (Map.class.isInstance(unknownObject)) {
21  			Map<?, ?> mapOfUnknown = (Map<?, ?>)unknownObject;
22  			for (Object key: mapOfUnknown.keySet()) {
23  				if (TableNode.TableName.class.isInstance(key)) {
24  					return Table;
25  				}
26  				if ("config".equals(key)) {
27  					return Config;
28  				}
29  				if ("defines".equals(key)) {
30  					return Defines;
31  				}
32  			}
33  			return Unknown;
34  		}
35  
36  		if (CodeNode.class.isInstance(unknownObject)) {
37  			return Code;
38  		}
39  
40  		return Unknown;
41  	}
42  }