code
stringlengths
23
201k
docstring
stringlengths
17
96.2k
func_name
stringlengths
0
235
language
stringclasses
1 value
repo
stringlengths
8
72
path
stringlengths
11
317
url
stringlengths
57
377
license
stringclasses
7 values
public boolean hasNext() { return stack.isEmpty() ? false : true; }
@return whether we have a next smallest number
hasNext
java
kdn251/interviews
leetcode/stack/BinarySearchTreeIterator.java
https://github.com/kdn251/interviews/blob/master/leetcode/stack/BinarySearchTreeIterator.java
MIT
@Override public Integer next() { return stack.pop().getInteger(); }
// This is the interface that allows for creating nested lists. // You should not implement it, or speculate about its implementation public interface NestedInteger { // @return true if this NestedInteger holds a single integer, rather than a nested list. public boolean isInteger(); // @return the single integer that this NestedInteger holds, if it holds a single integer // Return null if this NestedInteger holds a nested list public Integer getInteger(); // @return the nested list that this NestedInteger holds, if it holds a nested list // Return null if this NestedInteger holds a single integer public List<NestedInteger> getList(); }
next
java
kdn251/interviews
leetcode/stack/FlattenNestedListIterator.java
https://github.com/kdn251/interviews/blob/master/leetcode/stack/FlattenNestedListIterator.java
MIT
@Override public boolean hasNext() { while(!stack.isEmpty()) { NestedInteger current = stack.peek(); if(current.isInteger()) { return true; } stack.pop(); for(int i = current.getList().size() - 1; i >= 0; i--) { stack.push(current.getList().get(i)); } } return false; }
// This is the interface that allows for creating nested lists. // You should not implement it, or speculate about its implementation public interface NestedInteger { // @return true if this NestedInteger holds a single integer, rather than a nested list. public boolean isInteger(); // @return the single integer that this NestedInteger holds, if it holds a single integer // Return null if this NestedInteger holds a nested list public Integer getInteger(); // @return the nested list that this NestedInteger holds, if it holds a nested list // Return null if this NestedInteger holds a single integer public List<NestedInteger> getList(); }
hasNext
java
kdn251/interviews
leetcode/stack/FlattenNestedListIterator.java
https://github.com/kdn251/interviews/blob/master/leetcode/stack/FlattenNestedListIterator.java
MIT
public int maxPathSum(TreeNode root) { maxPathSumRecursive(root); return max; }
Definition for a binary tree node. public class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { val = x; } }
maxPathSum
java
kdn251/interviews
leetcode/tree/BinaryTreeMaximumPathSum.java
https://github.com/kdn251/interviews/blob/master/leetcode/tree/BinaryTreeMaximumPathSum.java
MIT
private int maxPathSumRecursive(TreeNode root) { if(root == null) { return 0; } int left = Math.max(maxPathSumRecursive(root.left), 0); int right = Math.max(maxPathSumRecursive(root.right), 0); max = Math.max(max, root.val + left + right); return root.val + Math.max(left, right); }
Definition for a binary tree node. public class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { val = x; } }
maxPathSumRecursive
java
kdn251/interviews
leetcode/tree/BinaryTreeMaximumPathSum.java
https://github.com/kdn251/interviews/blob/master/leetcode/tree/BinaryTreeMaximumPathSum.java
MIT
public List<String> binaryTreePaths(TreeNode root) { List<String> result = new ArrayList<String>(); if(root == null) { return result; } helper(new String(), root, result); return result; }
Definition for a binary tree node. public class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { val = x; } }
binaryTreePaths
java
kdn251/interviews
leetcode/tree/BinaryTreePaths.java
https://github.com/kdn251/interviews/blob/master/leetcode/tree/BinaryTreePaths.java
MIT
public void helper(String current, TreeNode root, List<String> result) { if(root.left == null && root.right == null) { result.add(current + root.val); } if(root.left != null) { helper(current + root.val + "->", root.left, result); } if(root.right != null) { helper(current + root.val + "->", root.right, result); } }
Definition for a binary tree node. public class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { val = x; } }
helper
java
kdn251/interviews
leetcode/tree/BinaryTreePaths.java
https://github.com/kdn251/interviews/blob/master/leetcode/tree/BinaryTreePaths.java
MIT
public TreeNode inorderSuccessor(TreeNode root, TreeNode p) { TreeNode successor = null; while(root != null) { if(p.val < root.val) { successor = root; root = root.left; } else { root = root.right; } } return successor; }
Definition for a binary tree node. public class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { val = x; } }
inorderSuccessor
java
kdn251/interviews
leetcode/tree/InorderSuccessorInBST.java
https://github.com/kdn251/interviews/blob/master/leetcode/tree/InorderSuccessorInBST.java
MIT
public TreeNode invertTree(TreeNode root) { if(root == null) { return root; } TreeNode temp = root.left; root.left = invertTree(root.right); root.right = invertTree(temp); return root; }
Definition for a binary tree node. public class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { val = x; } }
invertTree
java
kdn251/interviews
leetcode/tree/InvertBinaryTree.java
https://github.com/kdn251/interviews/blob/master/leetcode/tree/InvertBinaryTree.java
MIT
public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { if(root == null || root == p || root == q) { return root; } TreeNode left = lowestCommonAncestor(root.left, p, q); TreeNode right = lowestCommonAncestor(root.right, p, q); if(left != null && right != null) { return root; } return left == null ? right : left; }
Definition for a binary tree node. public class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { val = x; } }
lowestCommonAncestor
java
kdn251/interviews
leetcode/tree/LowestCommonAncestorOfABinaryTree.java
https://github.com/kdn251/interviews/blob/master/leetcode/tree/LowestCommonAncestorOfABinaryTree.java
MIT
public int sumOfLeftLeaves(TreeNode root) { if(root == null) { return 0; } int total = 0; if(root.left != null) { if(root.left.left == null && root.left.right == null) { total += root.left.val; } else { total += sumOfLeftLeaves(root.left); } } total += sumOfLeftLeaves(root.right); return total; }
Definition for a binary tree node. public class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { val = x; } }
sumOfLeftLeaves
java
kdn251/interviews
leetcode/tree/SumOfLeftLeaves.java
https://github.com/kdn251/interviews/blob/master/leetcode/tree/SumOfLeftLeaves.java
MIT
public TreeNode trimBST(TreeNode root, int L, int R) { if(root == null) { return root; } if(root.val < L) { return trimBST(root.right, L, R); } if(root.val > R) { return trimBST(root.left, L, R); } root.left = trimBST(root.left, L, R); root.right = trimBST(root.right, L, R); return root; }
Definition for a binary tree node. public class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { val = x; } }
trimBST
java
kdn251/interviews
leetcode/tree/TrimABinarySearchTree.java
https://github.com/kdn251/interviews/blob/master/leetcode/tree/TrimABinarySearchTree.java
MIT
public boolean isValidBST(TreeNode root) { if(root == null) { return true; } return validBSTRecursive(root, Long.MIN_VALUE, Long.MAX_VALUE); }
Definition for a binary tree node. public class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { val = x; } }
isValidBST
java
kdn251/interviews
leetcode/tree/ValidateBinarySearchTree.java
https://github.com/kdn251/interviews/blob/master/leetcode/tree/ValidateBinarySearchTree.java
MIT
public boolean validBSTRecursive(TreeNode root, long minValue, long maxValue) { if(root == null) { return true; } else if(root.val >= maxValue || root.val <= minValue) { return false; } else { return validBSTRecursive(root.left, minValue, root.val) && validBSTRecursive(root.right, root.val, maxValue); } }
Definition for a binary tree node. public class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { val = x; } }
validBSTRecursive
java
kdn251/interviews
leetcode/tree/ValidateBinarySearchTree.java
https://github.com/kdn251/interviews/blob/master/leetcode/tree/ValidateBinarySearchTree.java
MIT
public boolean hasCycle(ListNode head) { if(head == null || head.next == null) { return false; } ListNode slow = head; ListNode fast = head.next; while(fast != null && fast.next != null && fast != slow) { slow = slow.next; fast = fast.next.next; } return fast == slow; }
Definition for singly-linked list. class ListNode { int val; ListNode next; ListNode(int x) { val = x; next = null; } }
hasCycle
java
kdn251/interviews
leetcode/two-pointers/LinkedListCycle.java
https://github.com/kdn251/interviews/blob/master/leetcode/two-pointers/LinkedListCycle.java
MIT
public static void main(String[] args) { Scanner input = new Scanner(System.in); int numberOfTestCases = input.nextInt(); while (numberOfTestCases != 0) { int[] numbers = new int[10]; int number = input.nextInt(); for (int i = number; i > 0; i--) { int j = i; while (j != 0) { numbers[j % 10]++; j = j / 10; } } for (int i = 0; i < 10; i++) { if (i != 0) { System.out.print(" "); } System.out.print(numbers[i]); } System.out.println(); numberOfTestCases--; } }
Trung is bored with his mathematics homeworks. He takes a piece of chalk and starts writing a sequence of consecutive integers starting with 1 to N (1 < N < 10000). After that, he counts the number of times each digit (0 to 9) appears in the sequence. For example, with N = 13, the sequence is: 12345678910111213 In this sequence, 0 appears once, 1 appears 6 times, 2 appears 2 times, 3 appears 3 times, and each digit from 4 to 9 appears once. After playing for a while, Trung gets bored again. He now wants to write a program to do this for him. Your task is to help him with writing this program. Input The input file consists of several data sets. The first line of the input file contains the number of data sets which is a positive integer and is not bigger than 20. The following lines describe the data sets. For each test case, there is one single line containing the number N. Output For each test case, write sequentially in one line the number of digit 0, 1, . . . 9 separated by a space. Sample Input 2 3 13 Sample Output 0 1 1 1 0 0 0 0 0 0 1 6 2 2 1 1 1 1 1 1
main
java
kdn251/interviews
uva/DigitCounting.java
https://github.com/kdn251/interviews/blob/master/uva/DigitCounting.java
MIT
public static void premain(String agentArgs, Instrumentation inst) { agentmain(agentArgs, inst); }
Premain-Class for the Arex agent. <p>The JVM loads the class onto the application's classloader, and then the agent needs to append jars from its internal directory: bootstrap/ to the bootstrap classloader.
premain
java
arextest/arex-agent-java
arex-agent/src/main/java/io/arex/agent/ArexAgent.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent/src/main/java/io/arex/agent/ArexAgent.java
Apache-2.0
public static void agentmain(String agentArgs, Instrumentation inst) { init(inst, agentArgs); }
Premain-Class for the Arex agent. <p>The JVM loads the class onto the application's classloader, and then the agent needs to append jars from its internal directory: bootstrap/ to the bootstrap classloader.
agentmain
java
arextest/arex-agent-java
arex-agent/src/main/java/io/arex/agent/ArexAgent.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent/src/main/java/io/arex/agent/ArexAgent.java
Apache-2.0
private static void init(Instrumentation inst, String agentArgs) { try { printAgentInfo(); /* * The jars that need to be added to the bootstrap classloader * are packaged in the /bootstrap directory inside the arex-agent.jar package. * These jars should be added to the bootstrap classloader in advance. */ installBootstrapJar(inst); AgentInitializer.initialize(inst, getJarFile(ArexAgent.class), agentArgs, ArexAgent.class.getClassLoader()); } catch (Exception ex) { System.out.printf("%s [AREX] Agent initialize error, stacktrace: %s%n", getCurrentTime(), ex); } }
Premain-Class for the Arex agent. <p>The JVM loads the class onto the application's classloader, and then the agent needs to append jars from its internal directory: bootstrap/ to the bootstrap classloader.
init
java
arextest/arex-agent-java
arex-agent/src/main/java/io/arex/agent/ArexAgent.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent/src/main/java/io/arex/agent/ArexAgent.java
Apache-2.0
private static synchronized void installBootstrapJar(Instrumentation inst) throws Exception { File agentJarFile = getJarFile(ArexAgent.class); List<File> nestedBootStrapJars = JarUtils.extractNestedBootStrapJar(agentJarFile); for (File bootStrapFile : nestedBootStrapJars) { inst.appendToBootstrapClassLoaderSearch(new JarFile(bootStrapFile, false)); } }
Premain-Class for the Arex agent. <p>The JVM loads the class onto the application's classloader, and then the agent needs to append jars from its internal directory: bootstrap/ to the bootstrap classloader.
installBootstrapJar
java
arextest/arex-agent-java
arex-agent/src/main/java/io/arex/agent/ArexAgent.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent/src/main/java/io/arex/agent/ArexAgent.java
Apache-2.0
private static synchronized File getJarFile(Class<?> clazz) throws Exception { CodeSource codeSource = clazz.getProtectionDomain().getCodeSource(); if (codeSource == null) { throw new IllegalStateException("could not get agent jar location"); } return new File(codeSource.getLocation().toURI()); }
Premain-Class for the Arex agent. <p>The JVM loads the class onto the application's classloader, and then the agent needs to append jars from its internal directory: bootstrap/ to the bootstrap classloader.
getJarFile
java
arextest/arex-agent-java
arex-agent/src/main/java/io/arex/agent/ArexAgent.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent/src/main/java/io/arex/agent/ArexAgent.java
Apache-2.0
public static void init(Instrumentation inst, File agent) { try { printAgentInfo(); /* * The jars that need to be added to the bootstrap classloader * are packaged in the /bootstrap directory inside the arex-agent.jar package. * These jars should be added to the bootstrap classloader in advance. */ installBootstrapJar(inst); AgentInitializer.initialize(inst, agent, "", ArexAgent.class.getClassLoader()); } catch (Exception ex) { System.out.printf("%s [AREX] Agent initialize error, stacktrace: %s%n", getCurrentTime(), ex); } }
Premain-Class for the Arex agent. <p>The JVM loads the class onto the application's classloader, and then the agent needs to append jars from its internal directory: bootstrap/ to the bootstrap classloader.
init
java
arextest/arex-agent-java
arex-agent/src/main/java/io/arex/agent/ArexAgent.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent/src/main/java/io/arex/agent/ArexAgent.java
Apache-2.0
private static void printAgentInfo() { String agentVersion = ArexAgent.class.getPackage().getImplementationVersion(); System.out.printf("%s [AREX] Agent-v%s starts initialization...%n", getCurrentTime(), agentVersion); if (agentVersion != null) { System.setProperty(AGENT_VERSION, agentVersion); } }
Premain-Class for the Arex agent. <p>The JVM loads the class onto the application's classloader, and then the agent needs to append jars from its internal directory: bootstrap/ to the bootstrap classloader.
printAgentInfo
java
arextest/arex-agent-java
arex-agent/src/main/java/io/arex/agent/ArexAgent.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent/src/main/java/io/arex/agent/ArexAgent.java
Apache-2.0
private static String getCurrentTime() { return LocalDateTime.now().format(DATE_TIME_FORMATTER); }
Premain-Class for the Arex agent. <p>The JVM loads the class onto the application's classloader, and then the agent needs to append jars from its internal directory: bootstrap/ to the bootstrap classloader.
getCurrentTime
java
arextest/arex-agent-java
arex-agent/src/main/java/io/arex/agent/ArexAgent.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent/src/main/java/io/arex/agent/ArexAgent.java
Apache-2.0
public static void initialize(Instrumentation inst, File agentFile, String agentArgs, ClassLoader parentClassLoader) throws Exception { if (classLoader != null) { return; } initializeSimpleLoggerConfig(agentFile.getParent()); File[] extensionFiles = getExtensionJarFiles(agentFile); classLoader = new AgentClassLoader(agentFile, parentClassLoader, extensionFiles); InstrumentationHolder.setAgentClassLoader(classLoader); InstrumentationHolder.setInstrumentation(inst); InstrumentationHolder.setAgentFile(agentFile); AgentInstaller installer = createAgentInstaller(inst, agentFile, agentArgs); addJarToLoaderSearch(agentFile, extensionFiles); installer.install(); }
@param parentClassLoader Normally, the parentClassLoader should be ClassLoaders.AppClassLoader.
initialize
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/AgentInitializer.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/AgentInitializer.java
Apache-2.0
private static void addJarToLoaderSearch(File agentFile, File[] extensionFiles) { AdviceClassesCollector.INSTANCE.addJarToLoaderSearch(agentFile); if (extensionFiles == null) { return; } for (File file : extensionFiles) { AdviceClassesCollector.INSTANCE.addJarToLoaderSearch(file); } }
@param parentClassLoader Normally, the parentClassLoader should be ClassLoaders.AppClassLoader.
addJarToLoaderSearch
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/AgentInitializer.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/AgentInitializer.java
Apache-2.0
private static File[] getExtensionJarFiles(File jarFile) { String extensionDir = jarFile.getParent() + "/extensions/"; return new File(extensionDir).listFiles(AgentInitializer::isJar); }
@param parentClassLoader Normally, the parentClassLoader should be ClassLoaders.AppClassLoader.
getExtensionJarFiles
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/AgentInitializer.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/AgentInitializer.java
Apache-2.0
private static boolean isJar(File f) { return f.isFile() && f.getName().endsWith(".jar"); }
@param parentClassLoader Normally, the parentClassLoader should be ClassLoaders.AppClassLoader.
isJar
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/AgentInitializer.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/AgentInitializer.java
Apache-2.0
private static AgentInstaller createAgentInstaller(Instrumentation inst, File file, String agentArgs) throws Exception { Class<?> clazz = classLoader.loadClass("io.arex.agent.instrumentation.InstrumentationInstaller"); Constructor<?> constructor = clazz.getDeclaredConstructor(Instrumentation.class, File.class, String.class); return (AgentInstaller) constructor.newInstance(inst, file, agentArgs); }
@param parentClassLoader Normally, the parentClassLoader should be ClassLoaders.AppClassLoader.
createAgentInstaller
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/AgentInitializer.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/AgentInitializer.java
Apache-2.0
private static void initializeSimpleLoggerConfig(String agentFileParent) { System.setProperty(ConfigConstants.SIMPLE_LOGGER_SHOW_DATE_TIME, Boolean.TRUE.toString()); System.setProperty(ConfigConstants.SIMPLE_LOGGER_DATE_TIME_FORMAT, SIMPLE_DATE_FORMAT_MILLIS); String logPath = System.getProperty(ConfigConstants.LOG_PATH); if (StringUtil.isEmpty(logPath)) { logPath = agentFileParent + "/logs"; System.setProperty(ConfigConstants.LOG_PATH, logPath); } Path filePath = Paths.get(logPath); if (Files.notExists(filePath)) { try { Files.createDirectories(filePath); } catch (IOException e) { System.err.printf("%s [AREX] Failed to create log directory: %s%n", LocalDateTime.now().format(DateTimeFormatter.ofPattern(SIMPLE_DATE_FORMAT_MILLIS)), logPath); return; } } String logFilePath = logPath + "/arex." + LocalDate.now().format(DateTimeFormatter.ISO_LOCAL_DATE) + ".log"; System.setProperty(ConfigConstants.SIMPLE_LOGGER_FILE, logFilePath); }
@param parentClassLoader Normally, the parentClassLoader should be ClassLoaders.AppClassLoader.
initializeSimpleLoggerConfig
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/AgentInitializer.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/AgentInitializer.java
Apache-2.0
public static String get(boolean createIfAbsent) { String messageId = TRACE_CONTEXT.get(); if (messageId == null && createIfAbsent) { messageId = idGenerator.next(); TRACE_CONTEXT.set(messageId); } return messageId; }
This method can only be called at the service entrance
get
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/TraceContextManager.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/TraceContextManager.java
Apache-2.0
public static String remove() { String messageId = TRACE_CONTEXT.get(); TRACE_CONTEXT.remove(); return messageId; }
This method can only be called at the service entrance
remove
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/TraceContextManager.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/TraceContextManager.java
Apache-2.0
public static String generateId() { return idGenerator.next(); }
This method can only be called at the service entrance
generateId
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/TraceContextManager.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/TraceContextManager.java
Apache-2.0
public String next() { return PREFIX.concat(String.valueOf(getNowMillis())).concat(String.valueOf(COUNTER_UPDATER.getAndIncrement(this))); }
This method can only be called at the service entrance
next
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/TraceContextManager.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/TraceContextManager.java
Apache-2.0
private long getNowMillis() { return System.nanoTime() / 1000000; }
This method can only be called at the service entrance
getNowMillis
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/TraceContextManager.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/TraceContextManager.java
Apache-2.0
private static void wrapRunnableField(Runnable runnable) { try { Class<? extends Runnable> runnableClass = runnable.getClass(); Optional<Field> originalRunnableFieldOpt = COMPARABLE_RUNNABLE_FIELD_MAP.computeIfAbsent(runnableClass.getName(), k -> { for (Field declaredField : runnableClass.getDeclaredFields()) { Class<?> declaredFieldType = declaredField.getType(); if (declaredFieldType.isAssignableFrom(Runnable.class) && !declaredFieldType.isAssignableFrom(Comparable.class)) { declaredField.setAccessible(true); return Optional.of(declaredField); } } return Optional.empty(); }); if (originalRunnableFieldOpt.isPresent()) { Field originalRunnableField = originalRunnableFieldOpt.get(); Runnable originalRunnable = (Runnable) originalRunnableField.get(runnable); if (originalRunnable instanceof RunnableWrapper) { return; } RunnableWrapper runnableWrapper = new RunnableWrapper(originalRunnable); originalRunnableField.set(runnable, runnableWrapper); } } catch (Exception e) { if (EXECEPTION_LOGGED.compareAndSet(false, true)) { System.err.printf("wrap original runnable %s failed.%n", runnable.getClass().getName()); } } }
issue: https://github.com/arextest/arex-agent-java/issues/516 executor with PriorityQueue ex: class PriorityRunnable extends Runnable implements Comparable<PriorityRunnable> { private final Runnable run; private final int priority; } can't wrap the PriorityRunnable because queue need runnable implement Comparable, so we need to wrap the original runnable field.
wrapRunnableField
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/ctx/RunnableWrapper.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/ctx/RunnableWrapper.java
Apache-2.0
public Map<String, String> getTags() { return this.tags; }
Put tag into the tags map will throw {@link UnsupportedOperationException}. @return the tags map
getTags
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
Apache-2.0
public void setTags(Map<String, String> tags) { this.tags = tags; }
Put tag into the tags map will throw {@link UnsupportedOperationException}. @return the tags map
setTags
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
Apache-2.0
public String getId() { return this.id; }
Put tag into the tags map will throw {@link UnsupportedOperationException}. @return the tags map
getId
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
Apache-2.0
public MockCategoryType getCategoryType() { return this.categoryType; }
Put tag into the tags map will throw {@link UnsupportedOperationException}. @return the tags map
getCategoryType
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
Apache-2.0
public String getReplayId() { return this.replayId; }
Put tag into the tags map will throw {@link UnsupportedOperationException}. @return the tags map
getReplayId
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
Apache-2.0
public String getRecordId() { return this.recordId; }
Put tag into the tags map will throw {@link UnsupportedOperationException}. @return the tags map
getRecordId
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
Apache-2.0
public String getAppId() { return this.appId; }
Put tag into the tags map will throw {@link UnsupportedOperationException}. @return the tags map
getAppId
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
Apache-2.0
public int getRecordEnvironment() { return this.recordEnvironment; }
Put tag into the tags map will throw {@link UnsupportedOperationException}. @return the tags map
getRecordEnvironment
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
Apache-2.0
public String getRecordVersion() { return this.recordVersion; }
Put tag into the tags map will throw {@link UnsupportedOperationException}. @return the tags map
getRecordVersion
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
Apache-2.0
@Deprecated public void setRecordVersion(String recordVersion) { this.recordVersion = recordVersion; }
Put tag into the tags map will throw {@link UnsupportedOperationException}. @return the tags map
setRecordVersion
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
Apache-2.0
public long getCreationTime() { return this.creationTime; }
Put tag into the tags map will throw {@link UnsupportedOperationException}. @return the tags map
getCreationTime
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
Apache-2.0
public Mocker.Target getTargetRequest() { return this.targetRequest; }
Put tag into the tags map will throw {@link UnsupportedOperationException}. @return the tags map
getTargetRequest
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
Apache-2.0
public Mocker.Target getTargetResponse() { return this.targetResponse; }
Put tag into the tags map will throw {@link UnsupportedOperationException}. @return the tags map
getTargetResponse
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
Apache-2.0
public String getOperationName() { return this.operationName; }
Put tag into the tags map will throw {@link UnsupportedOperationException}. @return the tags map
getOperationName
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
Apache-2.0
public void setId(String id) { this.id = id; }
Put tag into the tags map will throw {@link UnsupportedOperationException}. @return the tags map
setId
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
Apache-2.0
public void setCategoryType(MockCategoryType categoryType) { this.categoryType = categoryType; }
Put tag into the tags map will throw {@link UnsupportedOperationException}. @return the tags map
setCategoryType
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
Apache-2.0
public void setReplayId(String replayId) { this.replayId = replayId; }
Put tag into the tags map will throw {@link UnsupportedOperationException}. @return the tags map
setReplayId
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
Apache-2.0
public void setRecordId(String recordId) { this.recordId = recordId; }
Put tag into the tags map will throw {@link UnsupportedOperationException}. @return the tags map
setRecordId
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
Apache-2.0
public void setAppId(String appId) { this.appId = appId; }
Put tag into the tags map will throw {@link UnsupportedOperationException}. @return the tags map
setAppId
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
Apache-2.0
public void setRecordEnvironment(int recordEnvironment) { this.recordEnvironment = recordEnvironment; }
Put tag into the tags map will throw {@link UnsupportedOperationException}. @return the tags map
setRecordEnvironment
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
Apache-2.0
public void setCreationTime(long creationTime) { this.creationTime = creationTime; }
Put tag into the tags map will throw {@link UnsupportedOperationException}. @return the tags map
setCreationTime
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
Apache-2.0
public void setTargetRequest(Mocker.Target targetRequest) { this.targetRequest = targetRequest; }
Put tag into the tags map will throw {@link UnsupportedOperationException}. @return the tags map
setTargetRequest
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
Apache-2.0
public void setTargetResponse(Mocker.Target targetResponse) { this.targetResponse = targetResponse; }
Put tag into the tags map will throw {@link UnsupportedOperationException}. @return the tags map
setTargetResponse
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
Apache-2.0
public void setOperationName(String operationName) { this.operationName = operationName; }
Put tag into the tags map will throw {@link UnsupportedOperationException}. @return the tags map
setOperationName
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
Apache-2.0
public boolean isNeedMerge() { return needMerge; }
Put tag into the tags map will throw {@link UnsupportedOperationException}. @return the tags map
isNeedMerge
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
Apache-2.0
public void setNeedMerge(boolean needMerge) { this.needMerge = needMerge; }
Put tag into the tags map will throw {@link UnsupportedOperationException}. @return the tags map
setNeedMerge
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
Apache-2.0
public boolean isMatched() { return matched.get(); }
Put tag into the tags map will throw {@link UnsupportedOperationException}. @return the tags map
isMatched
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
Apache-2.0
public void setMatched(boolean matched) { this.matched.compareAndSet(false, matched); }
Put tag into the tags map will throw {@link UnsupportedOperationException}. @return the tags map
setMatched
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
Apache-2.0
@Override public int getAccurateMatchKey() { return this.accurateMatchKey; }
Put tag into the tags map will throw {@link UnsupportedOperationException}. @return the tags map
getAccurateMatchKey
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
Apache-2.0
@Override public void setAccurateMatchKey(int accurateMatchKey) { this.accurateMatchKey = accurateMatchKey; }
Put tag into the tags map will throw {@link UnsupportedOperationException}. @return the tags map
setAccurateMatchKey
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
Apache-2.0
@Override public int getFuzzyMatchKey() { return this.fuzzyMatchKey; }
Put tag into the tags map will throw {@link UnsupportedOperationException}. @return the tags map
getFuzzyMatchKey
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
Apache-2.0
@Override public void setFuzzyMatchKey(int fuzzyMatchKey) { this.fuzzyMatchKey = fuzzyMatchKey; }
Put tag into the tags map will throw {@link UnsupportedOperationException}. @return the tags map
setFuzzyMatchKey
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ArexMocker.java
Apache-2.0
public static ComparableVersion of(String version) { if (StringUtil.isEmpty(version)) { return EMPTY; } final String[] split = StringUtil.split(version, SEPARATOR); List<Integer> list = new ArrayList<>(split.length); for (String s : split) { if (StringUtil.isNumeric(s)) { list.add(Integer.parseInt(s)); } else { list.add(StringUtil.getFirstNumeric(s)); } } return new ComparableVersion(list); }
supported format: number.number.number... 1.2.1 -> [1,2,1] 1.2.1-SNAPSHOT -> [1,2,1] 6.2.0.CR1 -> [6,2,0,1]
of
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ComparableVersion.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ComparableVersion.java
Apache-2.0
public List<Integer> getVersionItems() { return versionItems; }
supported format: number.number.number... 1.2.1 -> [1,2,1] 1.2.1-SNAPSHOT -> [1,2,1] 6.2.0.CR1 -> [6,2,0,1]
getVersionItems
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ComparableVersion.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ComparableVersion.java
Apache-2.0
@Override public int compareTo(ComparableVersion targetVersion) { if (targetVersion == null) { return 1; } Iterator<Integer> currentIterator = this.versionItems.iterator(); Iterator<Integer> targetIterator = targetVersion.getVersionItems().iterator(); while (currentIterator.hasNext() && targetIterator.hasNext()) { Integer currentPart = currentIterator.next(); Integer targetPart = targetIterator.next(); int result = currentPart.compareTo(targetPart); if (result != 0) { return result; } } if (currentIterator.hasNext()) { return 1; } if (targetIterator.hasNext()) { return -1; } return 0; }
supported format: number.number.number... 1.2.1 -> [1,2,1] 1.2.1-SNAPSHOT -> [1,2,1] 6.2.0.CR1 -> [6,2,0,1]
compareTo
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ComparableVersion.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ComparableVersion.java
Apache-2.0
public String getCode() { return code; }
Strict matching, Null if not matched
getCode
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/MockStrategyEnum.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/MockStrategyEnum.java
Apache-2.0
private void validateConstructorArguments() { TypeVariable<?>[] formals = rawType.getTypeParameters(); // check correct arity of actual type args if (formals.length != actualTypeArguments.length){ throw new MalformedParameterizedTypeException(); } for (int i = 0; i < actualTypeArguments.length; i++) { // check actuals against formals' bounds } }
ref: <a href="https://github.com/openjdk/jdk17/blob/master/src/java.base/share/classes/sun/reflect/generics/reflectiveObjects/ParameterizedTypeImpl.java"> sun/reflect/generics/reflectiveObjects/ParameterizedTypeImpl.java </a>
validateConstructorArguments
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ParameterizedTypeImpl.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ParameterizedTypeImpl.java
Apache-2.0
public static ParameterizedTypeImpl make(Class<?> rawType, Type[] actualTypeArguments, Type ownerType) { return new ParameterizedTypeImpl(rawType, actualTypeArguments, ownerType); }
Static factory. Given a (generic) class, actual type arguments and an owner type, creates a parameterized type. This class can be instantiated with a a raw type that does not represent a generic type, provided the list of actual type arguments is empty. If the ownerType argument is null, the declaring class of the raw type is used as the owner type. <p> This method throws a MalformedParameterizedTypeException under the following circumstances: If the number of actual type arguments (i.e., the size of the array <tt>typeArgs</tt>) does not correspond to the number of formal type arguments. If any of the actual type arguments is not an instance of the bounds on the corresponding formal. @param rawType the Class representing the generic type declaration being instantiated @param actualTypeArguments - a (possibly empty) array of types representing the actual type arguments to the parameterized type @param ownerType - the enclosing type, if known. @return An instance of <tt>ParameterizedType</tt> @throws MalformedParameterizedTypeException - if the instantiation is invalid
make
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ParameterizedTypeImpl.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ParameterizedTypeImpl.java
Apache-2.0
public Type[] getActualTypeArguments() { return actualTypeArguments.clone(); }
Returns an array of <tt>Type</tt> objects representing the actual type arguments to this type. <p>Note that in some cases, the returned array be empty. This can occur if this type represents a non-parameterized type nested within a parameterized type. @return an array of <tt>Type</tt> objects representing the actual type arguments to this type @throws <tt>TypeNotPresentException</tt> if any of the actual type arguments refers to a non-existent type declaration @throws <tt>MalformedParameterizedTypeException</tt> if any of the actual type parameters refer to a parameterized type that cannot be instantiated for any reason @since 1.5
getActualTypeArguments
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ParameterizedTypeImpl.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ParameterizedTypeImpl.java
Apache-2.0
public Class<?> getRawType() { return rawType; }
Returns the <tt>Type</tt> object representing the class or interface that declared this type. @return the <tt>Type</tt> object representing the class or interface that declared this type
getRawType
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ParameterizedTypeImpl.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ParameterizedTypeImpl.java
Apache-2.0
public Type getOwnerType() { return ownerType; }
Returns a <tt>Type</tt> object representing the type that this type is a member of. For example, if this type is <tt>O<T>.I<S></tt>, return a representation of <tt>O<T></tt>. <p>If this type is a top-level type, <tt>null</tt> is returned. @return a <tt>Type</tt> object representing the type that this type is a member of. If this type is a top-level type, <tt>null</tt> is returned @throws <tt>TypeNotPresentException</tt> if the owner type refers to a non-existent type declaration @throws <tt>MalformedParameterizedTypeException</tt> if the owner type refers to a parameterized type that cannot be instantiated for any reason
getOwnerType
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ParameterizedTypeImpl.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ParameterizedTypeImpl.java
Apache-2.0
@Override public boolean equals(Object o) { if (o instanceof ParameterizedType) { // Check that information is equivalent ParameterizedType that = (ParameterizedType) o; if (this == that) return true; Type thatOwner = that.getOwnerType(); Type thatRawType = that.getRawType(); if (false) { // Debugging boolean ownerEquality = (ownerType == null ? thatOwner == null : ownerType.equals(thatOwner)); boolean rawEquality = (rawType == null ? thatRawType == null : rawType.equals(thatRawType)); boolean typeArgEquality = Arrays.equals(actualTypeArguments, // avoid clone that.getActualTypeArguments()); for (Type t : actualTypeArguments) { System.out.printf("\t\t%s%s%n", t, t.getClass()); } System.out.printf("\towner %s\traw %s\ttypeArg %s%n", ownerEquality, rawEquality, typeArgEquality); return ownerEquality && rawEquality && typeArgEquality; } return Objects.equals(ownerType, thatOwner) && Objects.equals(rawType, thatRawType) && Arrays.equals(actualTypeArguments, // avoid clone that.getActualTypeArguments()); } else return false; }
Returns a <tt>Type</tt> object representing the type that this type is a member of. For example, if this type is <tt>O<T>.I<S></tt>, return a representation of <tt>O<T></tt>. <p>If this type is a top-level type, <tt>null</tt> is returned. @return a <tt>Type</tt> object representing the type that this type is a member of. If this type is a top-level type, <tt>null</tt> is returned @throws <tt>TypeNotPresentException</tt> if the owner type refers to a non-existent type declaration @throws <tt>MalformedParameterizedTypeException</tt> if the owner type refers to a parameterized type that cannot be instantiated for any reason
equals
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ParameterizedTypeImpl.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ParameterizedTypeImpl.java
Apache-2.0
@Override public int hashCode() { return Arrays.hashCode(actualTypeArguments) ^ Objects.hashCode(ownerType) ^ Objects.hashCode(rawType); }
Returns a <tt>Type</tt> object representing the type that this type is a member of. For example, if this type is <tt>O<T>.I<S></tt>, return a representation of <tt>O<T></tt>. <p>If this type is a top-level type, <tt>null</tt> is returned. @return a <tt>Type</tt> object representing the type that this type is a member of. If this type is a top-level type, <tt>null</tt> is returned @throws <tt>TypeNotPresentException</tt> if the owner type refers to a non-existent type declaration @throws <tt>MalformedParameterizedTypeException</tt> if the owner type refers to a parameterized type that cannot be instantiated for any reason
hashCode
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ParameterizedTypeImpl.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ParameterizedTypeImpl.java
Apache-2.0
public String toString() { StringBuilder sb = new StringBuilder(); if (ownerType != null) { if (ownerType instanceof Class) sb.append(((Class)ownerType).getName()); else sb.append(ownerType.toString()); sb.append("$"); if (ownerType instanceof ParameterizedTypeImpl) { // Find simple name of nested type by removing the // shared prefix with owner. sb.append(rawType.getName().replace( ((ParameterizedTypeImpl)ownerType).rawType.getName() + "$", "")); } else sb.append(rawType.getSimpleName()); } else sb.append(rawType.getName()); if (actualTypeArguments != null && actualTypeArguments.length > 0) { sb.append("<"); boolean first = true; for(Type t: actualTypeArguments) { if (!first) sb.append(", "); if (t != null) { sb.append(t.getTypeName()); } first = false; } sb.append(">"); } return sb.toString(); }
Returns a <tt>Type</tt> object representing the type that this type is a member of. For example, if this type is <tt>O<T>.I<S></tt>, return a representation of <tt>O<T></tt>. <p>If this type is a top-level type, <tt>null</tt> is returned. @return a <tt>Type</tt> object representing the type that this type is a member of. If this type is a top-level type, <tt>null</tt> is returned @throws <tt>TypeNotPresentException</tt> if the owner type refers to a non-existent type declaration @throws <tt>MalformedParameterizedTypeException</tt> if the owner type refers to a parameterized type that cannot be instantiated for any reason
toString
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ParameterizedTypeImpl.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/model/ParameterizedTypeImpl.java
Apache-2.0
public static boolean isEmpty(Collection<?> coll) { return (coll == null || coll.isEmpty()); }
Suppresses default constructor, ensuring non-instantiability.
isEmpty
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/util/CollectionUtil.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/util/CollectionUtil.java
Apache-2.0
public static boolean isNotEmpty(Collection<?> coll) { return !isEmpty(coll); }
Suppresses default constructor, ensuring non-instantiability.
isNotEmpty
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/util/CollectionUtil.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/util/CollectionUtil.java
Apache-2.0
@SuppressWarnings("unchecked") public static <E> List<E> emptyList() { return (List<E>) EMPTY_LIST; }
Suppresses default constructor, ensuring non-instantiability.
emptyList
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/util/CollectionUtil.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/util/CollectionUtil.java
Apache-2.0
public static <E> List<E> newArrayList() { return new ArrayList<>(); }
Suppresses default constructor, ensuring non-instantiability.
newArrayList
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/util/CollectionUtil.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/util/CollectionUtil.java
Apache-2.0
@SafeVarargs public static <E> List<E> newArrayList(E... elements) { if (elements == null) { return emptyList(); } List<E> list = new ArrayList<>(elements.length); Collections.addAll(list, elements); return list; }
Suppresses default constructor, ensuring non-instantiability.
newArrayList
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/util/CollectionUtil.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/util/CollectionUtil.java
Apache-2.0
@SafeVarargs public static <E> Set<E> newHashSet(E... elements) { if (elements == null) { return new HashSet<>(); } Set<E> set = new HashSet<>(elements.length); Collections.addAll(set, elements); return set; }
Suppresses default constructor, ensuring non-instantiability.
newHashSet
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/util/CollectionUtil.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/util/CollectionUtil.java
Apache-2.0
public static <V> List<List<V>> split(List<V> originalList, int splitCount) { if (isEmpty(originalList)) { return emptyList(); } int originalSize = originalList.size(); List<List<V>> splitList = new ArrayList<>(); if (originalSize < splitCount || splitCount == 0) { splitList.add(originalList); return splitList; } for (int i = 0; i < splitCount; i++) { List<V> list = new ArrayList<>(); splitList.add(list); } int index = 0; for (V value : originalList) { splitList.get(index).add(value); index = (index + 1) % splitCount; } return splitList; }
split to multiple list by split count
split
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/util/CollectionUtil.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/util/CollectionUtil.java
Apache-2.0
public static <V> List<V> filterNull(List<V> originalList) { if (isEmpty(originalList)) { return emptyList(); } List<V> filterList = new ArrayList<>(originalList.size()); for (V element : originalList) { if (element != null) { filterList.add(element); } } return filterList; }
split to multiple list by split count
filterNull
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/util/CollectionUtil.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/util/CollectionUtil.java
Apache-2.0
public static byte[] listToByteArray(List<byte[]> list) { int totalLength = 0; for (byte[] array : list) { totalLength += array.length; } byte[] result = new byte[totalLength]; int currentPos = 0; for (byte[] array : list) { System.arraycopy(array, 0, result, currentPos, array.length); currentPos += array.length; } return result; }
split to multiple list by split count
listToByteArray
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/util/CollectionUtil.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/util/CollectionUtil.java
Apache-2.0
public static void cleanDirectory(File directory) throws IOException { if (!directory.exists()) { String message = directory + " does not exist"; throw new IllegalArgumentException(message); } if (!directory.isDirectory()) { String message = directory + " is not a directory"; throw new IllegalArgumentException(message); } File[] files = directory.listFiles(); if (files == null) { // null if security restricted throw new IOException("Failed to list contents of " + directory); } IOException exception = null; for (File file : files) { try { forceDelete(file); } catch (IOException ioe) { exception = ioe; } } if (null != exception) { throw exception; } }
Cleans a directory without deleting it. @param directory directory to clean @throws IOException in case cleaning is unsuccessful
cleanDirectory
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/util/FileUtils.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/util/FileUtils.java
Apache-2.0
public static void forceDelete(File file) throws IOException { if (file.isDirectory()) { deleteDirectory(file); } else { boolean filePresent = file.exists(); if (!file.delete()) { if (!filePresent){ throw new FileNotFoundException("File does not exist: " + file); } String message = "Unable to delete file: " + file; throw new IOException(message); } } }
Deletes a file. If file is a directory, delete it and all sub-directories. <p> The difference between File.delete() and this method are: <ul> <li>A directory to be deleted does not have to be empty.</li> <li>You get exceptions when a file or directory cannot be deleted. (java.io.File methods returns a boolean)</li> </ul> @param file file or directory to delete, must not be {@code null} @throws NullPointerException if the directory is {@code null} @throws FileNotFoundException if the file was not found @throws IOException in case deletion is unsuccessful
forceDelete
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/util/FileUtils.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/util/FileUtils.java
Apache-2.0
public static void deleteDirectory(File directory) throws IOException { if (!directory.exists()) { return; } cleanDirectory(directory); if (!directory.delete()) { String message = "Unable to delete directory " + directory + "."; throw new IOException(message); } }
Deletes a directory recursively. @param directory directory to delete @throws IOException in case deletion is unsuccessful
deleteDirectory
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/util/FileUtils.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/util/FileUtils.java
Apache-2.0
public static void appendToClassLoaderSearch(ClassLoader classLoader, File jarFile) { try { if (classLoader instanceof URLClassLoader) { addURL.invoke(classLoader, jarFile.toURI().toURL()); } /* * Due to Java 8 vs java 9+ incompatibility issues * See https://stackoverflow.com/questions/46694600/java-9-compatability-issue-with-classloader-getsystemclassloader/51584718 */ ClassLoader urlClassLoader = ClassLoader.getSystemClassLoader(); if (!(urlClassLoader instanceof URLClassLoader)) { try (URLClassLoader tempClassLoader = new URLClassLoader(new URL[] {jarFile.toURI().toURL()}, urlClassLoader)) { addURL.invoke(tempClassLoader, jarFile.toURI().toURL()); } } else { addURL.invoke(urlClassLoader, jarFile.toURI().toURL()); } appendToAppClassLoaderSearch(classLoader, jarFile); } catch (Exception e) { System.err.printf("appendToClassLoaderSearch failed, classLoader: %s, jarFile: %s%n", classLoader.getClass().getName(), jarFile.getAbsolutePath()); } }
tomcat jdk <= 8, classLoader is ParallelWebappClassLoader, ClassLoader.getSystemClassLoader() is Launcher$AppClassLoader jdk > 8, classLoader is ParallelWebappClassLoader, ClassLoader.getSystemClassLoader() is ClassLoaders$AppClassLoader
appendToClassLoaderSearch
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/util/JarUtils.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/util/JarUtils.java
Apache-2.0
private static void appendToAppClassLoaderSearch(ClassLoader classLoader, File jarFile) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { Class<? extends ClassLoader> loaderClass = classLoader.getClass(); if (JdkUtils.isJdk11OrHigher() && ConfigConstants.APP_CLASSLOADER_NAME.equalsIgnoreCase(loaderClass.getName())) { Method classPathMethod = loaderClass.getDeclaredMethod("appendToClassPathForInstrumentation", String.class); classPathMethod.setAccessible(true); classPathMethod.invoke(classLoader, jarFile.getPath()); } }
append jar jdk.internal.loader.ClassLoaders.AppClassLoader if java version >= 11 need add jvm option:--add-opens=java.base/jdk.internal.loader=ALL-UNNAMED
appendToAppClassLoaderSearch
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/util/JarUtils.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/util/JarUtils.java
Apache-2.0
public static boolean isEmpty(Map<?, ?> map) { return map == null || map.isEmpty(); }
The largest power of two that can be represented as an {@code int}. @since 10.0
isEmpty
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/util/MapUtils.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/util/MapUtils.java
Apache-2.0
public static boolean isNotEmpty(Map<?, ?> map) { return !isEmpty(map); }
The largest power of two that can be represented as an {@code int}. @since 10.0
isNotEmpty
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/util/MapUtils.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/util/MapUtils.java
Apache-2.0
public static <K, V> Map<K, V> newHashMapWithExpectedSize(int expectedSize) { return new HashMap<>(capacity(expectedSize)); }
The largest power of two that can be represented as an {@code int}. @since 10.0
newHashMapWithExpectedSize
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/util/MapUtils.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/util/MapUtils.java
Apache-2.0
static int capacity(int expectedSize) { if (expectedSize < 3) { return expectedSize + 1; } if (expectedSize < MAX_POWER_OF_TWO) { // This is the calculation used in JDK8 to resize when a putAll // happens; it seems to be the most conservative calculation we // can make. 0.75 is the default load factor. return (int) (expectedSize / 0.75F + 1.0F); } // any large value return Integer.MAX_VALUE; }
The largest power of two that can be represented as an {@code int}. @since 10.0
capacity
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/util/MapUtils.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/util/MapUtils.java
Apache-2.0
public static <K> boolean getBoolean(final Map<? super K, ?> map, final K key) { return getBoolean(map, key, false); }
The largest power of two that can be represented as an {@code int}. @since 10.0
getBoolean
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/util/MapUtils.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/util/MapUtils.java
Apache-2.0
public static <K> boolean getBoolean(final Map<? super K, ?> map, final K key, boolean defaultValue) { if (isEmpty(map) || map.get(key) == null) { return defaultValue; } final Object answer = map.get(key); if (answer instanceof Boolean) { return (Boolean) answer; } if (answer instanceof String) { return Boolean.parseBoolean((String) answer); } if (answer instanceof Number) { final Number num = (Number) answer; return num.intValue() != 0; } return defaultValue; }
The largest power of two that can be represented as an {@code int}. @since 10.0
getBoolean
java
arextest/arex-agent-java
arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/util/MapUtils.java
https://github.com/arextest/arex-agent-java/blob/master/arex-agent-bootstrap/src/main/java/io/arex/agent/bootstrap/util/MapUtils.java
Apache-2.0