Java Code Examples for java.util.Stack#clear()
The following examples show how to use
java.util.Stack#clear() .
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: CharStringHandler.java From gcs with Mozilla Public License 2.0 | 6 votes |
/** * Handler for a sequence of CharStringCommands. * * @param sequence of CharStringCommands * */ public List<Number> handleSequence(List<Object> sequence) { Stack<Number> stack = new Stack<Number>(); for (Object obj : sequence) { if (obj instanceof CharStringCommand) { List<Number> results = handleCommand(stack, (CharStringCommand)obj); stack.clear(); // this is basically returning the new stack if (results != null) { stack.addAll(results); } } else { stack.push((Number)obj); } } return stack; }
Example 3
Source File: SchemaReferencesMetaData.java From secure-data-service with Apache License 2.0 | 6 votes |
public void aggregateForeignKeyReferences() { List<NeutralSchema> schemas = schemaRepo.getSchemas(); Stack<SchemaReferenceNode> stack = new Stack<SchemaReferenceNode>(); for(NeutralSchema schema: schemas) { String schemaType = schema.getType(); LOG.debug("Introspecting {} for References.", schemaType); SchemaReferenceNode root = new SchemaReferenceNode(schemaType); stack.clear(); stack.push(root); collectReferences(schema, stack, refNodeLists); } //Below code block can be enabled for debugging! /* NeutralSchema schema = schemaRepo.getSchema("session"); String schemaType = schema.getType(); LOG.info("Introspecting {} for References.", schemaType); SchemaReferenceNode root = new SchemaReferenceNode(schemaType); stack.clear(); stack.push(root); collectReferences(schema, stack, refNodeLists); */ }
Example 4
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 5
Source File: Context.java From FoxBPM with Apache License 2.0 | 5 votes |
public static void clearAbstractScriptLanguageMgmt() { Stack<AbstractScriptLanguageMgmt> stack = getStack(abstractScriptLanguageMgmtThreadLocal); while(!stack.isEmpty()){ AbstractScriptLanguageMgmt scriptManagement = stack.pop(); if(scriptManagement != null){ scriptManagement.close(); } } stack.clear(); }
Example 6
Source File: StackUtils.java From panda with Apache License 2.0 | 5 votes |
/** * Reverse the stack * * @param stack the stack to reverse * @param <T> the type of the values * @return the stack with reversed values (the same instance) */ public static <T> Stack<T> reverse(Stack<T> stack) { List<T> reversed = new ArrayList<>(stack); Collections.reverse(reversed); stack.clear(); for (T element : reversed) { stack.push(element); } return stack; }
Example 7
Source File: Generator.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * Update chart UI attributes with inherited styles if those UI attributes * don't be set or updated. * * @param model * @param externalProcessor */ protected void updateWithInhertingtyles( Chart model, IStyleProcessor externalProcessor ) { Stack<StyledComponent> token = new Stack<StyledComponent>( ); token.push( StyledComponent.CHART_ALL_LITERAL ); prepareComponent( model, token, model, externalProcessor ); token.clear( ); }
Example 8
Source File: RTOperationManager.java From Android-RTEditor with Apache License 2.0 | 5 votes |
/** * Flush all operations for a specific rich text editor (method unused at the moment) * * @param editor This rich text editor's operations will be flushed */ synchronized void flushOperations(RTEditText editor) { Stack<Operation> undoStack = getUndoStack(editor); Stack<Operation> redoStack = getRedoStack(editor); undoStack.clear(); redoStack.clear(); }
Example 9
Source File: RTOperationManager.java From Android-RTEditor with Apache License 2.0 | 5 votes |
/** * Call this when an operation is performed to add it to the undo stack. * * @param editor The rich text editor the operation was performed on * @param op The Operation that was performed */ synchronized void executed(RTEditText editor, Operation op) { Stack<Operation> undoStack = getUndoStack(editor); Stack<Operation> redoStack = getRedoStack(editor); // if operations are executed in a quick succession we "merge" them to have but one // -> saves memory and makes more sense from a user perspective (each key stroke an undo? -> no way) while (!undoStack.empty() && op.canMerge(undoStack.peek())) { Operation previousOp = undoStack.pop(); op.merge(previousOp); } push(op, undoStack); redoStack.clear(); }
Example 10
Source File: Context.java From fixflow with Apache License 2.0 | 5 votes |
public static void removeAbstractScriptLanguageMgmt() { Stack<AbstractScriptLanguageMgmt> abstractScriptLanguageMgmts = getStack(abstractScriptLanguageMgmtThreadLocal); for (int i = 0; i < abstractScriptLanguageMgmts.size(); i++) { abstractScriptLanguageMgmts.get(i).close(); } abstractScriptLanguageMgmts.clear(); }
Example 11
Source File: RTOperationManager.java From memoir with Apache License 2.0 | 5 votes |
/** * Call this when an operation is performed to add it to the undo stack. * * @param editor The rich text editor the operation was performed on * @param op The Operation that was performed */ synchronized void executed(RTEditText editor, Operation op) { Stack<Operation> undoStack = getUndoStack(editor); Stack<Operation> redoStack = getRedoStack(editor); // if operations are executed in a quick succession we "merge" them to have but one // -> saves memory and makes more sense from a user perspective (each key stroke an undo? -> no way) while (!undoStack.empty() && op.canMerge(undoStack.peek())) { Operation previousOp = undoStack.pop(); op.merge(previousOp); } push(op, undoStack); redoStack.clear(); }
Example 12
Source File: RTOperationManager.java From memoir with Apache License 2.0 | 5 votes |
/** * Flush all operations for a specific rich text editor (method unused at the moment) * * @param editor This rich text editor's operations will be flushed */ synchronized void flushOperations(RTEditText editor) { Stack<Operation> undoStack = getUndoStack(editor); Stack<Operation> redoStack = getRedoStack(editor); undoStack.clear(); redoStack.clear(); }
Example 13
Source File: RTOperationManager.java From memoir with Apache License 2.0 | 5 votes |
/** * Call this when an operation is performed to add it to the undo stack. * * @param editor The rich text editor the operation was performed on * @param op The Operation that was performed */ synchronized void executed(RTEditText editor, Operation op) { Stack<Operation> undoStack = getUndoStack(editor); Stack<Operation> redoStack = getRedoStack(editor); // if operations are executed in a quick succession we "merge" them to have but one // -> saves memory and makes more sense from a user perspective (each key stroke an undo? -> no way) while (!undoStack.empty() && op.canMerge(undoStack.peek())) { Operation previousOp = undoStack.pop(); op.merge(previousOp); } push(op, undoStack); redoStack.clear(); }
Example 14
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 15
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 16
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; }
Example 17
Source File: Signer.java From IDES-Data-Preparation-Java with Creative Commons Zero v1.0 Universal | 4 votes |
protected void updateDigestWithXmlChunk(StringBuilder parseBuf, MessageDigest messageDigest, Stack<XmlTag> stackStartTag, Stack<XmlTag> stackChunkStartTag, Stack<XmlTag> stackChunkEndTag, Canonicalizer canonicalizer, DocumentBuilder docBuilderNSTrue, String digestPrefixStr, String digestSuffixStr) throws Exception { //stackChunkStartTag has start tags whose end tags are not in chunk //stackChunkEndTag has end tags whose start tags are not in chunk int startPrefixTagCount = 0, pos; int startTagToAddCount = stackStartTag.size() - stackChunkStartTag.size(); String startPrefixTags = "", endSuffixTags = "", prefix, suffix; XmlTag tag; byte[] tmpbuf; //add end tags, newest to oldest to match xml structure, to xml chunk for transformation while (!stackChunkStartTag.empty()) { //stackChunkStartTag - 0=<MessageSpec>, 1=<TAG>....add suffix </TAG></MessageSpec> tag = stackChunkStartTag.pop(); //corresponding start tag exists in chunk endSuffixTags = endSuffixTags + tag.getEndTag(); } //add start tags, newest to oldest to match xml structure, to xml chunk for transformation while (!stackChunkEndTag.empty()) { //stackChunkEndTag - 0=<Address>, 1=<AddressFix>....meaning parseBuf has </AddressFix></Address> //add prefix <Address><AddressFix> startPrefixTagCount++; tag = stackChunkEndTag.pop(); startPrefixTags = startPrefixTags + tag.getStartTag(); //corresponding end tag exists in chunk } //add tags, prefix and suffix, present in stackStartTag as they may have NS (namespace) defined //even if a tag in stackStartTag has no NS defined, we need them because of correct transformation, mainly for 'Exclusive' transformation //stackStartTag - 0=<OUTERTAG>, 1=<MessageSpec> add prefix=<OUTERTAG><MessageSpec> and suffix=</MessageSpec></OUTERTAG> prefix = suffix = ""; for (int i = 0; i < startTagToAddCount; i++) { tag = stackStartTag.get(i); //do not restrict to tags with ns only - Exclusive transformation would fail startPrefixTagCount++; prefix = prefix + tag.getStartTag(); suffix = tag.getEndTag() + suffix; } startPrefixTags = prefix + startPrefixTags; endSuffixTags = endSuffixTags + suffix; startPrefixTags = digestPrefixStr + startPrefixTags; //for prefix with digestPrefixStr //<Object> and <SignatureProperty> has 1 prefix tag while <SignatureProperties><SignatureProperty> has 2 pos = 0; while ((pos = digestPrefixStr.indexOf(">", pos + 1)) > 0) startPrefixTagCount++; endSuffixTags += digestSuffixStr; String modifiedval = startPrefixTags + parseBuf.toString() + endSuffixTags; logger.trace("to transform str=" + modifiedval); Document doc = docBuilderNSTrue.parse(new InputSource(new StringReader(modifiedval))); String digestval = new String(canonicalizer.canonicalizeSubtree(doc)); logger.trace("transformed str=" + digestval); //simply drop endSuffixTags - they don't gets altered by canonicalization if (endSuffixTags.length() > 0) digestval = digestval.substring(0, digestval.length() - endSuffixTags.length()); //drop canonicalized startPrefixTags - remember they may be altered by transformation and so use prefix count to drop them pos = 0; for (int i = 0; i < startPrefixTagCount; i++) pos = digestval.indexOf(">", pos + 1); if (pos > 0) digestval = digestval.substring(pos + 1); logger.trace("digestval=" + digestval); tmpbuf = digestval.getBytes(); messageDigest.update(tmpbuf); if (digestBuf != null) digestBuf = UtilShared.append(digestBuf, tmpbuf); parseBuf.setLength(0); stackChunkStartTag.clear(); stackChunkEndTag.clear(); }
Example 18
Source File: BKKCKCF.java From ReactionDecoder with GNU Lesser General Public License v3.0 | 4 votes |
int init_Algorithm() { // System.out.println( "init_Algorithm " + comp_graph_nodes.size() ); List<Integer> R = new ArrayList<>(); Stack<Integer> Q = new Stack<>(); List<Integer> X = new ArrayList<>(); List<Integer> N = new ArrayList<>(); Stack<Integer> P = new Stack<>(); //nodes of vector comp_graph_nodes are stored in V Stack<Integer> V = new Stack<>();//Initialization of Stack V int V_set_size = comp_graph_nodes.size() / 3; for (int a = 0; a < V_set_size; a++) { V.push(comp_graph_nodes.get(a * 3 + 2)); } V.push(0); int b = 0; while (V.get(b) != 0) { // V[b] is node u int central_node = V.get(b); P.clear(); Q.clear(); X.clear(); N.clear(); R.clear(); //find the neighbors of the central node from V N = find_neighbors(central_node); // System.out.println("N-Neigh: " + N); for (int c = 0; c < N.size(); c = c + 2) { // N[c] is node v //System.out.println("N[" + c + "]= " + N.get(c) + " "); /* * Grouping of the neighbors in X,P and Q * u and v are adjacent via a R-edge */ if (N.get(c + 1) == 1) { if (T.contains(N.get(c))) { X.add(N.get(c)); } else { P.push(N.get(c)); } } else if (N.get(c + 1) == 2) { // u and v are adjacent via a Q-edge // System.out.println("u and v are adjacent via a Q-edge"); Q.push(N.get(c)); } //find respective neighbor position in P, which is needed for the deletion from V int V_size = V.size(); int neighbor_position = -1; //System.out.println("V Size: "+ V.size()); for (int d = 0; d < V_size; d++) { //System.out.println(" N[c]: " + N.get(c)+ " , V[" + d + "]: " + V.get(d)); if (N.get(c).intValue() == (V.get(d))) { neighbor_position = d; } } //delete neighbor from set V if (neighbor_position != -1) { // System.out.println("neighbor_position : " + neighbor_position); for (int e = neighbor_position; e < V_size - 1; e++) { V.set(e, V.get(e + 1)); } V.pop(); if (neighbor_position < b) { b = b - 1; } } } P.add(0); R.add(central_node); Enumerate_Cliques(R, P, Q, X); T.add(central_node); b++; } return 0; }
Example 19
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 20
Source File: SpringLayout.java From springlayout with MIT License | 4 votes |
private void createViewMetrics(Stack<ViewConstraints> springMetrics) { springMetrics.clear(); mIdToViewConstraints.clear(); if (mRootConstraints != null) { mRootConstraints.release(); for (int i = 0; i < mViewConstraints.length; i++) { mViewConstraints[i].release(); } mRootConstraints.reset(this); resizeViewConstraintsArray(getChildCount()); } else { mRootConstraints = new ViewConstraints(this, mLayoutMath); mViewConstraints = new ViewConstraints[getChildCount()]; } mRootConstraints.left.setValueObject(mLayoutMath.variable(0)); mRootConstraints.top.setValueObject(mLayoutMath.variable(0)); final int count = getChildCount(); for (int i = 0; i < count; i++) { final View v = getChildAt(i); mIdToViewConstraints.append(v.getId(), i); if (mViewConstraints[i] == null) { mViewConstraints[i] = new ViewConstraints(v, mLayoutMath); } else { mViewConstraints[i].reset(v); } } for (int i = 0; i < count; i++) { final ViewConstraints viewConstraints = mViewConstraints[i]; final LayoutParams layoutParams = (LayoutParams) viewConstraints.getView().getLayoutParams(); if (layoutParams.getWidthWeight() > 0) { viewConstraints.markAsHorizontalSpring(); } if (layoutParams.getHeightWeight() > 0) { viewConstraints.markAsVerticalSpring(); } int[] childRules = layoutParams.getRelations(); for (int relation : VALID_RELATIONS) { final ViewConstraints metrics = getViewMetrics(childRules[relation]); if (metrics != null) { metrics.updateRelation(viewConstraints, relation); } } if (viewConstraints.isHorizontalSpring() || viewConstraints.isVerticalSpring()) { springMetrics.add(viewConstraints); } } }