code: 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;
      }
docs: Convert a PhysicalElement to a JSON object.
  
  @param pe the physical element to convert
  @return  the JSON object
  @throws IllegalArgumentException if the physical element is not supported