本文整理汇总了Java中java.util.Stack.get方法的典型用法代码示例。如果您正苦于以下问题:Java Stack.get方法的具体用法?Java Stack.get怎么用?Java Stack.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Stack
的用法示例。
在下文中一共展示了Stack.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: showFragment
import java.util.Stack; //导入方法依赖的package包/类
/**
* Displays the fragment identified by its tab index and level. Child fragments are removed
* automatically.
*
* @param tabIndex The index of the tab that the fragment belongs to.
* @param level The level of the fragment. {@link #TAB_LEVEL_TOP}, {@link
* #TAB_LEVEL_LAST} and {@link #TAB_LEVEL_ONE_BACK} are allowed.
* @param closeIfEmpty If set to true and the other parameters would lead to the top level
* fragment being removed, the app will be closed. Handy for back
* navigation, but not if a fragment tries to remove itself.
* @return True if the fragment identified by {@code tabIndex} and {@code level} is now
* displayed, false otherwise (e.g., if that would have closed the app and that isn't
* permitted).
*/
private boolean showFragment(int tabIndex, int level, boolean closeIfEmpty) {
Stack<MainFragment> tabStack = mFragments[tabIndex];
if (level == TAB_LEVEL_LAST)
level = tabStack.size() - 1;
else if (level == TAB_LEVEL_ONE_BACK)
level = tabStack.size() - 2;
if (level < 0) {
if (!closeIfEmpty)
return false;
getViewOrThrow().finish();
} else {
while (tabStack.size() > level + 1)
tabStack.pop();
MainFragment fragment = tabStack.get(level);
getViewOrThrow().showFragment(fragment, mCurrentTabIndex, tabIndex);
mCurrentFragment = fragment;
mCurrentTabIndex = tabIndex;
mCurrentLevel = level;
}
return false;
}
示例2: convertFahrenheitToCelsius
import java.util.Stack; //导入方法依赖的package包/类
private int convertFahrenheitToCelsius(String fahrenheit) {
Stack<Integer> stack = new Stack<Integer>();
// Subtract 32 from the temperature
ldc.execute(stack, fahrenheit);
bipush.execute(stack, 32);
isub.execute(stack);
// Multiply by 5
bipush.execute(stack, 5);
imul.execute(stack);
// Divide by 9
ldc.execute(stack, "Nine");
idiv.execute(stack);
// Pull the answer from the stack
Integer celsius = stack.get(0);
return celsius;
}
示例3: readArray
import java.util.Stack; //导入方法依赖的package包/类
@Override
public short[] readArray(JsonReader reader) {
Stack<Short> shortStack = new Stack<>();
reader.beginArray();
while (JsonToken.END_ARRAY != reader.peek()) {
if (JsonToken.NULL == reader.peek()) {
reader.skipValue();
shortStack.push(null);
} else {
shortStack.push(new Integer(reader.nextInt()).shortValue());
}
}
reader.endArray();
short[] shorts = new short[shortStack.size()];
for (int i = 0; i < shortStack.size(); i++) {
shorts[i] = shortStack.get(i);
}
return shorts;
}
示例4: updateLog
import java.util.Stack; //导入方法依赖的package包/类
public static void updateLog() {
TextView tv = layout.findViewById(R.id.tv_log);
StringBuffer sb = new StringBuffer();
sb.append("当前打开Activity:");
sb.append(ActivityManager.getInstance().getActivityCount());
sb.append("个");
sb.append("\n");
sb.append("栈顶Activity:");
Activity peek = ActivityManager.getInstance().getActivityStack().peek();
sb.append(peek.getClass().getSimpleName() + "@" + Integer.toHexString(peek.hashCode()));
sb.append("\n");
sb.append("\n");
Stack<Activity> stack = ActivityManager.getInstance().getActivityStack();
for (int i = stack.size() - 1; i >= 0; i--) {
Activity activity = stack.get(i);
sb.append(i);
sb.append(" - ");
sb.append(activity.getClass().getSimpleName() + "@" + Integer.toHexString(activity.hashCode()));
sb.append("\n");
}
tv.setText(sb.toString());
}
示例5: removeFragment
import java.util.Stack; //导入方法依赖的package包/类
/**
* Removes the specified fragment from the hierarchy. Any child fragments will be removed too.
*
* @param fragment The fragment to be removed.
* @return True if the fragment was removed, false otherwise (e.g., the fragment is the top
* level fragment).
*/
public boolean removeFragment(@NonNull MainFragment fragment) {
if (fragment.equals(mCurrentFragment))
return showFragment(mCurrentTabIndex, TAB_LEVEL_ONE_BACK, false);
int i = mFragments[mCurrentTabIndex].indexOf(fragment);
if (i >= 0)
return showFragment(mCurrentTabIndex, i, false);
for (int tabIndex = 0; tabIndex < mFragments.length; tabIndex++) {
Stack<MainFragment> tabStack = mFragments[tabIndex];
for (int level = 0; level < tabStack.size(); level++) {
MainFragment f = tabStack.get(level);
if (fragment.equals(f))
while (tabStack.size() > level + 1)
tabStack.pop();
}
}
return true;
}
示例6: addFragment
import java.util.Stack; //导入方法依赖的package包/类
/**
* Adds the fragment as the child of parent, and shows it. If parent already has a child (and
* possibly sub-children), those are removed.
*
* @param parent The parent of the added fragment
* @param child The fragment to add
*/
public void addFragment(@NonNull MainFragment parent, @NonNull MainFragment child) {
for (int tabIndex = 0; tabIndex < mFragments.length; tabIndex++) {
Stack<MainFragment> tabStack = mFragments[tabIndex];
for (int level = 0; level < tabStack.size(); level++) {
MainFragment fragment = tabStack.get(level);
if (parent.equals(fragment)) {
int diff = tabStack.size() - tabStack.indexOf(parent) - 1;
for (int k = 0; k < diff; k++)
tabStack.pop();
tabStack.push(child);
showFragment(tabIndex, TAB_LEVEL_LAST, false);
return;
}
}
}
}
示例7: discardProcessedMarkupItems
import java.util.Stack; //导入方法依赖的package包/类
private void discardProcessedMarkupItems(Stack<MarkupItem> stack, int startIndex, int endIndex) {
for (int index = endIndex; index >= startIndex; index--) {
MarkupItem item = stack.get(index);
// #198659 - when a document is not valid (eg. accicentally a tag was not closed)
// then below assert can be triggered; disabling it for now
//assert item.processed || item.virtual : "assumption here is that a tag within process tag must be either processed or perhaps virtual: item="+item+" stack="+(getStack().size() < 30 ? getStack() : "[too many items]");
stack.remove(index);
}
}
示例8: assertStack
import java.util.Stack; //导入方法依赖的package包/类
private void assertStack(Stack<Integer> stack, int... expectedValues) {
assertEquals("Stack size wrong. Contains " + stack + " Sizes:", expectedValues.length, stack.size());
for (int i=0; i<expectedValues.length; i++) {
int actual = (int) stack.get(expectedValues.length - i -1);
int expected = expectedValues[i];
assertEquals("Stack does not contain expected value at index[" + i + "].", expected, actual);
}
}
示例9: bigNum
import java.util.Stack; //导入方法依赖的package包/类
/**
* Adds the given number as a push data chunk to the given index in the program.
* This is intended to use for negative numbers or values > 16, and although
* it will accept numbers in the range 0-16 inclusive, the encoding would be
* considered non-standard.
*
* @see #number(int)
*/
protected ScriptBuilder bigNum(int index, long num) {
final byte[] data;
if (num == 0) {
data = new byte[0];
} else {
Stack<Byte> result = new Stack<>();
final boolean neg = num < 0;
long absvalue = Math.abs(num);
while (absvalue != 0) {
result.push((byte) (absvalue & 0xff));
absvalue >>= 8;
}
if ((result.peek() & 0x80) != 0) {
// The most significant byte is >= 0x80, so push an extra byte that
// contains just the sign of the value.
result.push((byte) (neg ? 0x80 : 0));
} else if (neg) {
// The most significant byte is < 0x80 and the value is negative,
// set the sign bit so it is subtracted and interpreted as a
// negative when converting back to an integral.
result.push((byte) (result.pop() | 0x80));
}
data = new byte[result.size()];
for (int byteIdx = 0; byteIdx < data.length; byteIdx++) {
data[byteIdx] = result.get(byteIdx);
}
}
// At most the encoded value could take up to 8 bytes, so we don't need
// to use OP_PUSHDATA opcodes
return addChunk(index, new ScriptChunk(data.length, data));
}
示例10: addIndent
import java.util.Stack; //导入方法依赖的package包/类
private static final void addIndent(Stack<Pair<Integer,Boolean>> indent, StringBuilder result) {
for (int i = 0; i < indent.size(); i++) {
Pair<Integer,Boolean> p = indent.get(i);
for (int s = 0; s < p.one(); s++) {
result.append(" ");
}
result.append(p.two() ? (i == indent.size() - 1 ? " +-- " : " | ") : " ");
}
}
示例11: printStack
import java.util.Stack; //导入方法依赖的package包/类
private void printStack(StringBuilder sb, _Rigger rigger, Stack<String> stack, int level) {
if (stack == null || stack.empty()) return;
for (int p = stack.size() - 1; p >= 0; p--) {
String tag = stack.get(p);
sb.append("\n");
sb.append("┃");
if (level != 1) {
for (int i = 0; i < level; i++) {
sb.append(" ").append(" ").append(" ").append(" ");
}
}
for (int i = 0; i < level; i++) {
sb.append("\t");
}
Fragment fragment = rigger.mRiggerTransaction.find(tag);
_Rigger childRigger = (_Rigger) Rigger.getRigger(fragment);
Stack<String> childStack = childRigger.getFragmentStack();
if (p > 0 && childStack.isEmpty()) {
sb.append("┠");
} else {
sb.append("┖");
}
sb.append("————");
sb.append(tag);
printStack(sb, childRigger, childStack, level + 1);
}
}
示例12: resolveInitialStateFromPredecessorFor
import java.util.Stack; //导入方法依赖的package包/类
public ParsingHelper resolveInitialStateFromPredecessorFor(GraphNode aNode, ParsingHelper aPredecessor) {
// The node will import the full stack from its predecessor
ParsingHelper.ValueProvider theProvider = aPredecessor::requestValue;
ParsingHelper theNew = new ParsingHelper(localVariableTableAttributeInfo, aNode, theProvider);
Stack<Value> theStackToImport = aPredecessor.stack;
for (int i=0;i<theStackToImport.size();i++) {
StackVariableDescription theStackDesc = new StackVariableDescription(theStackToImport.size() - i - 1);
Value theImportedValue = theStackToImport.get(i);
theNew.stack.push(theImportedValue);
aNode.addToImportedList(theImportedValue, theStackDesc);
}
return theNew;
}
示例13: tick
import java.util.Stack; //导入方法依赖的package包/类
public static Result tick(BehaviorTree tree, BehaviorData data)
{
Cursor cursor = new Cursor(tree, data);
tree.onStart(data);
Result r = tree.getRoot().execute(cursor);
cursor.onTreeResult(r);
Stack<Node> prevOpenNodes = cursor.getBehaviorData().getData(cursor.getBehaviorTree().id, null).get("_open_nodes", new Stack<Node>());
Stack<Node> openNodes = new Stack<Node>();
openNodes.addAll(cursor.getOpenNodes());
int start = 0;
for (int i = 0; i < Math.min(prevOpenNodes.size(), openNodes.size()); ++i)
{
start = i + 1;
if (prevOpenNodes.get(i) != openNodes.get(i))
{
break;
}
}
for (int i = prevOpenNodes.size() - 1; i >= start; --i)
{
prevOpenNodes.get(i).close(cursor);
}
cursor.getBehaviorData().getData(cursor.getBehaviorTree().id, null).set("_open_nodes", openNodes);
return r;
}
示例14: analyse
import java.util.Stack; //导入方法依赖的package包/类
public static Vector analyse(String input)
{
Vector output = new Vector();
try
{
Stack allStk = new Stack();
Method.analyse(input,allStk);
for(int i=0;i<allStk.size();i++)
{
Stack outputStack = (Stack)allStk.get(i);
Vector part = new Vector();
Vector tag = new Vector();
while (!outputStack.empty())
{
Entry entry = (Entry)outputStack.pop();
String s = TabConverter.revert(entry.getPart());
part.add(s);
int tagInt = entry.getTag();
if(tagInt != -1)
{
s = String.valueOf(tagInt);
}
else
s = "";
tag.add(s);
}
output.add(new Element(part,tag));
}
}catch(Exception e)
{
System.err.println("Analyser analyse: " + e);
e.printStackTrace();
return null;
}
return output;
}
示例15: Match
import java.util.Stack; //导入方法依赖的package包/类
protected Match Match(INlpSentence s, int offset, long terminalStateIndex, int consumeLimit, boolean assertionMatch, boolean indexedSearch, SearchSpaceReducer.PTAcache ptaCache) throws GGSException, IOException {
//reset bindings for the jsEngine if this is not an assertion match
if (!assertionMatch && stateMachine.usesJs()) {
stateMachine.resetJsVariables();
if (lastS != s) {
stateMachine.setJsSentence(s);
lastS = s;
}
}
Match sofar = new Match();
sofar.sentence = s;
sofar.startPositionInSentence = offset;
Stack<State> statesStack = new Stack<State>();
sofar = Match(s, offset, sofar, new Stack<GraphNode>(), new Stack<GraphNode>(), statesStack, terminalStateIndex, consumeLimit, indexedSearch, ptaCache);
if (sofar != null) {
for (SpanAnnotation a : sofar.getSpanAnnotations()) {
if (a.getEndTokenIndex() == -1 || a.getStartTokenIndex() == -1)
throw new GGSOutputMalformatException(a);
}
sofar.matchedGraphNodesPath = new ArrayList<>();
for (int i = 0; i < statesStack.size(); i++) {
if (statesStack.get(i).isGraphNodeEntry) {
sofar.matchedGraphNodesPath.add(statesStack.get(i).parentGraphNode);
}
}
}
return sofar;
}