List of usage examples for java.lang Class getSimpleName
public String getSimpleName()
From source file:io.wcm.caravan.pipeline.extensions.hal.filter.HalResourceFilters.java
/** * Converts the state of the HAL resource to an object of the given type and applies the provided function. * @param <S> Type of the HAL resource state * @param clazz Class type of the HAL resource state * @param function Function to apply on the object * @return Return value of the executed function *//*from w w w . j av a 2s . c o m*/ public static <S> HalResourcePredicate object(Class<S> clazz, Func1<S, Boolean> function) { return new HalResourcePredicate() { @Override public String getId() { return "OBJECT(" + clazz.getSimpleName() + ")"; } @Override public boolean apply(HalPath halPath, HalResource hal) { S object = OBJECT_MAPPER.convertValue(hal.getModel(), clazz); return function.call(object); } }; }
From source file:Main.java
private static void injectClassField(Class clazz, String fieldStr, long newValue) { try {//from ww w. j a v a2 s. com final Field field = clazz.getDeclaredField(fieldStr); if (field != null) { field.setAccessible(true); Object obj = null; field.set(obj, newValue); } } catch (Exception e) { Log.d("REFLECTION", clazz.getSimpleName() + " injection failed for field: " + fieldStr); } }
From source file:com.proofpoint.event.client.EventDataType.java
static void validateFieldValueType(Object value, Class<?> expectedType) { Preconditions.checkNotNull(value, "value is null"); Preconditions.checkArgument(expectedType.isInstance(value), "Expected 'value' to be a " + expectedType.getSimpleName() + " but it is a " + value.getClass().getName()); }
From source file:com.opengamma.elsql.ElSqlBundle.java
/** * Loads external SQL based for the specified type. * <p>/* ww w.j av a 2 s . c om*/ * This will load a file from the same package, with the ".elsql" extension * followed by one with the suffix "-$ConfigName.elsql". * * @param config the config, not null * @param type the type, not null * @return the bundle, not null * @throws IllegalArgumentException if the input cannot be parsed */ public static ElSqlBundle of(ElSqlConfig config, Class<?> type) { ArgumentChecker.notNull(config, "config"); ArgumentChecker.notNull(type, "type"); ClassPathResource baseResource = new ClassPathResource(type.getSimpleName() + ".elsql", type); ClassPathResource configResource = new ClassPathResource( type.getSimpleName() + "-" + config.getName() + ".elsql", type); return parse(config, baseResource, configResource); }
From source file:com.iflytek.edu.cloud.frame.utils.ReflectionUtils.java
/** * ??,Class?. public UserDao extends//from w w w .j a v a 2 s. com * HibernateDao<User,Long> * * @param clazz clazz The class to introspect * @param index the Index of the generic ddeclaration,start from 0. * @return the index generic declaration, or Object.class if cannot be * determined */ public static Class getSuperClassGenricType(final Class clazz, final int index) { Type genType = clazz.getGenericSuperclass(); if (!(genType instanceof ParameterizedType)) { logger.warn(clazz.getSimpleName() + "'s superclass not ParameterizedType"); return Object.class; } Type[] params = ((ParameterizedType) genType).getActualTypeArguments(); if (index >= params.length || index < 0) { logger.warn("Index: " + index + ", Size of " + clazz.getSimpleName() + "'s Parameterized Type: " + params.length); return Object.class; } if (!(params[index] instanceof Class)) { logger.warn(clazz.getSimpleName() + " not set the actual class on superclass generic parameter"); return Object.class; } return (Class) params[index]; }
From source file:com.liferay.wsrp.proxy.TypeConvertorUtil.java
public static Object convert(Object source, int sourceVersion) throws Exception { if (source == null) { return null; }/* ww w.j a v a2s .co m*/ String sourcePackage = _V1_PACKAGE; String destinationPackage = _V2_PACKAGE; if (sourceVersion == 2) { sourcePackage = _V2_PACKAGE; destinationPackage = _V1_PACKAGE; } Class<?> sourceClass = source.getClass(); String sourceClassName = sourceClass.getSimpleName(); Object destination = null; if (sourceClass.isArray()) { destination = source; Class<?> componentType = sourceClass.getComponentType(); if (componentType.getName().contains(sourcePackage)) { Object[] sourceArray = (Object[]) source; Class<?> destinationComponentType = Class .forName(destinationPackage + componentType.getSimpleName()); Object[] destinationArray = (Object[]) Array.newInstance(destinationComponentType, sourceArray.length); for (int i = 0; i < sourceArray.length; i++) { Object sourceArrayValue = sourceArray[i]; destinationArray[i] = convert(sourceArrayValue, sourceVersion); } destination = destinationArray; } } else if (sourceClass == CookieProtocol.class) { CookieProtocol cookieProtocol = (CookieProtocol) source; destination = oasis.names.tc.wsrp.v2.types.CookieProtocol.fromValue(cookieProtocol.getValue()); } else if (sourceClass == oasis.names.tc.wsrp.v2.types.CookieProtocol.class) { oasis.names.tc.wsrp.v2.types.CookieProtocol cookieProtocol = (oasis.names.tc.wsrp.v2.types.CookieProtocol) source; destination = CookieProtocol.fromValue(cookieProtocol.getValue()); } else if (sourceClass == StateChange.class) { StateChange stateChange = (StateChange) source; destination = oasis.names.tc.wsrp.v2.types.StateChange.fromValue(stateChange.getValue()); } else if (sourceClass == oasis.names.tc.wsrp.v2.types.StateChange.class) { oasis.names.tc.wsrp.v2.types.StateChange stateChange = (oasis.names.tc.wsrp.v2.types.StateChange) source; destination = StateChange.fromValue(stateChange.getValue()); } else { Class<?> destinationClass = Class.forName(destinationPackage + sourceClassName); destination = destinationClass.newInstance(); Map<String, Object> sourceChildren = PropertyUtils.describe(source); for (Map.Entry<String, Object> sourceChildEntry : sourceChildren.entrySet()) { String sourceChildName = sourceChildEntry.getKey(); if (sourceChildName.equals("class")) { continue; } Object sourceChild = sourceChildEntry.getValue(); if (sourceChild == null) { continue; } _convert(sourceVersion, sourcePackage, sourceClass, sourceChild, sourceChildName, destination); } } return destination; }
From source file:com.creapple.tms.mobiledriverconsole.utils.MDCUtils.java
/** * Generate LOG_TAG per each class//w ww . j a v a 2s. c o m * @param className * @return */ public static String getLogTag(Class className) { return Constants.PRE_LOG_ENTRY + className.getSimpleName() + Constants.POST_LOG_ENTRY; }
From source file:eu.crisis_economics.utilities.EnumDistribution.java
public static <T extends Enum<T>> EnumDistribution<T> // Immutable create(Class<T> token, String sourceFile) throws IOException { if (token == null) throw new NullArgumentException(); if (!token.isEnum()) throw new IllegalArgumentException("EnumDistribution: " + token.getSimpleName() + " is not an enum."); if (token.getEnumConstants().length == 0) throw new IllegalArgumentException("EnumDistribution: " + token.getSimpleName() + " is an empty enum."); EnumDistribution<T> result = new EnumDistribution<T>(); result.values = token.getEnumConstants(); result.probabilities = new EnumMap<T, Double>(token); Map<String, T> converter = new HashMap<String, T>(); final int numberOfValues = result.values.length; int[] valueIndices = new int[numberOfValues]; double[] valueProbabilities = new double[numberOfValues]; BitSet valueIsComitted = new BitSet(numberOfValues); {//from w w w.ja va 2 s . c o m int counter = 0; for (T value : result.values) { valueIndices[counter] = counter++; result.probabilities.put(value, 0.); converter.put(value.name(), value); } } BufferedReader reader = new BufferedReader(new FileReader(sourceFile)); try { String newLine; while ((newLine = reader.readLine()) != null) { if (newLine.isEmpty()) continue; StringTokenizer tokenizer = new StringTokenizer(newLine); final String name = tokenizer.nextToken(" ,:\t"), pStr = tokenizer.nextToken(" ,:\t"); if (tokenizer.hasMoreTokens()) throw new ParseException( "EnumDistribution: " + newLine + " is not a valid entry in " + sourceFile + ".", 0); final double p = Double.parseDouble(pStr); if (p < 0. || p > 1.) throw new IOException(pStr + " is not a valid probability for the value " + name); result.probabilities.put(converter.get(name), p); final int ordinal = converter.get(name).ordinal(); if (valueIsComitted.get(ordinal)) throw new ParseException("The value " + name + " appears twice in " + sourceFile, 0); valueProbabilities[converter.get(name).ordinal()] = p; valueIsComitted.set(ordinal, true); } { // Check sum of probabilities double sum = 0.; for (double p : valueProbabilities) sum += p; if (Math.abs(sum - 1.) > 1e2 * Math.ulp(1.)) throw new IllegalStateException("EnumDistribution: parser has succeeded, but the resulting " + "probaility sum (value " + sum + ") is not equal to 1."); } } catch (Exception e) { throw new IOException(e.getMessage()); } finally { reader.close(); } result.dice = new EnumeratedIntegerDistribution(valueIndices, valueProbabilities); return result; }
From source file:io.github.lxgaming.teleportbow.managers.CommandManager.java
public static boolean registerCommand(Class<? extends AbstractCommand> commandClass) { if (getCommandClasses().contains(commandClass)) { TeleportBow.getInstance().getLogger().warn("{} has already been registered", commandClass.getSimpleName()); return false; }// w w w . ja va 2s.c om getCommandClasses().add(commandClass); Optional<AbstractCommand> command = Toolbox.newInstance(commandClass); if (!command.isPresent()) { TeleportBow.getInstance().getLogger().error("{} failed to initialize", commandClass.getSimpleName()); return false; } getCommands().add(command.get()); Sponge.getCommandManager().register(TeleportBow.getInstance().getPluginContainer(), command.get(), command.get().getAliases().toArray(new String[0])); TeleportBow.getInstance().getLogger().debug("{} registered", commandClass.getSimpleName()); return true; }
From source file:de.tudarmstadt.ukp.dkpro.core.testing.IOTestRunner.java
public static void testOneWay2(Class<? extends CollectionReader> aReader, Class<? extends AnalysisComponent> aWriter, String aExpectedFile, String aOutputFile, String aFile, Object... aExtraParams) throws Exception { String outputFolder = aReader.getSimpleName() + "-" + FilenameUtils.getBaseName(aFile); if (DkproTestContext.get() != null) { outputFolder = DkproTestContext.get().getTestOutputFolderName(); }/* www. ja v a 2s . co m*/ File reference = new File("src/test/resources/" + aExpectedFile); File input = new File("src/test/resources/" + aFile); File output = new File("target/test-output/" + outputFolder); List<Object> extraReaderParams = new ArrayList<>(); extraReaderParams.add(ComponentParameters.PARAM_SOURCE_LOCATION); extraReaderParams.add(input); extraReaderParams.addAll(asList(aExtraParams)); CollectionReaderDescription reader = createReaderDescription(aReader, extraReaderParams.toArray()); List<Object> extraWriterParams = new ArrayList<>(); if (!ArrayUtils.contains(aExtraParams, ComponentParameters.PARAM_TARGET_LOCATION)) { extraWriterParams.add(ComponentParameters.PARAM_TARGET_LOCATION); extraWriterParams.add(output); } extraWriterParams.add(ComponentParameters.PARAM_STRIP_EXTENSION); extraWriterParams.add(true); extraWriterParams.addAll(asList(aExtraParams)); AnalysisEngineDescription writer = createEngineDescription(aWriter, extraWriterParams.toArray()); runPipeline(reader, writer); String expected = FileUtils.readFileToString(reference, "UTF-8"); String actual = FileUtils.readFileToString(new File(output, aOutputFile), "UTF-8"); assertEquals(expected.trim(), actual.trim()); }