本文整理汇总了Java中java.util.Stack.add方法的典型用法代码示例。如果您正苦于以下问题:Java Stack.add方法的具体用法?Java Stack.add怎么用?Java Stack.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Stack
的用法示例。
在下文中一共展示了Stack.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createEmailOnlyChooserIntent
import java.util.Stack; //导入方法依赖的package包/类
public static Intent createEmailOnlyChooserIntent(Context context, Intent source,
CharSequence chooserTitle) {
Stack<Intent> intents = new Stack<>();
Intent i = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto",
"[email protected]", null));
List<ResolveInfo> activities = context.getPackageManager()
.queryIntentActivities(i, 0);
for (ResolveInfo ri : activities) {
Intent target = new Intent(source);
target.setPackage(ri.activityInfo.packageName);
intents.add(target);
}
if (!intents.isEmpty()) {
Intent chooserIntent = Intent.createChooser(intents.remove(0),
chooserTitle);
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
intents.toArray(new Parcelable[intents.size()]));
return chooserIntent;
} else {
return Intent.createChooser(source, chooserTitle);
}
}
示例2: readStack
import java.util.Stack; //导入方法依赖的package包/类
/**
* Reads an <code>Stack</code> from a <code>DataInput</code>.
*
* @throws IOException A problem occurs while reading from <code>in</code>
* @throws ClassNotFoundException The class of one of the <Code>Stack</code>'s elements cannot be
* found.
*
* @see #writeStack
* @since GemFire 5.7
*/
public static <E> Stack<E> readStack(DataInput in) throws IOException, ClassNotFoundException {
InternalDataSerializer.checkIn(in);
int size = InternalDataSerializer.readArrayLength(in);
if (size == -1) {
return null;
} else {
Stack<E> list = new Stack<E>();
for (int i = 0; i < size; i++) {
E element = DataSerializer.<E>readObject(in);
list.add(element);
}
if (logger.isTraceEnabled(LogMarker.SERIALIZER)) {
logger.trace(LogMarker.SERIALIZER, "Read Stack with {} elements: {}", size, list);
}
return list;
}
}
示例3: removeAllActivity
import java.util.Stack; //导入方法依赖的package包/类
/**
* 栈中销毁并移除所有Act对象
*/
public void removeAllActivity() {
if (null != activityStack && activityStack.size() > 0) {
//创建临时集合对象
Stack<Activity> activityTemp = new Stack<>();
for (Activity activity : activityStack) {
if (null != activity) {
//添加到临时集合中
activityTemp.add(activity);
//结束Activity
activity.finish();
}
}
activityStack.removeAll(activityTemp);
}
LogUtil.i("AppActivityTaskManager-->>removeAllActivity", "removeAllActivity");
System.gc();
System.exit(0);
}
示例4: getConnectedModules
import java.util.Stack; //导入方法依赖的package包/类
Set<TubeModule> getConnectedModules(TubeModule module) {
Set<TubeModule> modules = new HashSet<>();
Set<TileEntityPressureTube> traversedTubes = new HashSet<>();
Stack<TileEntityPressureTube> pendingTubes = new Stack<>();
pendingTubes.push((TileEntityPressureTube) module.getTube());
while (!pendingTubes.isEmpty()) {
TileEntityPressureTube tube = pendingTubes.pop();
for (TubeModule m : tube.modules) {
if (m != null) modules.add(m);
}
TileEntityCache[] cache = ((AirHandler) tube.getAirHandler(null)).getTileCache();
for (EnumFacing d : EnumFacing.VALUES) {
if (tube.sidesConnected[d.ordinal()]) {
TileEntityPressureTube newTube = ModInteractionUtils.getInstance().getTube(cache[d.ordinal()].getTileEntity());
if (newTube != null && !traversedTubes.contains(newTube)) {
pendingTubes.add(newTube);
traversedTubes.add(newTube);
}
}
}
}
return modules;
}
示例5: isConnected
import java.util.Stack; //导入方法依赖的package包/类
/**
* Returns whether the given graph is connected.
*
* @param graph
* to be checked if it is connected
* @return whether the given graph is connected
*/
public static boolean isConnected(Graph graph) {
if (graph == null) {
throw new IllegalArgumentException("Can't check a null graph.");
}
boolean[] visited = new boolean[graph.getN()];
Arrays.fill(visited, false);
Stack<Vertex> stack = new Stack<Vertex>();
stack.add(graph.getVertexById(0));
visited[0] = true;
int numVisited = 1;
while (!stack.empty()) {
Vertex u = stack.pop();
for (Vertex v : u.getNeighbors()) {
if (!visited[v.getId()]) {
numVisited++;
visited[v.getId()] = true;
stack.add(v);
}
}
}
return numVisited == graph.getN();
}
示例6: forEachBlockDepthFirstDom
import java.util.Stack; //导入方法依赖的package包/类
/**
* Visits blocks in dom-tree order, starting at the current node.
* The {@code parent} parameter of the Visitor.visitBlock callback
* is currently always set to null.
*
* @param v {@code non-null;} callback interface
*/
public void forEachBlockDepthFirstDom(SsaBasicBlock.Visitor v) {
BitSet visited = new BitSet(getBlocks().size());
Stack<SsaBasicBlock> stack = new Stack<SsaBasicBlock>();
stack.add(getEntryBlock());
while (stack.size() > 0) {
SsaBasicBlock cur = stack.pop();
ArrayList<SsaBasicBlock> curDomChildren = cur.getDomChildren();
if (!visited.get(cur.getIndex())) {
// We walk the tree this way for historical reasons...
for (int i = curDomChildren.size() - 1; i >= 0; i--) {
SsaBasicBlock child = curDomChildren.get(i);
stack.add(child);
}
visited.set(cur.getIndex());
v.visitBlock(cur, null);
}
}
}
示例7: isBipartite
import java.util.Stack; //导入方法依赖的package包/类
/**
* Returns whether the given graph is bipartite.
*
* @param graph
* to be checked if it is bipartite
* @return whether the given graph is bipartite
*/
public static boolean isBipartite(Graph graph) {
if (graph.getN() == 0)
return true;
int[] partition = new int[graph.getN()];
Arrays.fill(partition, -1);
Stack<Vertex> stack = new Stack<Vertex>();
stack.add(graph.getVertexById(0));
partition[0] = 0;
while (!stack.empty()) {
Vertex u = stack.pop();
for (Vertex v : u.getNeighbors()) {
if (partition[v.getId()] == partition[u.getId()])
return false;
if (partition[v.getId()] == -1) {
partition[v.getId()] = 1 - partition[u.getId()];
stack.add(v);
}
}
}
return true;
}
示例8: forEachBlockDepthFirst
import java.util.Stack; //导入方法依赖的package包/类
/**
* Walks the basic block tree in depth-first order, calling the visitor
* method once for every block. This depth-first walk may be run forward
* from the method entry point or backwards from the method exit points.
*
* @param reverse true if this should walk backwards from the exit points
* @param v {@code non-null;} callback interface. {@code parent} is set
* unless this is the root node
*/
public void forEachBlockDepthFirst(boolean reverse,
SsaBasicBlock.Visitor v) {
BitSet visited = new BitSet(blocks.size());
// We push the parent first, then the child on the stack.
Stack<SsaBasicBlock> stack = new Stack<SsaBasicBlock>();
SsaBasicBlock rootBlock = reverse ? getExitBlock() : getEntryBlock();
if (rootBlock == null) {
// in the case there's no exit block
return;
}
stack.add(null); // Start with null parent.
stack.add(rootBlock);
while (stack.size() > 0) {
SsaBasicBlock cur = stack.pop();
SsaBasicBlock parent = stack.pop();
if (!visited.get(cur.getIndex())) {
BitSet children
= reverse ? cur.getPredecessors() : cur.getSuccessors();
for (int i = children.nextSetBit(0); i >= 0
; i = children.nextSetBit(i + 1)) {
stack.add(cur);
stack.add(blocks.get(i));
}
visited.set(cur.getIndex());
v.visitBlock(cur, parent);
}
}
}
示例9: getPostDominatorOfUnit
import java.util.Stack; //导入方法依赖的package包/类
public static Unit getPostDominatorOfUnit(IInfoflowCFG cfg, Unit dataFlowStatement) {
Map<Unit, Set<ControlFlowPath>> controlFlowPathsAtUnit = new HashMap<Unit, Set<ControlFlowPath>>();
Set<ControlFlowPath> currentPaths = new HashSet<ControlFlowPath>();
Stack<Unit> worklist = new Stack<Unit>();
worklist.add(dataFlowStatement);
while(!worklist.isEmpty()) {
Unit currentUnit = worklist.pop();
if(currentUnit.hasTag(InstrumentedCodeTag.name)) {
List<Unit> successors = cfg.getSuccsOf(currentUnit);
for(Unit nextUnit : successors) {
if(proceedWithNextUnit(currentUnit, nextUnit, currentPaths, controlFlowPathsAtUnit)) {
worklist.push(nextUnit);
}
}
continue;
}
SootMethod currentMethod = cfg.getMethodOf(currentUnit);
//this is a kind of hack: We excluded exception-edges here and also keep in mind that ALL dominator-algorithms are intra-procedural
MHGPostDominatorsFinder<Unit> postdominatorFinder = new MHGPostDominatorsFinder<Unit>(new BriefUnitGraph(currentMethod.retrieveActiveBody()));
Unit immediatePostDominator = postdominatorFinder.getImmediateDominator(currentUnit);
while(immediatePostDominator.hasTag(InstrumentedCodeTag.name)) {
immediatePostDominator = postdominatorFinder.getImmediateDominator(immediatePostDominator);
}
return immediatePostDominator;
}
return null;
}
示例10: gettoCompount
import java.util.Stack; //导入方法依赖的package包/类
private static Object gettoCompount(Object nbttag, NBTCompound comp) {
Stack<String> structure = new Stack<>();
while (comp.getParent() != null) {
structure.add(comp.getName());
comp = comp.getParent();
}
while (!structure.isEmpty()) {
nbttag = getSubNBTTagCompound(nbttag, structure.pop());
if (nbttag == null) {
return null;
}
}
return nbttag;
}
示例11: findPartById
import java.util.Stack; //导入方法依赖的package包/类
static Part findPartById(Part searchRoot, long partId) {
if (searchRoot instanceof LocalMessage) {
LocalMessage localMessage = (LocalMessage) searchRoot;
if (localMessage.getMessagePartId() == partId) {
return localMessage;
}
}
Stack<Part> partStack = new Stack<>();
partStack.add(searchRoot);
while (!partStack.empty()) {
Part part = partStack.pop();
if (part instanceof LocalPart) {
LocalPart localBodyPart = (LocalPart) part;
if (localBodyPart.getPartId() == partId) {
return part;
}
}
Body body = part.getBody();
if (body instanceof Multipart) {
Multipart innerMultipart = (Multipart) body;
for (BodyPart innerPart : innerMultipart.getBodyParts()) {
partStack.add(innerPart);
}
}
if (body instanceof Part) {
partStack.add((Part) body);
}
}
return null;
}
示例12: main
import java.util.Stack; //导入方法依赖的package包/类
public static void main(String[] args) {
Stack<Plant> stack = new Stack<>();
Flower flower = new Flower(FlowerType.SEED, "水仙花", 1, 2);
stack.add(flower.getMemento());
LOGGER.info(flower.toString());
flower.growing();
stack.add(flower.getMemento());
LOGGER.info(flower.toString());
flower.growing();
stack.add(flower.getMemento());
LOGGER.info(flower.toString());
flower.growing();
stack.add(flower.getMemento());
LOGGER.info(flower.toString());
flower.growing();
stack.add(flower.getMemento());
LOGGER.info(flower.toString());
flower.growing();
stack.add(flower.getMemento());
LOGGER.info(flower.toString());
while (stack.size() > 0) {
flower.setMemento(stack.pop());
LOGGER.info(flower.toString());
}
}
示例13: gettoCompount
import java.util.Stack; //导入方法依赖的package包/类
private static Object gettoCompount(Object nbttag, NBTCompound comp){
Stack<String> structure = new Stack<String>();
while (comp.getParent() != null){
structure.add(comp.getName());
comp = comp.getParent();
}
while (!structure.isEmpty()){
nbttag = getSubNBTTagCompound(nbttag, (String)structure.pop());
if (nbttag == null) {
return null;
}
}
return nbttag;
}
示例14: toJSON
import java.util.Stack; //导入方法依赖的package包/类
@Override
public JSONObject toJSON() {
final JSONObject json = JSONable.super.toJSON();
try {
final JSONArray jArray = new JSONArray();
final JSONArray nodeIds = new JSONArray();
final Stack<Node> stack = new Stack<>();
stack.add(root);
Integer nodeCounter = 0;
while (!(stack.empty())) {
final Node currentNode = stack.pop();
jArray.put(currentNode.toJSON());
if (currentNode.leftChild != null) {
stack.push(currentNode.leftChild);
nodeIds.put(++nodeCounter);
} else {
nodeIds.put(NO_CHILD);
}
if (currentNode.rightChild != null) {
stack.push(currentNode.rightChild);
nodeIds.put(++nodeCounter);
} else {
nodeIds.put(NO_CHILD);
}
}
json.put("nodes", jArray);
json.put("nodeIds", nodeIds);
} catch (JSONException jse) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, jse);
}
return json;
}
示例15: getStringVariable
import java.util.Stack; //导入方法依赖的package包/类
private String getStringVariable() throws IOException {
int length = getNextByte();
Stack<Character> stringReverser = new Stack<>();
for (int i = 0; i < length; i++) {
stringReverser.add((char)getNextByte());
}
StringBuilder rightWayAroundString = new StringBuilder();
while (!stringReverser.isEmpty())
rightWayAroundString.append(stringReverser.pop().charValue());
return rightWayAroundString.toString();
}