Skip to content

Commit

Permalink
TODO
Browse files Browse the repository at this point in the history
  • Loading branch information
bit4woo committed Apr 24, 2024
1 parent 4a27ed8 commit be184a4
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/runcmd/ClassUtils.java
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;
}
}
29 changes: 29 additions & 0 deletions src/runcmd/MessagePart.java
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());
}
}

0 comments on commit be184a4

Please sign in to comment.