
com.basho.riak.client.convert.KeyUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of riak-client Show documentation
Show all versions of riak-client Show documentation
HttpClient-based client for Riak
/*
* This file is provided 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 com.basho.riak.client.convert;
import com.basho.riak.client.convert.reflect.AnnotationHelper;
/**
* Static methods to get /set the annotated key from/on a domain object.
*
* @author russell
* @see RiakKey
* @see JSONConverter
*/
public class KeyUtil {
/**
* Attempts to inject key
as the value of the {@link RiakKey}
* annotated field of domainObject
*
* @param
* the type of domainObject
* @param domainObject
* the object to inject the key into
* @param key
* the key to inject
* @return domainObject
with {@link RiakKey} annotated field
* set to key
* @throws ConversionException
* if there is a {@link RiakKey} annotated field but it cannot
* be set to the value of key
*/
public static T setKey(T domainObject, String key) throws ConversionException {
T obj = AnnotationHelper.getInstance().setRiakKey(domainObject, key);
return obj;
}
/**
* Attempts to get a key from domainObject
by looking for a
* {@link RiakKey} annotated field. If non-present it simply returns
* defaultKey
*
* @param
* the type of domainObject
* @param domainObject
* the object to search for a key
* @param defaultKey
* the pass through value that will get returned if no key found
* on domainObject
* @return either the value found on domainObject
;s
* {@link RiakKey} field or defaultkey
*/
public static String getKey(T domainObject, String defaultKey) {
String key = getKey(domainObject);
if (key == null) {
key = defaultKey;
}
return key;
}
/**
* Attempts to get a key from domainObject
by looking for a
* {@link RiakKey} annotated field. If non-present it simply returns
* null
*
* @param
* the type of domainObject
* @param domainObject
* the object to search for a key
* @return either the value found on domainObject
;s
* {@link RiakKey} field or null
*/
public static String getKey(T domainObject) {
return AnnotationHelper.getInstance().getRiakKey(domainObject);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy