com.azaptree.services.command.util.CommandUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of azaptree-command-service Show documentation
Show all versions of azaptree-command-service Show documentation
Command Service that implements "Chain of Responsibility" pattern - building on top of Commons-Chain
The newest version!
package com.azaptree.services.command.util;
/*
* #%L
* AZAPTREE-COMMAND-SERVICE
* %%
* Copyright (C) 2012 AZAPTREE.COM
* %%
* 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.
* #L%
*/
import org.apache.commons.chain.Context;
import org.springframework.util.Assert;
import com.azaptree.services.commons.TypeReferenceKey;
public abstract class CommandUtils {
public static T get(final Context ctx, final TypeReferenceKey key) {
Assert.notNull(ctx, "ctx is required");
Assert.notNull(key, "key is required");
final T t = (T) ctx.get(key);
return t != null ? t : key.getDefaultValue();
}
@SuppressWarnings("unchecked")
public static T put(final Context ctx, final TypeReferenceKey key, final T value) {
Assert.notNull(ctx, "ctx is required");
Assert.notNull(key, "key is required");
Assert.notNull(value, "value is required");
return (T) ctx.put(key, value);
}
}