From be184a4d45002597b3cd5e59acde37c805d2473d Mon Sep 17 00:00:00 2001 From: bit4woo Date: Wed, 24 Apr 2024 17:45:13 +0800 Subject: [PATCH] TODO --- src/runcmd/ClassUtils.java | 51 +++++++++++++++++++++++++++++++++++++ src/runcmd/MessagePart.java | 29 +++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 src/runcmd/ClassUtils.java create mode 100644 src/runcmd/MessagePart.java diff --git a/src/runcmd/ClassUtils.java b/src/runcmd/ClassUtils.java new file mode 100644 index 0000000..5c7d4d4 --- /dev/null +++ b/src/runcmd/ClassUtils.java @@ -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 getPublicStaticFinalStringFields(Class classObj) { + List 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 getStringFields(Class classObj) { + List 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; + } +} diff --git a/src/runcmd/MessagePart.java b/src/runcmd/MessagePart.java new file mode 100644 index 0000000..af1fa15 --- /dev/null +++ b/src/runcmd/MessagePart.java @@ -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 getPartList(){ + return ClassUtils.getPublicStaticFinalStringFields(MessagePart.class); + } + + public MessagePart() { + // TODO Auto-generated constructor stub + } + + public static void main(String[] args) { + System.out.println(getPartList()); + } +}