com.baidu.hugegraph.util.ReflectionUtil Java Examples
The following examples show how to use
com.baidu.hugegraph.util.ReflectionUtil.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PerfUtil.java From hugegraph-common with Apache License 2.0 | 6 votes |
public void profilePackage(String... packages) throws NotFoundException, IOException, ClassNotFoundException, CannotCompileException { Set<String> loadedClasses = new HashSet<>(); Iterator<ClassInfo> classes = ReflectionUtil.classes(packages); while (classes.hasNext()) { String cls = classes.next().getName(); // super class first for (String s : ReflectionUtil.superClasses(cls)) { if (!loadedClasses.contains(s)) { profileClass(s); loadedClasses.add(s); } } // self class if (!loadedClasses.contains(cls)) { profileClass(cls); loadedClasses.add(cls); } } }
Example #2
Source File: PerfUtil.java From hugegraph-common with Apache License 2.0 | 6 votes |
public void profileClass(String... classes) throws NotFoundException, CannotCompileException, ClassNotFoundException { ClassPool classPool = ClassPool.getDefault(); for (String cls : classes) { CtClass ctClass = classPool.get(cls); List<CtMethod> methods = ReflectionUtil.getMethodsAnnotatedWith( ctClass, Watched.class, false); for (CtMethod method : methods) { profile(method); } // load class and make it effective if (!methods.isEmpty()) { ctClass.toClass(); } } }
Example #3
Source File: ReflectionUtilTest.java From hugegraph-common with Apache License 2.0 | 6 votes |
@Test public void testIsSimpleType() { Assert.assertTrue(ReflectionUtil.isSimpleType(byte.class)); Assert.assertTrue(ReflectionUtil.isSimpleType(char.class)); Assert.assertTrue(ReflectionUtil.isSimpleType(short.class)); Assert.assertTrue(ReflectionUtil.isSimpleType(int.class)); Assert.assertTrue(ReflectionUtil.isSimpleType(long.class)); Assert.assertTrue(ReflectionUtil.isSimpleType(float.class)); Assert.assertTrue(ReflectionUtil.isSimpleType(double.class)); Assert.assertTrue(ReflectionUtil.isSimpleType(boolean.class)); Assert.assertTrue(ReflectionUtil.isSimpleType(Byte.class)); Assert.assertTrue(ReflectionUtil.isSimpleType(Character.class)); Assert.assertTrue(ReflectionUtil.isSimpleType(Short.class)); Assert.assertTrue(ReflectionUtil.isSimpleType(Integer.class)); Assert.assertTrue(ReflectionUtil.isSimpleType(Long.class)); Assert.assertTrue(ReflectionUtil.isSimpleType(Float.class)); Assert.assertTrue(ReflectionUtil.isSimpleType(Double.class)); Assert.assertTrue(ReflectionUtil.isSimpleType(Boolean.class)); Assert.assertTrue(ReflectionUtil.isSimpleType(String.class)); Assert.assertFalse(ReflectionUtil.isSimpleType(Object.class)); Assert.assertFalse(ReflectionUtil.isSimpleType(BaseUnitTest.class)); }
Example #4
Source File: ReflectionUtilTest.java From hugegraph-common with Apache License 2.0 | 6 votes |
@Test public void testGetMethodsAnnotatedWith() { List<Method> methods; methods = ReflectionUtil.getMethodsAnnotatedWith(Sub.class, Watched.class, false); methods.sort((m1, m2) -> m1.getName().compareTo(m2.getName())); Assert.assertEquals(2, methods.size()); Assert.assertEquals("func1", methods.get(0).getName()); Assert.assertEquals("func3", methods.get(1).getName()); methods = ReflectionUtil.getMethodsAnnotatedWith(Sub.class, Watched.class, true); methods.sort((m1, m2) -> m1.getName().compareTo(m2.getName())); Assert.assertEquals(3, methods.size()); Assert.assertEquals("func", methods.get(0).getName()); Assert.assertEquals("func1", methods.get(1).getName()); Assert.assertEquals("func3", methods.get(2).getName()); }
Example #5
Source File: ReflectionUtilTest.java From hugegraph-common with Apache License 2.0 | 6 votes |
@Test public void testClasses() throws IOException { @SuppressWarnings("unchecked") List<ClassInfo> classes = IteratorUtils.toList(ReflectionUtil.classes( "com.baidu.hugegraph.util")); Assert.assertEquals(16, classes.size()); classes.sort((c1, c2) -> c1.getName().compareTo(c2.getName())); Assert.assertEquals("com.baidu.hugegraph.util.Bytes", classes.get(0).getName()); Assert.assertEquals("com.baidu.hugegraph.util.CheckSocket", classes.get(1).getName()); Assert.assertEquals("com.baidu.hugegraph.util.CollectionUtil", classes.get(2).getName()); Assert.assertEquals("com.baidu.hugegraph.util.VersionUtil", classes.get(15).getName()); }
Example #6
Source File: GraphElement.java From hugegraph-client with Apache License 2.0 | 5 votes |
public GraphElement property(String name, Object value) { E.checkArgumentNotNull(name, "property name"); E.checkArgumentNotNull(value, "property value"); Class<?> clazz = value.getClass(); E.checkArgument(ReflectionUtil.isSimpleType(clazz) || clazz.equals(UUID.class) || clazz.equals(Date.class) || value instanceof List || value instanceof Set, "Invalid property value type: '%s'", clazz); this.properties.put(name, value); return this; }
Example #7
Source File: ReflectionUtilTest.java From hugegraph-common with Apache License 2.0 | 5 votes |
@Test public void testSuperClasses() throws NotFoundException { List<String> classes = ReflectionUtil.superClasses(Sub.class.getName()); Assert.assertEquals(2, classes.size()); classes.sort((c1, c2) -> c1.compareTo(c2)); Assert.assertEquals(Base.class.getName(), classes.get(0)); Assert.assertEquals(Object.class.getName(), classes.get(1)); }
Example #8
Source File: DataTypeUtil.java From hugegraph-loader with Apache License 2.0 | 4 votes |
public static boolean isSimpleValue(Object value) { if (value == null) { return false; } return ReflectionUtil.isSimpleType(value.getClass()); }