MessageLiteral.java
/***************************************************************************
Copyright 2014 Emily Estes
Licensed 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 net.metanotion.util;
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
/** This is a utility class to generate commonly used data objects for dispatchers to parse. This is useful for both
testing and other use cases. */
public final class MessageLiteral {
/** Make a message "pair" of a "method name" and a parameter list, with a zero length parameter list.
@param method The name of the method.
@return A pair containing a method name as the key and a zero length list as the value.
@see net.metanotion.util.ReflectionListDispatcher
*/
public static Map.Entry<String,Object> get(String method) { return MessageLiteral.get(method, null); }
/** Make a message "pair" of a method name and a parameter list.
@param method The name of the method.
@param params The array containing the parameters.
@return A pair whose key is the method name and whose value is the list of parameters.
@see net.metanotion.util.ReflectionListDispatcher
*/
public static Map.Entry<String,Object> get(String method, Object... params) {
return new Pair<String,Object>(method, (params == null) ? Collections.EMPTY_LIST : Arrays.asList(params));
}
}