/** * Ends the timing of the recent task started by {@link #start(java.lang.String)}. */ public static void end() { final Stopwatch root = STOPWATCH.get(); if (null == root) { return; // Donoting.... } final Stopwatch recent = getRecentRunning(root); if (null == recent) { return; } recent.setEndTime(System.currentTimeMillis()); // Ends timing }
/** * Starts a task timing with the specified task title. * * @param taskTitle the specified task title */ public static void start(final String taskTitle) { Stopwatch root = STOPWATCH.get(); if (null == root) { root = new Stopwatch(taskTitle); // Creates the root stopwatch STOPWATCH.set(root); return; } final Stopwatch recent = getRecentRunning(STOPWATCH.get()); if (null == recent) { return; } recent.addLeaf(new Stopwatch(taskTitle)); // Adds sub-stopwatch }
/** * Gets the recent running stopwatch with the specified parent stopwatch. * * @param parent the specified parent stopwatch * @return the recent stopwatch, returns {@code null} if not found */ private static Stopwatch getRecentRunning(final Stopwatch parent) { if (null == parent) { return null; } final List<Stopwatch> leaves = parent.getLeaves(); if (leaves.isEmpty()) { if (parent.isRunning()) { return parent; } else { return null; } } for (int i = leaves.size() - 1; i > -1; i--) { final Stopwatch leaf = leaves.get(i); if (leaf.isRunning()) { return getRecentRunning(leaf); } else { continue; } } return parent; }
/** * Ends the timing of the recent task started by {@link #start(java.lang.String)}. */ public static void end() { final Stopwatch root = STOPWATCH.get(); if (null == root) { return; // Donoting.... } final Stopwatch recent = getRecentRunning(root); if (null == recent) { return; } recent.setEndTime(System.currentTimeMillis()); // Ends timing }
/** * Starts a task timing with the specified task title. * * @param taskTitle the specified task title */ public static void start(final String taskTitle) { Stopwatch root = STOPWATCH.get(); if (null == root) { root = new Stopwatch(taskTitle); // Creates the root stopwatch STOPWATCH.set(root); return; } final Stopwatch recent = getRecentRunning(STOPWATCH.get()); if (null == recent) { return; } recent.addLeaf(new Stopwatch(taskTitle)); // Adds sub-stopwatch }
/** * Gets the recent running stopwatch with the specified parent stopwatch. * * @param parent the specified parent stopwatch * @return the recent stopwatch, returns {@code null} if not found */ private static Stopwatch getRecentRunning(final Stopwatch parent) { if (null == parent) { return null; } final List<Stopwatch> leaves = parent.getLeaves(); if (leaves.isEmpty()) { if (parent.isRunning()) { return parent; } else { return null; } } for (int i = leaves.size() - 1; i > -1; i--) { final Stopwatch leaf = leaves.get(i); if (leaf.isRunning()) { return getRecentRunning(leaf); } else { continue; } } return parent; }