public JSONObject physicalElementToJSON ( PhysicalElement pe ) { JSONObject o = new JSONObject ( ) ; if ( pe instanceof Node ) { o . put ( "type" , NODE_LABEL ) ; o . put ( "id" , ( ( Node ) pe ) . id ( ) ) ; } else if ( pe instanceof Switch ) { o . put ( "type" , SWITCH_LABEL ) ; o . put ( "id" , ( ( Switch ) pe ) . id ( ) ) ; } else { throw new IllegalArgumentException ( "Unsupported physical element '" + pe . getClass ( ) . toString ( ) + "'" ) ; } return o ; }
Convert a PhysicalElement to a JSON object .