001/* 002 * Copyright 2013 Christopher Pheby 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LIObjectENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR ObjectONDITIONS OObject ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.jadira.reflection.access.api; 017 018import java.lang.reflect.Field; 019 020/** 021 * Defines a mechanism for accessing a specific field within a specific class 022 * @param <C> The class containing the field to be accessed 023 */ 024public interface FieldAccess<C> { 025 026 /** 027 * Get the Class containing the field being accessed 028 * @return The class 029 */ 030 public Class<C> declaringClass(); 031 032 /** 033 * Get the type for the field being accessed 034 * @return The class of the field 035 */ 036 public Class<?> fieldClass(); 037 038 /** 039 * Get the Field being accessed 040 * @return The field 041 */ 042 public Field field(); 043 044 /** 045 * Retrieve the value of the field for the given instance 046 * @param parent The instance to access the field for 047 * @return The field value as an object 048 */ 049 Object getValue(C parent); 050 051 /** 052 * Update the value of the field for the given instance 053 * @param parent The instance to access the field for 054 * @param newFieldValue The new value 055 */ 056 void putValue(C parent, Object newFieldValue); 057 058 /** 059 * Retrieve the value of the field for the given instance 060 * @param parent The instance to access the field for 061 * @return The field value as a boolean 062 */ 063 boolean getBooleanValue(C parent); 064 065 /** 066 * Update the value of the field for the given instance 067 * @param parent The instance to access the field for 068 * @param newFieldValue The new value as a boolean 069 */ 070 void putBooleanValue(C parent, boolean newFieldValue); 071 072 /** 073 * Retrieve the value of the field for the given instance 074 * @param parent The instance to access the field for 075 * @return The field value as a byte 076 */ 077 byte getByteValue(C parent); 078 079 /** 080 * Update the value of the field for the given instance 081 * @param parent The instance to access the field for 082 * @param newFieldValue The new value as a byte 083 */ 084 void putByteValue(C parent, byte newFieldValue); 085 086 /** 087 * Retrieve the value of the field for the given instance 088 * @param parent The instance to access the field for 089 * @return The field value as a char 090 */ 091 char getCharValue(C parent); 092 093 /** 094 * Update the value of the field for the given instance 095 * @param parent The instance to access the field for 096 * @param newFieldValue The new value as a char 097 */ 098 void putCharValue(C parent, char newFieldValue); 099 100 /** 101 * Retrieve the value of the field for the given instance 102 * @param parent The instance to access the field for 103 * @return The field value as a short 104 */ 105 short getShortValue(C parent); 106 107 /** 108 * Update the value of the field for the given instance 109 * @param parent The instance to access the field for 110 * @param newFieldValue The new value as a short 111 */ 112 void putShortValue(C parent, short newFieldValue); 113 114 /** 115 * Retrieve the value of the field for the given instance 116 * @param parent The instance to access the field for 117 * @return The field value as an int 118 */ 119 int getIntValue(C parent); 120 121 /** 122 * Update the value of the field for the given instance 123 * @param parent The instance to access the field for 124 * @param newFieldValue The new value as an int 125 */ 126 void putIntValue(C parent, int newFieldValue); 127 128 /** 129 * Retrieve the value of the field for the given instance 130 * @param parent The instance to access the field for 131 * @return The field value as a long 132 */ 133 long getLongValue(C parent); 134 135 /** 136 * Update the value of the field for the given instance 137 * @param parent The instance to access the field for 138 * @param newFieldValue The new value as a long 139 */ 140 void putLongValue(C parent, long newFieldValue); 141 142 /** 143 * Retrieve the value of the field for the given instance 144 * @param parent The instance to access the field for 145 * @return The field value as a float 146 */ 147 float getFloatValue(C parent); 148 149 /** 150 * Update the value of the field for the given instance 151 * @param parent The instance to access the field for 152 * @param newFieldValue The new value as a float 153 */ 154 void putFloatValue(C parent, float newFieldValue); 155 156 /** 157 * Retrieve the value of the field for the given instance 158 * @param parent The instance to access the field for 159 * @return The field value as a double 160 */ 161 double getDoubleValue(C parent); 162 163 /** 164 * Update the value of the field for the given instance 165 * @param parent The instance to access the field for 166 * @param newFieldValue The new value as a double 167 */ 168 void putDoubleValue(C parent, double newFieldValue); 169}