Java tutorial
/* * This file is part of dropwizard-curator. * * dropwizard-curator is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * dropwizard-curator is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with dropwizard-curator. If not, see <http://www.gnu.org/licenses/>. */ package com.pandich.dropwizard.curator.refresh; import com.google.common.base.Predicate; import com.pandich.dropwizard.curator.CuratorRootConfiguration; import com.pandich.dropwizard.curator.PropertySources.PropertySource; import com.pandich.dropwizard.curator.mapper.CuratorMapper; import org.apache.commons.lang3.reflect.FieldUtils; import org.apache.curator.framework.CuratorFramework; import javax.annotation.Nullable; import java.lang.reflect.Field; import java.util.Map; import static java.lang.reflect.Modifier.isFinal; import static java.lang.reflect.Modifier.isStatic; public final class FieldRefresher extends Refresher<Field> { public static final Predicate<Field> fieldIsValid = new Predicate<Field>() { @Override public boolean apply(@Nullable final Field input) { return input != null && !isStatic(input.getModifiers()) && !isFinal(input.getModifiers()); } }; public FieldRefresher(final Map<Class<?>, CuratorMapper<?>> mappers, final CuratorFramework client, final CuratorRootConfiguration configuration) { super(mappers, client, configuration); } @Override protected Field doCastMember(final Object o) { return (Field) o; } @Override protected Class<?> getType(final Field element) { return element.getType(); } @Override protected void doWrite(final Field element, final Object value) throws ReflectiveOperationException { FieldUtils.writeField(element, this.configuration, value, true); } @Override protected void register(final Class<? extends CuratorRootConfiguration> configurationClass, final Field element, final PropertySource source) { this.propertySources.register(configurationClass, element, source); } }