| // *************************************************************************************************************************** |
| // * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * |
| // * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * |
| // * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * |
| // * with the License. You may obtain a copy of the License at * |
| // * * |
| // * http://www.apache.org/licenses/LICENSE-2.0 * |
| // * * |
| // * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * |
| // * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * |
| // * specific language governing permissions and limitations under the License. * |
| // *************************************************************************************************************************** |
| package org.apache.juneau.rest; |
| |
| import java.util.*; |
| |
| import org.apache.juneau.collections.*; |
| |
| /** |
| * Builder for {@link RestMethods} object. |
| */ |
| public class RestMethodsBuilder { |
| |
| TreeMap<String,TreeSet<RestMethodContext>> map = new TreeMap<>(); |
| Set<RestMethodContext> set = ASet.of(); |
| |
| /** |
| * Adds a method context to this builder. |
| * |
| * @param mc The REST method context to add. |
| * @return Adds a method context to this builder. |
| */ |
| public RestMethodsBuilder add(RestMethodContext mc) { |
| return add(mc.getHttpMethod(), mc); |
| } |
| |
| /** |
| * Adds a method context to this builder. |
| * |
| * @param httpMethodName The HTTP method name. |
| * @param mc The REST method context to add. |
| * @return Adds a method context to this builder. |
| */ |
| public RestMethodsBuilder add(String httpMethodName, RestMethodContext mc) { |
| httpMethodName = httpMethodName.toUpperCase(); |
| if (! map.containsKey(httpMethodName)) |
| map.put(httpMethodName, new TreeSet<>()); |
| map.get(httpMethodName).add(mc); |
| set.add(mc); |
| return this; |
| } |
| |
| /** |
| * Creates a new {@link RestMethods} object using the contents of this builder. |
| * |
| * @return A new {@link RestMethods} object. |
| */ |
| public RestMethods build() { |
| return new RestMethods(this); |
| } |
| } |