final <R extends Route> R add(R route) throws MalformedRouteException { if (route == null) { throw new NullPointerException("No null route accepted"); } if (((Route) route).parent != null) { throw new IllegalArgumentException("No route with an existing parent can be accepted"); } // LinkedList<Param> ancestorParams = new LinkedList<Param>(); findAncestorOrSelfParams(ancestorParams); LinkedList<Param> descendantParams = new LinkedList<Param>(); for (Param param : ancestorParams) { ((Route) route).findDescendantOrSelfParams(param.name, descendantParams); if (descendantParams.size() > 0) { throw new MalformedRouteException("Duplicate parameter " + param.name); } } // if (route instanceof PatternRoute || route instanceof SegmentRoute) { children = Tools.appendTo(children, route); terminal = false; ((Route) route).parent = this; } else { throw new IllegalArgumentException("Only accept segment or pattern routes"); } // return route; }
final Route add(RequestParam param) throws MalformedRouteException { Param existing = findParam(param.name); if (existing != null) { throw new MalformedRouteException("Duplicate parameter " + param.name); } if (requestParamArray.length == 0) { requestParamMap = new HashMap<String, RequestParam>(); } requestParamMap.put(param.matchName, param); requestParamArray = Tools.appendTo(requestParamArray, param); return this; }