Example usage for java.lang.reflect Modifier STATIC

List of usage examples for java.lang.reflect Modifier STATIC

Introduction

In this page you can find the example usage for java.lang.reflect Modifier STATIC.

Prototype

int STATIC

To view the source code for java.lang.reflect Modifier STATIC.

Click Source Link

Document

The int value representing the static modifier.

Usage

From source file:org.openflamingo.uploader.el.ELService.java

public static Object findConstant(String className, String constantName) throws SystemException {
    try {/*  ww w.  java 2  s  . com*/
        Class clazz = Thread.currentThread().getContextClassLoader().loadClass(className);
        Field field = clazz.getField(constantName);
        if ((field.getModifiers() & (Modifier.PUBLIC | Modifier.STATIC)) != (Modifier.PUBLIC
                | Modifier.STATIC)) {
            // throw new SystemException(ErrorCode.E0114, className, constantName);
        }
        return field.get(null);
    } catch (IllegalAccessException ex) {
        throw new SystemException(ex);
    } catch (NoSuchFieldException ex) {
        throw new SystemException(ex);
    } catch (ClassNotFoundException ex) {
        throw new SystemException(ex);
    }
}

From source file:info.raack.appliancedetection.evaluation.web.EvaluationController.java

@RequestMapping(value = "/evaluation/{id}", method = RequestMethod.GET)
public void getEvaluationData(@PathVariable("id") String simulationId,
        @RequestParam("algorithmId") int algorithmId,
        @RequestParam(value = "start", required = false) Double startMillis,
        @RequestParam(value = "end", required = false) Double endMillis,
        @RequestParam(value = "ticks", required = false) Integer ticks, HttpServletRequest request,
        HttpServletResponse response) throws IOException {

    // TODO - for now, just use the naive algorithm's energy measurements.

    Date start = null;/*from   w w w . ja v  a  2  s .c  o m*/
    Date end = null;

    if (startMillis != null && endMillis != null) {
        start = new Date(startMillis.longValue());
        end = new Date(endMillis.longValue());
    } else if (startMillis != null && endMillis == null) {
        // if only start or end are provided, create a one day span
        Calendar c = new GregorianCalendar();
        c.setTimeInMillis(startMillis.longValue());
        start = c.getTime();
    } else if (startMillis == null && endMillis != null) {
        // if only start or end are provided, create a one day span
        Calendar c = new GregorianCalendar();
        c.setTimeInMillis(endMillis.longValue());
        end = c.getTime();

    }

    if (ticks == null) {
        ticks = 300;
    }

    Evaluation evaluation = simulationService.getEvaluation(algorithmId, simulationId, start, end, true);

    if (evaluation == null) {
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        return;
    }

    EvaluationWrapper wrapper = new EvaluationWrapper(evaluation);

    JsonSerializer<EnergyTimestep> dateSerializer = new JsonSerializer<EnergyTimestep>() {
        // serialize date to milliseconds since epoch
        public JsonElement serialize(EnergyTimestep energyTimestep, Type me, JsonSerializationContext arg2) {
            JsonArray object = new JsonArray();
            object.add(new JsonPrimitive(energyTimestep.getStartTime().getTime()));
            object.add(new JsonPrimitive(energyTimestep.getEnergyConsumed()));
            return object;
        }
    };

    String dataJS = new GsonBuilder().registerTypeAdapter(EnergyTimestep.class, dateSerializer)
            .excludeFieldsWithModifiers(Modifier.STATIC).setExclusionStrategies(new ExclusionStrategy() {

                // skip logger
                public boolean shouldSkipClass(Class<?> clazz) {
                    return clazz.equals(Logger.class);
                }

                public boolean shouldSkipField(FieldAttributes fieldAttributes) {
                    // skip simulation of simulated appliance
                    return (fieldAttributes.getName().equals("simulation")
                            && fieldAttributes.getDeclaringClass() == SimulatedAppliance.class) ||
                    // skip simulation second data
                    (fieldAttributes.getName().equals("secondData")
                            && fieldAttributes.getDeclaringClass() == Simulation.class) ||
                    // skip endTime of energytimestep
                    (fieldAttributes.getName().equals("endTime")
                            && fieldAttributes.getDeclaringClass() == EnergyTimestep.class) ||
                    // skip userAppliance, detectionAlgorithmId of appliance state transition
                    ((fieldAttributes.getName().equals("userAppliance")
                            || fieldAttributes.getName().equals("detectionAlgorithmId"))
                            && fieldAttributes.getDeclaringClass() == ApplianceStateTransition.class);
                }
            }).create().toJson(wrapper);

    response.getWriter().write(dataJS);
    response.setContentType("application/json");
}

From source file:hu.bme.mit.sette.common.model.snippet.SnippetContainer.java

/**
 * Validates the fields of the class./*  w  w  w  .  jav a2 s.c o m*/
 *
 * @param validator
 *            a validator
 */
private void validateFields(final AbstractValidator<?> validator) {
    // check: only constant ("public static final") or synthetic fields
    for (Field field : javaClass.getDeclaredFields()) {
        if (field.isSynthetic()) {
            // skip for synthetic fields (e.g. switch for enum generates
            // synthetic methods and fields)
            continue;
        }

        FieldValidator v = new FieldValidator(field);
        v.withModifiers(Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL);
        v.withoutModifiers(Modifier.SYNCHRONIZED | Modifier.TRANSIENT | Modifier.VOLATILE);

        validator.addChildIfInvalid(v);
    }
}

From source file:com.antsdb.saltedfish.util.UberUtil.java

/**
 * warning, this method has no consideration of performance. it is written to help logging objects
 * //from   w w w .j  a  v a 2s.  c  om
 * @param obj
 * @return
 */
public static String toString(Object obj) {
    if (obj == null) {
        return "NULL";
    }
    StringBuilder buf = new StringBuilder();
    for (Field i : obj.getClass().getFields()) {
        if ((i.getModifiers() & Modifier.STATIC) != 0) {
            continue;
        }
        buf.append(i.getName());
        buf.append(":");
        Object value;
        try {
            value = i.get(obj);
        } catch (Exception x) {
            value = x.getMessage();
        }
        if (value != null) {
            buf.append(value.toString());
        } else {
            buf.append("NULL");
        }
        buf.append('\n');
    }
    return buf.toString();
}

From source file:org.eclipse.skalli.testutil.PropertyTestUtil.java

private static boolean hasPrivateField(Class<?> clazz, String fieldName) {
    for (Field field : clazz.getDeclaredFields()) {
        if (fieldName.equals(field.getName()) && ((field.getModifiers() & Modifier.PRIVATE) == Modifier.PRIVATE)
                && !((field.getModifiers() & Modifier.STATIC) == Modifier.STATIC)) {
            return true;
        }/*from w ww  . ja  v  a2 s .c om*/
    }
    return false;
}

From source file:hu.bme.mit.sette.common.model.snippet.SnippetInputFactoryContainer.java

/**
 * Validates methods of the class.// www  .ja v a 2s .com
 *
 * @param validator
 *            a validator
 * @return a map containing the input factory methods by their name
 */
private Map<String, Method> validateMethods(final AbstractValidator<?> validator) {
    // check: only "public static" or synthetic methods
    Map<String, Method> factoryMethods = new HashMap<String, Method>();

    for (Method method : javaClass.getDeclaredMethods()) {
        if (method.isSynthetic()) {
            // skip synthetic methods
            continue;
        }

        MethodValidator v = new MethodValidator(method);

        if (factoryMethods.get(method.getName()) != null) {
            v.addException("The method must have a unique name");
        }

        v.withModifiers(Modifier.PUBLIC | Modifier.STATIC);
        v.withoutModifiers(Modifier.ABSTRACT | Modifier.FINAL | Modifier.NATIVE | Modifier.SYNCHRONIZED);

        factoryMethods.put(method.getName(), method);

        validator.addChildIfInvalid(v);
    }

    return factoryMethods;
}

From source file:org.gvnix.addon.jpa.addon.query.JpaQueryMetadata.java

/**
 * Create metadata for a field definition.
 * /*from  w  w w.  j av a  2 s . c  om*/
 * @return a FieldMetadata object
 */
private FieldMetadata getFilterByField() {
    if (filterByField == null) {
        JavaSymbolName curName = new JavaSymbolName("filterByAssociations");
        String initializer = "null";
        int modifier = Modifier.PUBLIC + Modifier.STATIC;
        filterByField = getOrCreateField(curName, MAP_STRING_LIST_STRING, initializer, modifier, null);
    }
    return filterByField;
}

From source file:org.gvnix.addon.jpa.addon.query.JpaQueryMetadata.java

/**
 * Create metadata for a field definition.
 * /*w w  w .j ava2 s .  c om*/
 * @return a FieldMetadata object
 */
private FieldMetadata getOrderByField() {
    if (orderByField == null) {
        JavaSymbolName curName = new JavaSymbolName("orderyByAssociations");
        String initializer = "null";
        int modifier = Modifier.PUBLIC + Modifier.STATIC;
        orderByField = getOrCreateField(curName, MAP_STRING_LIST_STRING, initializer, modifier, null);
    }
    return orderByField;
}

From source file:com.yek.keyboard.ChewbaccaUncaughtExceptionHandler.java

private void addResourceNameWithId(StringBuilder resources, int resourceId, Class clazz) {
    for (Field field : clazz.getFields()) {
        if (field.getType().equals(int.class)) {
            if ((field.getModifiers() & (Modifier.STATIC | Modifier.PUBLIC)) != 0) {
                try {
                    if (resourceId == field.getInt(null)) {
                        resources.append(clazz.getName()).append(".").append(field.getName());
                        resources.append('\n');
                    }/* w  w w.jav  a 2  s  . c om*/
                } catch (IllegalAccessException e) {
                    Logger.d("EEEE", "Failed to access " + field.getName(), e);
                }
            }
        }
    }
}

From source file:hd3gtv.mydmam.db.orm.CassandraOrm.java

private ArrayList<Field> getOrmobjectUsableFields() {
    ArrayList<Field> result = new ArrayList<Field>();

    Field[] fields = this.reference.getFields();
    Field field;/*from   ww w  .  j  a  v  a 2s.c  o m*/
    int mod;
    for (int pos_df = 0; pos_df < fields.length; pos_df++) {
        field = fields[pos_df];
        if (field.isAnnotationPresent(Transient.class)) {
            /**
             * Is transient ?
             */
            continue;
        }
        if (field.getName().equals("key")) {
            /**
             * Not this (primary key)
             */
            continue;
        }
        mod = field.getModifiers();

        if ((mod & Modifier.PROTECTED) != 0)
            continue;
        if ((mod & Modifier.PRIVATE) != 0)
            continue;
        if ((mod & Modifier.ABSTRACT) != 0)
            continue;
        if ((mod & Modifier.STATIC) != 0)
            continue;
        if ((mod & Modifier.FINAL) != 0)
            continue;
        if ((mod & Modifier.TRANSIENT) != 0)
            continue;
        if ((mod & Modifier.INTERFACE) != 0)
            continue;

        try {
            result.add(field);
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (SecurityException e) {
            e.printStackTrace();
        }
    }

    return result;
}