Java Code Examples for java.util.Stack#iterator()
The following examples show how to use
java.util.Stack#iterator() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ActivityUtils.java From DevUtils with Apache License 2.0 | 6 votes |
/** * 结束所有 Activity * @return {@link ActivityUtils} */ public ActivityUtils finishAllActivity() { synchronized (mActivityStacks) { // 保存新的堆栈, 防止出现同步问题 Stack<Activity> stack = new Stack<>(); stack.addAll(mActivityStacks); // 清空全部, 便于后续操作处理 mActivityStacks.clear(); // 进行遍历移除 Iterator<Activity> iterator = stack.iterator(); while (iterator.hasNext()) { Activity activity = iterator.next(); if (activity != null && !activity.isFinishing()) { activity.finish(); // 删除对应的 Item iterator.remove(); } } // 移除数据, 并且清空内存 stack.clear(); stack = null; } return this; }
Example 2
Source File: ShortestPath.java From CQL with GNU Affero General Public License v3.0 | 5 votes |
public List<E> pathTo(N v) { if (!hasPathTo(v)) { return null; } Stack<E> path = new Stack<>(); for (DirectedEdge<N, E> e = edgeTo.get(v); e != null; e = edgeTo.get(e.from)) { path.push(e.e); } Iterator<E> it = path.iterator(); List<E> ret = new LinkedList<>(); while (it.hasNext()) { ret.add(it.next()); } return Util.reverse(ret); // TODO aql apparently this is backwards }
Example 3
Source File: LauncherApplication.java From SoloPi with Apache License 2.0 | 5 votes |
/** * 清理无用Context * @param stack */ public void clearDestroyedContext(Stack<ContextInstanceWrapper> stack) { ReentrantReadWriteLock.WriteLock writeLock = null; // 查找对应锁 if (stack == openedActivity) { writeLock = ACTIVITY_STACK_LOCK.writeLock(); } else if (stack == openedService) { // 不修改,加读锁 writeLock = SERVICE_STACK_LOCK.writeLock(); } if (writeLock != null) { writeLock.lock(); } // 清理掉Destroy的Context Iterator<ContextInstanceWrapper> iterator = stack.iterator(); while (iterator.hasNext()) { ContextInstanceWrapper item = iterator.next(); if (!item.checkValid()) { iterator.remove(); } } if (writeLock != null) { writeLock.unlock(); } }
Example 4
Source File: ActivityUtils.java From DevUtils with Apache License 2.0 | 5 votes |
/** * 检测是否包含指定的 Activity * @param clazzs Class(Activity)[] * @return {@code true} yes, {@code false} no */ public boolean existActivitys(final Class<?>... clazzs) { if (clazzs != null && clazzs.length != 0) { synchronized (mActivityStacks) { // 保存新的堆栈, 防止出现同步问题 Stack<Activity> stack = new Stack<>(); stack.addAll(mActivityStacks); try { // 进行遍历判断 Iterator<Activity> iterator = stack.iterator(); while (iterator.hasNext()) { Activity activity = iterator.next(); if (activity != null && !activity.isFinishing()) { for (int i = 0, len = clazzs.length; i < len; i++) { if (clazzs[i] != null && activity.getClass().getName().equals(clazzs[i].getName())) { return true; } } } } } finally { // 移除数据, 并且清空内存 stack.clear(); stack = null; } } } return false; }
Example 5
Source File: ActivityUtils.java From DevUtils with Apache License 2.0 | 5 votes |
/** * 关闭指定类名 Activity * @param clazz Activity.class * @return {@link ActivityUtils} */ public ActivityUtils finishActivity(final Class<?> clazz) { if (clazz != null) { synchronized (mActivityStacks) { // 保存新的堆栈, 防止出现同步问题 Stack<Activity> stack = new Stack<>(); stack.addAll(mActivityStacks); // 清空全部, 便于后续操作处理 mActivityStacks.clear(); // 进行遍历移除 Iterator<Activity> iterator = stack.iterator(); while (iterator.hasNext()) { Activity activity = iterator.next(); // 判断是否想要关闭的 Activity if (activity != null) { if (activity.getClass() == clazz) { // 如果 Activity 没有 finish 则进行 finish if (!activity.isFinishing()) { activity.finish(); } // 删除对应的 Item iterator.remove(); } } else { // 删除对应的 Item iterator.remove(); } } // 把不符合条件的保存回去 mActivityStacks.addAll(stack); // 移除数据, 并且清空内存 stack.clear(); stack = null; } } return this; }
Example 6
Source File: ActivityUtils.java From DevUtils with Apache License 2.0 | 5 votes |
/** * 结束全部 Activity 除忽略的 Activity 外 * @param clazz Activity.class * @return {@link ActivityUtils} */ public ActivityUtils finishAllActivityToIgnore(final Class<?> clazz) { if (clazz != null) { synchronized (mActivityStacks) { // 保存新的堆栈, 防止出现同步问题 Stack<Activity> stack = new Stack<>(); stack.addAll(mActivityStacks); // 清空全部, 便于后续操作处理 mActivityStacks.clear(); // 进行遍历移除 Iterator<Activity> iterator = stack.iterator(); while (iterator.hasNext()) { Activity activity = iterator.next(); // 判断是否想要关闭的 Activity if (activity != null) { if (!(activity.getClass() == clazz)) { // 如果 Activity 没有 finish 则进行 finish if (!activity.isFinishing()) { activity.finish(); } // 删除对应的 Item iterator.remove(); } } else { // 删除对应的 Item iterator.remove(); } } // 把不符合条件的保存回去 mActivityStacks.addAll(stack); // 移除数据, 并且清空内存 stack.clear(); stack = null; } } return this; }
Example 7
Source File: RandomShoot.java From ShootOFF with GNU General Public License v3.0 | 5 votes |
private void saySubtargets() { final List<File> soundFiles = new ArrayList<>(); soundFiles.add(new File("sounds/voice/shootoff-shoot.wav")); final Stack<Integer> temp = new Stack<>(); temp.addAll(currentSubtargets); Collections.reverse(temp); final Iterator<Integer> it = temp.iterator(); while (it.hasNext()) { final Integer index = it.next(); if (!it.hasNext() && currentSubtargets.size() > 1) soundFiles.add(new File("sounds/voice/shootoff-and.wav")); final File targetNameSound = new File(String.format("sounds/voice/shootoff-%s.wav", subtargets.get(index))); if (targetNameSound.exists()) { soundFiles.add(targetNameSound); } else { // We don't have a voice actor sounds file for a target // subregion, fall back // to TTS saySubtargetsTTS(); return; } } super.playSounds(soundFiles); }
Example 8
Source File: StagedDeepening.java From algorithms-nutshell-2ed with MIT License | 5 votes |
/** * Helper routine to copy stacks which need to be maintained for linking * in solutions. * * @param existing stack to be copied. */ private static Stack<IMove> stackCopy(Stack<IMove> existing) { Stack<IMove> aCopy = new Stack<IMove>(); for (Iterator<IMove> it = existing.iterator(); it.hasNext(); ) { aCopy.push(it.next()); } return aCopy; }
Example 9
Source File: StagedDeepening.java From algorithms-nutshell-2ed with MIT License | 5 votes |
/** * Helper routine to copy stacks which need to be maintained for linking * in solutions. * * @param existing stack to be copied. */ private static Stack<IMove> stackCopy(Stack<IMove> existing) { Stack<IMove> aCopy = new Stack<IMove>(); for (Iterator<IMove> it = existing.iterator(); it.hasNext(); ) { aCopy.push(it.next()); } return aCopy; }
Example 10
Source File: ActivityUtils.java From DevUtils with Apache License 2.0 | 4 votes |
/** * 结束多个类名 Activity * @param clazzs Class(Activity)[] * @return {@link ActivityUtils} */ public ActivityUtils finishActivity(final Class<?>... clazzs) { if (clazzs != null && clazzs.length != 0) { synchronized (mActivityStacks) { // 保存新的堆栈, 防止出现同步问题 Stack<Activity> stack = new Stack<>(); stack.addAll(mActivityStacks); // 清空全部, 便于后续操作处理 mActivityStacks.clear(); // 判断是否销毁 boolean isRemove; // 进行遍历移除 Iterator<Activity> iterator = stack.iterator(); while (iterator.hasNext()) { Activity activity = iterator.next(); // 判断是否想要关闭的 Activity if (activity != null) { // 默认不需要销毁 isRemove = false; // 循环判断 for (int i = 0, len = clazzs.length; i < len; i++) { // 判断是否相同 if (activity.getClass() == clazzs[i]) { isRemove = true; break; } } // 判断是否销毁 if (isRemove) { // 如果 Activity 没有 finish 则进行 finish if (!activity.isFinishing()) { activity.finish(); } // 删除对应的 Item iterator.remove(); } } else { // 删除对应的 Item iterator.remove(); } } // 把不符合条件的保存回去 mActivityStacks.addAll(stack); // 移除数据, 并且清空内存 stack.clear(); stack = null; } } return this; }
Example 11
Source File: ActivityUtils.java From DevUtils with Apache License 2.0 | 4 votes |
/** * 结束全部 Activity 除忽略的 Activity 外 * @param clazzs Class(Activity)[] * @return {@link ActivityUtils} */ public ActivityUtils finishAllActivityToIgnore(final Class<?>... clazzs) { if (clazzs != null && clazzs.length != 0) { synchronized (mActivityStacks) { // 保存新的堆栈, 防止出现同步问题 Stack<Activity> stack = new Stack<>(); stack.addAll(mActivityStacks); // 清空全部, 便于后续操作处理 mActivityStacks.clear(); // 判断是否销毁 boolean isRemove; // 进行遍历移除 Iterator<Activity> iterator = stack.iterator(); while (iterator.hasNext()) { Activity activity = iterator.next(); // 判断是否想要关闭的 Activity if (activity != null) { // 默认需要销毁 isRemove = true; // 循环判断 for (int i = 0, len = clazzs.length; i < len; i++) { // 判断是否相同 if (activity.getClass() == clazzs[i]) { isRemove = false; break; } } // 判断是否销毁 if (isRemove) { // 如果 Activity 没有 finish 则进行 finish if (!activity.isFinishing()) { activity.finish(); } // 删除对应的 Item iterator.remove(); } } else { // 删除对应的 Item iterator.remove(); } } // 把不符合条件的保存回去 mActivityStacks.addAll(stack); // 移除数据, 并且清空内存 stack.clear(); stack = null; } } return this; }