List of usage examples for java.util Stack Stack
public Stack()
From source file:Main.java
public static void addActivity(Activity activity) { if (activityStack == null) { activityStack = new Stack<>(); }//from w ww . j a v a 2 s . c om activityStack.add(activity); }
From source file:Main.java
public static void addActivity(Activity activity) { if (activityStack == null) { activityStack = new Stack<Activity>(); }//w w w . ja va 2 s . co m activityStack.add(activity); }
From source file:Main.java
public static void addActivity(Activity activity) { if (null == mActivityStack) { mActivityStack = new Stack<>(); }// ww w . ja v a 2 s.c o m mActivityStack.add(activity); }
From source file:Main.java
public static void addActivity(Activity activity) { if (statckActivity == null) { statckActivity = new Stack<Activity>(); }//from w w w.j a va 2 s .com statckActivity.add(activity); }
From source file:Main.java
public static void sortingByFastStack(int[] intArray, boolean ascending) { Stack<Integer> sa = new Stack<Integer>(); sa.push(0);//from ww w . j av a 2s. co m sa.push(intArray.length - 1); while (!sa.isEmpty()) { int end = ((Integer) sa.pop()).intValue(); int start = ((Integer) sa.pop()).intValue(); int i = start; int j = end; int tmp = intArray[i]; if (ascending) { while (i < j) { while (intArray[j] > tmp && i < j) { j--; } if (i < j) { intArray[i] = intArray[j]; i++; } for (; intArray[i] < tmp && i < j; i++) { ; } if (i < j) { intArray[j] = intArray[i]; j--; } } } else { while (i < j) { while (intArray[j] < tmp && i < j) { j--; } if (i < j) { intArray[i] = intArray[j]; i++; } for (; intArray[i] > tmp && i < j; i++) { ; } if (i < j) { intArray[j] = intArray[i]; j--; } } } intArray[i] = tmp; if (start < i - 1) { sa.push(Integer.valueOf(start)); sa.push(Integer.valueOf(i - 1)); } if (end > i + 1) { sa.push(Integer.valueOf(i + 1)); sa.push(Integer.valueOf(end)); } } }
From source file:Main.java
public static String _10_to_62(long number, int length) { Long rest = number;//from w w w. j a v a 2 s .c om Stack<Character> stack = new Stack<Character>(); StringBuilder result = new StringBuilder(0); while (rest != 0) { stack.add(charSet[new Long((rest - (rest / 62) * 62)).intValue()]); rest = rest / 62; } for (; !stack.isEmpty();) { result.append(stack.pop()); } int result_length = result.length(); StringBuilder temp0 = new StringBuilder(); for (int i = 0; i < length - result_length; i++) { temp0.append('0'); } return temp0.toString() + result.toString(); }
From source file:Main.java
public static String getNodeHierarchy(Node node) { StringBuffer sb = new StringBuffer(); if (node != null) { Stack<Node> st = new Stack<Node>(); st.push(node);//from www .j a v a 2 s . co m Node parent = node.getParentNode(); while ((parent != null) && (parent.getNodeType() != Node.DOCUMENT_NODE)) { st.push(parent); parent = parent.getParentNode(); } // constructs node hierarchy Node n = null; while (!st.isEmpty() && null != (n = st.pop())) { if (n instanceof Element) { Element e = (Element) n; if (sb.length() == 0) { sb.append(e.getTagName()); } else { sb.append("/" + e.getTagName()); } } } } return sb.toString(); }
From source file:Main.java
public static List<File> listFilesByName(File f) { Log.d("listFileByName f", "" + f); final List<File> fList = new LinkedList<>(); final Stack<File> stk = new Stack<>(); if (f.isDirectory()) { stk.push(f);//from w w w .j ava2 s . co m } else { fList.add(f); } File fi = null; File[] fs; while (stk.size() > 0) { fi = stk.pop(); fs = fi.listFiles(); for (File f2 : fs) { if (f2.isDirectory()) { stk.push(f2); } else { fList.add(f2); } } } return fList; }
From source file:Main.java
/** 0: number of files/*w w w .j a va 2 s . co m*/ 1: total length 2: number of directories */ public static void getDirSize(final File f, final long[] l) { if (f.isFile()) { l[0]++; l[1] += f.length(); } else { Stack<File> stk = new Stack<>(); stk.add(f); File fi = null; File[] fs; while (stk.size() > 0) { fi = stk.pop(); fs = fi.listFiles(); for (File f2 : fs) { if (f2.isDirectory()) { stk.push(f2); l[2]++; } else { l[0]++; l[1] += f2.length(); } } } } }
From source file:Main.java
public static boolean parseXMLMessage(String msg, HashMap<String, String> strMap) { boolean bRet = true; // parse xml document. XmlPullParserFactory factory;/* w ww . ja v a 2s. c o m*/ XmlPullParser parser; try { factory = XmlPullParserFactory.newInstance(); parser = factory.newPullParser(); Stack eleStack = new Stack(); int parserEvent; parser.setInput(new StringReader(msg)); parserEvent = parser.getEventType(); while (parserEvent != XmlPullParser.END_DOCUMENT) { switch (parserEvent) { case XmlPullParser.START_TAG: String newtag = parser.getName(); if (newtag.compareTo("xml") != 0) { eleStack.push(newtag); } break; case XmlPullParser.END_TAG: if (parser.getName().compareTo("xml") != 0) { eleStack.pop(); } break; case XmlPullParser.TEXT: String tagkey = ""; for (int i = 0; i < eleStack.size(); i++) { tagkey += eleStack.elementAt(i); if (i < eleStack.size() - 1) tagkey += "_"; } strMap.put(tagkey, parser.getText()); break; default: break; } parserEvent = parser.next(); } eleStack = null; parser = null; factory = null; } catch (Exception e) { e.printStackTrace(); bRet = false; } return bRet; }