Skip to content

Commit

Permalink
= code cleanup
Browse files Browse the repository at this point in the history
- rename private methods
- inline private on-shot methods
- add more final modifier for vars
  • Loading branch information
oldratlee committed Aug 2, 2020
1 parent 920efe7 commit 8af8392
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions src/main/java/com/alibaba/ttl/threadpool/agent/TtlAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public final class TtlAgent {
* @see Logger#STDERR
* @see Logger#STDOUT
*/
public static void premain(String agentArgs, @NonNull Instrumentation inst) {
public static void premain(final String agentArgs, @NonNull final Instrumentation inst) {
kvs = splitCommaColonStringToKV(agentArgs);

Logger.setLoggerImplType(getLogImplTypeFromAgentArgs(kvs));
Expand Down Expand Up @@ -184,7 +184,7 @@ public static boolean isTtlAgentLoaded() {
* @since 2.10.1
*/
public static boolean isDisableInheritableForThreadPool() {
return isOptionSetOrFalse(kvs, TTL_AGENT_DISABLE_INHERITABLE_FOR_THREAD_POOL);
return isBooleanOptionSet(kvs, TTL_AGENT_DISABLE_INHERITABLE_FOR_THREAD_POOL, false);
}

/**
Expand All @@ -193,22 +193,14 @@ public static boolean isDisableInheritableForThreadPool() {
* @since 2.10.1
*/
public static boolean isEnableTimerTask() {
return isOptionSetOrTrue(kvs, TTL_AGENT_ENABLE_TIMER_TASK_KEY);
return isBooleanOptionSet(kvs, TTL_AGENT_ENABLE_TIMER_TASK_KEY, true);
}

private static boolean isOptionSetOrFalse(@Nullable final Map<String, String> kvs, @NonNull String key) {
return isOptionSetOrFalse(kvs, key, false);
}

private static boolean isOptionSetOrTrue(@Nullable final Map<String, String> kvs, @NonNull String key) {
return isOptionSetOrFalse(kvs, key, true);
}

private static boolean isOptionSetOrFalse(@Nullable final Map<String, String> kvs, @NonNull String key, boolean defaultValue) {
private static boolean isBooleanOptionSet(@Nullable final Map<String, String> kvs, @NonNull String key, boolean defaultValue) {
if (null == kvs) return defaultValue;

final boolean hasEnableKey = kvs.containsKey(key);
if (!hasEnableKey) return defaultValue;
final boolean containsKey = kvs.containsKey(key);
if (!containsKey) return defaultValue;

return !"false".equalsIgnoreCase(kvs.get(key));
}
Expand All @@ -217,8 +209,8 @@ private static boolean isOptionSetOrFalse(@Nullable final Map<String, String> kv
* Split to {@code json} like String({@code "k1:v1,k2:v2"}) to KV map({@code "k1"->"v1", "k2"->"v2"}).
*/
@NonNull
static Map<String, String> splitCommaColonStringToKV(@Nullable String commaColonString) {
Map<String, String> ret = new HashMap<String, String>();
static Map<String, String> splitCommaColonStringToKV(@Nullable final String commaColonString) {
final Map<String, String> ret = new HashMap<String, String>();
if (commaColonString == null || commaColonString.trim().length() == 0) return ret;

final String[] splitKvArray = commaColonString.trim().split("\\s*,\\s*");
Expand Down

0 comments on commit 8af8392

Please sign in to comment.