-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package runcmd; | ||
|
||
import java.lang.reflect.Field; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
|
||
public class ClassUtils { | ||
|
||
public ClassUtils() { | ||
// TODO Auto-generated constructor stub | ||
} | ||
|
||
public static List<String> getPublicStaticFinalStringFields(Class classObj) { | ||
List<String> result = new ArrayList<>(); | ||
Field[] fields = classObj.getDeclaredFields(); | ||
for (Field field : fields) { | ||
if (isPublicStaticFinalString(field)) { | ||
try { | ||
result.add((String) field.get(null)); | ||
} catch (IllegalAccessException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
public static List<String> getStringFields(Class classObj) { | ||
List<String> result = new ArrayList<>(); | ||
Field[] fields = classObj.getDeclaredFields(); | ||
for (Field field : fields) { | ||
if (field.getType() == String.class) { | ||
try { | ||
result.add((String) field.get(null)); | ||
} catch (IllegalAccessException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
private static boolean isPublicStaticFinalString(Field field) { | ||
int modifiers = field.getModifiers(); | ||
return java.lang.reflect.Modifier.isPublic(modifiers) | ||
&& java.lang.reflect.Modifier.isStatic(modifiers) | ||
&& java.lang.reflect.Modifier.isFinal(modifiers) | ||
&& field.getType() == String.class; | ||
} | ||
} |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package runcmd; | ||
|
||
import java.util.List; | ||
|
||
public class MessagePart { | ||
|
||
public static final String Host = "Host"; | ||
public static final String BaseURL = "BaseURL"; | ||
public static final String FullURL = "FullURL"; | ||
|
||
public static final String Request = "Request"; | ||
public static final String Response = "Response"; | ||
public static final String RequestHeaders = "RequestHeaders"; | ||
public static final String RequestBody = "RequestHeaders"; | ||
public static final String ResponseHeaders = "ResponseHeaders"; | ||
public static final String ResponseBody = "ResponseBody"; | ||
|
||
public static List<String> getPartList(){ | ||
return ClassUtils.getPublicStaticFinalStringFields(MessagePart.class); | ||
} | ||
|
||
public MessagePart() { | ||
// TODO Auto-generated constructor stub | ||
} | ||
|
||
public static void main(String[] args) { | ||
System.out.println(getPartList()); | ||
} | ||
} |