List of usage examples for java.lang Class getSimpleName
public String getSimpleName()
From source file:com.evolveum.midpoint.model.client.ModelClientUtil.java
public static QName getTypeQName(Class<? extends ObjectType> type) { QName typeQName = new QName(NS_COMMON, type.getSimpleName()); return typeQName; }
From source file:de.micromata.genome.tpsb.htmlunit.HtmlPageBase.java
public static String getPageName(Class<? extends HtmlPageBase> clazz) { HtmlPageUrl an = clazz.getAnnotation(HtmlPageUrl.class); if (an == null) throw new RuntimeException("Class missing HtmlPageUrl annotation: " + clazz.getSimpleName()); return an.value(); }
From source file:com.velonuboso.made.core.common.Helper.java
/** * Modification by rhgarcia from the implementation of M. Jessup * at StackOverflow./*w w w.j av a 2 s .c o m*/ * http://stackoverflow.com/users/294738/m-jessup */ public static ArrayList<Class> topologicalOrder(ArrayList<Class> classes) throws Exception { Node[] allNodes = new Node[classes.size()]; HashMap<String, Node> nodes = new HashMap<String, Node>(); for (int i = 0; i < classes.size(); i++) { Class c = classes.get(i); Node n = new Node(c); allNodes[i] = n; nodes.put(c.getSimpleName(), n); } for (int i = 0; i < allNodes.length; i++) { Node n = allNodes[i]; Class c = n.getC(); Archetype a = (Archetype) c.getConstructors()[0].newInstance(); ArrayList<Class> dependencies = a.getDependencies(); for (int j = 0; j < dependencies.size(); j++) { Class dep = dependencies.get(j); Node nAux = nodes.get(dep.getSimpleName()); if (nAux != null) { nAux.addEdge(n); } } } //L <- Empty list that will contain the sorted elements ArrayList<Node> L = new ArrayList<Node>(); //S <- Set of all nodes with no incoming edges HashSet<Node> S = new HashSet<Node>(); for (Node n : allNodes) { if (n.inEdges.size() == 0) { S.add(n); } } //while S is non-empty do while (!S.isEmpty()) { //remove a node n from S Node n = S.iterator().next(); S.remove(n); //insert n into L L.add(n); //for each node m with an edge e from n to m do for (Iterator<Edge> it = n.outEdges.iterator(); it.hasNext();) { //remove edge e from the graph Edge e = it.next(); Node m = e.to; it.remove();//Remove edge from n m.inEdges.remove(e);//Remove edge from m //if m has no other incoming edges then insert m into S if (m.inEdges.isEmpty()) { S.add(m); } } } //Check to see if all edges are removed boolean cycle = false; for (Node n : allNodes) { if (!n.inEdges.isEmpty()) { cycle = true; break; } } if (cycle) { throw new Exception("Cycle present, topological sort not possible"); } System.out.println("Topological Sort: " + Arrays.toString(L.toArray())); ArrayList<Class> ret = new ArrayList<Class>(); for (Node n : L) { ret.add(n.getC()); } return ret; }
From source file:iing.uabc.edu.mx.persistencia.util.JSON.java
private static void stringifyObject(JsonGenerator generator, BeanManager manager) { String keyName;/*from w w w . j av a 2s. c o m*/ Field[] fields = manager.getFields(); //Read every field and transform it to a json property string for (Field field : fields) { Class fieldType = manager.getType(field.getName()); keyName = field.getName(); Object value = manager.getProperty(keyName); System.out.println("KeyName: " + keyName); System.out.println("Valor " + keyName + ": " + value); if (value == null) { //Set to null the property generator.writeNull(keyName); continue; } //Is a String if (fieldType == String.class) { generator.write(keyName, String.valueOf(value)); } //Is a Date else if (fieldType == Date.class) { String date = DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(value); generator.write(keyName, date); } //Is a integer else if (fieldType == Integer.class || fieldType == Integer.TYPE) { generator.write(keyName, (int) value); } //Is a double else if (fieldType == Double.class || fieldType == Double.TYPE) { generator.write(keyName, (double) value); } //Is boolean else if (fieldType == Boolean.class || fieldType == Boolean.TYPE) { generator.write(keyName, (boolean) value); } //Is a collection else if (value instanceof Collection) { Class elementClass = manager.getCollectionElementType(keyName); System.out.println("Nueva Colleccion [] de clase: " + elementClass.getSimpleName()); generator.writeStartArray(keyName); //Create new collection manager with the given class CollectionManager collectionManager = new CollectionManager((Collection) value, elementClass); stringifyArray(generator, collectionManager); generator.writeEnd(); } else { //Is a object... probably BeanManager objectManager = new BeanManager(value); System.out.println("Nuevo Objecto {}: " + value.getClass().getSimpleName()); generator.writeStartObject(keyName); stringifyObject(generator, objectManager); generator.writeEnd(); } } }
From source file:io.github.lxgaming.teleportbow.managers.CommandManager.java
public static boolean registerCommand(AbstractCommand parentCommand, Class<? extends AbstractCommand> commandClass) { if (parentCommand.getClass() == commandClass) { TeleportBow.getInstance().getLogger().warn("{} attempted to register itself", parentCommand.getClass().getSimpleName()); return false; }/* w w w .j av a 2 s . c o m*/ if (getCommandClasses().contains(commandClass)) { TeleportBow.getInstance().getLogger().warn("{} has already been registered", commandClass.getSimpleName()); return false; } getCommandClasses().add(commandClass); Optional<AbstractCommand> command = Toolbox.newInstance(commandClass); if (!command.isPresent()) { TeleportBow.getInstance().getLogger().error("{} failed to initialize", commandClass.getSimpleName()); return false; } parentCommand.getChildren().add(command.get()); TeleportBow.getInstance().getLogger().debug("{} registered for {}", commandClass.getSimpleName(), parentCommand.getClass().getSimpleName()); return true; }
From source file:com.ngdata.hbaseindexer.indexer.FusionDocumentWriter.java
public static MetricName metricName(Class<?> producerClass, String metric, String indexerName) { return new MetricName("Lucidworks", producerClass.getSimpleName(), metric, indexerName); }
From source file:com.vmware.photon.controller.common.dcp.BasicServiceHost.java
private static String buildPath(Class<? extends Service> type) { try {/* w w w. jav a 2s .c om*/ Field f = type.getField(FIELD_NAME_SELF_LINK); return (String) f.get(null); } catch (NoSuchFieldException | IllegalAccessException e) { Utils.log(Utils.class, Utils.class.getSimpleName(), Level.SEVERE, "%s field not found in class %s: %s", FIELD_NAME_SELF_LINK, type.getSimpleName(), Utils.toString(e)); throw new IllegalArgumentException(e); } }
From source file:com.yahoo.elide.utils.coerce.converters.EpochToDateConverter.java
private static <T> T longToDate(Class<T> cls, Long epoch) throws ReflectiveOperationException { if (ClassUtils.isAssignable(cls, java.sql.Date.class)) { return (T) new java.sql.Date(epoch); } else if (ClassUtils.isAssignable(cls, Timestamp.class)) { return (T) new Timestamp(epoch); } else if (ClassUtils.isAssignable(cls, Time.class)) { return (T) new Time(epoch); } else if (ClassUtils.isAssignable(cls, Date.class)) { return (T) new Date(epoch); } else {//from ww w .jav a2 s .co m throw new UnsupportedOperationException("Cannot convert to " + cls.getSimpleName()); } }
From source file:edu.usu.sdl.openstorefront.util.ReflectionUtil.java
/** * This check for Value Model Objects// ww w . ja va 2s. com * * @param fieldClass * @return */ public static boolean isComplexClass(Class fieldClass) { Objects.requireNonNull(fieldClass, "Class is required"); boolean complex = false; if (!fieldClass.isPrimitive() && !fieldClass.isArray() && !fieldClass.getSimpleName().equalsIgnoreCase(String.class.getSimpleName()) && !fieldClass.getSimpleName().equalsIgnoreCase(Long.class.getSimpleName()) && !fieldClass.getSimpleName().equalsIgnoreCase(Integer.class.getSimpleName()) && !fieldClass.getSimpleName().equalsIgnoreCase(Boolean.class.getSimpleName()) && !fieldClass.getSimpleName().equalsIgnoreCase(Double.class.getSimpleName()) && !fieldClass.getSimpleName().equalsIgnoreCase(Float.class.getSimpleName()) && !fieldClass.getSimpleName().equalsIgnoreCase(BigDecimal.class.getSimpleName()) && !fieldClass.getSimpleName().equalsIgnoreCase(Date.class.getSimpleName()) && !fieldClass.getSimpleName().equalsIgnoreCase(List.class.getSimpleName()) && !fieldClass.getSimpleName().equalsIgnoreCase(Map.class.getSimpleName()) && !fieldClass.getSimpleName().equalsIgnoreCase(Collection.class.getSimpleName()) && !fieldClass.getSimpleName().equalsIgnoreCase(Queue.class.getSimpleName()) && !fieldClass.getSimpleName().equalsIgnoreCase(Set.class.getSimpleName()) && !fieldClass.getSimpleName().equalsIgnoreCase(BigInteger.class.getSimpleName())) { complex = true; } return complex; }
From source file:com.espertech.esper.epl.annotation.AnnotationUtil.java
private static Object getFinalValue(Class annotationClass, AnnotationAttribute annotationAttribute, Object value, EngineImportService engineImportService) throws AnnotationException { if (value == null) { if (annotationAttribute.getDefaultValue() == null) { throw new AnnotationException("Annotation '" + annotationClass.getSimpleName() + "' requires a value for attribute '" + annotationAttribute.getName() + "'"); }/* w w w. j av a 2 s .com*/ return annotationAttribute.getDefaultValue(); } // handle non-array if (!annotationAttribute.getType().isArray()) { // handle primitive value if (!annotationAttribute.getType().isAnnotation()) { SimpleTypeCaster caster = SimpleTypeCasterFactory.getCaster(value.getClass(), annotationAttribute.getType()); Object finalValue = caster.cast(value); if (finalValue == null) { throw new AnnotationException("Annotation '" + annotationClass.getSimpleName() + "' requires a " + annotationAttribute.getType().getSimpleName() + "-typed value for attribute '" + annotationAttribute.getName() + "' but received " + "a " + value.getClass().getSimpleName() + "-typed value"); } return finalValue; } else { // nested annotation if (!(value instanceof AnnotationDesc)) { throw new AnnotationException("Annotation '" + annotationClass.getSimpleName() + "' requires a " + annotationAttribute.getType().getSimpleName() + "-typed value for attribute '" + annotationAttribute.getName() + "' but received " + "a " + value.getClass().getSimpleName() + "-typed value"); } return createProxy((AnnotationDesc) value, engineImportService); } } if (!value.getClass().isArray()) { throw new AnnotationException("Annotation '" + annotationClass.getSimpleName() + "' requires a " + annotationAttribute.getType().getSimpleName() + "-typed value for attribute '" + annotationAttribute.getName() + "' but received " + "a " + value.getClass().getSimpleName() + "-typed value"); } Object array = Array.newInstance(annotationAttribute.getType().getComponentType(), Array.getLength(value)); for (int i = 0; i < Array.getLength(value); i++) { Object arrayValue = Array.get(value, i); if (arrayValue == null) { throw new AnnotationException("Annotation '" + annotationClass.getSimpleName() + "' requires a " + "non-null value for array elements for attribute '" + annotationAttribute.getName() + "'"); } SimpleTypeCaster caster = SimpleTypeCasterFactory.getCaster(arrayValue.getClass(), annotationAttribute.getType().getComponentType()); Object finalValue = caster.cast(arrayValue); if (finalValue == null) { throw new AnnotationException("Annotation '" + annotationClass.getSimpleName() + "' requires a " + annotationAttribute.getType().getComponentType().getSimpleName() + "-typed value for array elements for attribute '" + annotationAttribute.getName() + "' but received " + "a " + arrayValue.getClass().getSimpleName() + "-typed value"); } Array.set(array, i, finalValue); } return array; }