Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add function to reflect package, rename reflective initializer
- Loading branch information
Showing
3 changed files
with
35 additions
and
27 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
src/main/java/org/opentripplanner/reflect/ReflectionLibrary.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,28 @@ | |||
package org.opentripplanner.reflect; | |||
|
|||
import java.lang.reflect.Field; | |||
|
|||
public class ReflectionLibrary { | |||
|
|||
/** Concatenate all fields and values of a Java object. */ | |||
public static String dumpFields (Object object) { | |||
StringBuilder sb = new StringBuilder(); | |||
Class clazz = object.getClass(); | |||
sb.append("Summarizing "); | |||
sb.append(clazz.getSimpleName()); | |||
sb.append('\n'); | |||
for (Field field : clazz.getFields()) { | |||
sb.append(field.getName()); | |||
sb.append(" = "); | |||
try { | |||
String value = field.get(object).toString(); | |||
sb.append(value); | |||
} catch (IllegalAccessException ex) { | |||
sb.append("(non-public)"); | |||
} | |||
sb.append('\n'); | |||
} | |||
return sb.toString(); | |||
} | |||
|
|||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters