当前位置: 首页>>代码示例>>Java>>正文


Java Stack.empty方法代码示例

本文整理汇总了Java中java.util.Stack.empty方法的典型用法代码示例。如果您正苦于以下问题:Java Stack.empty方法的具体用法?Java Stack.empty怎么用?Java Stack.empty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.Stack的用法示例。


在下文中一共展示了Stack.empty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: pushNamespace

import java.util.Stack; //导入方法依赖的package包/类
/**
 * Declare a mapping of a prefix to namespace URI at the given element depth.
 * @param prefix a String with the prefix for a qualified name
 * @param uri a String with the uri to which the prefix is to map
 * @param elemDepth the depth of current declaration
 */
boolean pushNamespace(String prefix, String uri, int elemDepth)
{
    // Prefixes "xml" and "xmlns" cannot be redefined
    if (prefix.startsWith(XML_PREFIX))
    {
        return false;
    }

    Stack stack;
    // Get the stack that contains URIs for the specified prefix
    if ((stack = (Stack) m_namespaces.get(prefix)) == null)
    {
        m_namespaces.put(prefix, stack = new Stack());
    }

    if (!stack.empty() && uri.equals(((MappingRecord)stack.peek()).m_uri))
    {
        return false;
    }
    MappingRecord map = new MappingRecord(prefix,uri,elemDepth);
    stack.push(map);
    m_nodeStack.push(map);
    return true;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:31,代码来源:NamespaceMappings.java

示例2: getNamingContextName

import java.util.Stack; //导入方法依赖的package包/类
/**
    * Get naming context full name.
    */
   private String getNamingContextName() {
if (namingContextName == null) {
    Container parent = getParent();
    if (parent == null) {
	namingContextName = getName();
    } else {
	Stack stk = new Stack();
	StringBuffer buff = new StringBuffer();
	while (parent != null) {
	    stk.push(parent.getName());
	    parent = parent.getParent();
	}
	while (!stk.empty()) {
	    buff.append("/" + stk.pop());
	}
	buff.append(getName());
	namingContextName = buff.toString();
    }
}
return namingContextName;
   }
 
开发者ID:c-rainstorm,项目名称:jerrydog,代码行数:25,代码来源:StandardContext.java

示例3: solve

import java.util.Stack; //导入方法依赖的package包/类
public static String solve(String s) {
    Stack<Character> stack = new Stack<>();
    for (char c : s.toCharArray()) {
        if (c == '(' || c == '[' || c == '{') stack.push(c);
        else {
            if (stack.empty()) return "no";
            char p = stack.pop();
            if (c == ')') {
                if (p != '(') return "no";
                else continue;
            }
            if (c == ']') {
                if (p != '[') return "no";
                else continue;
            }
            if (c == '}') {
                if (p != '{') return "no";
            }
        }
    }
    return stack.empty() ? "yes" : "no";
}
 
开发者ID:hacktoberfest17,项目名称:programming,代码行数:23,代码来源:brackets.java

示例4: menuSort

import java.util.Stack; //导入方法依赖的package包/类
/**
 * 对菜单进行重排序
 *
 * @param menuList  菜单
 * @param parentIds 父级ID
 * @param resList   重排结果
 */
private static void menuSort(List<Menu> menuList, Stack<String> parentIds, List<Menu> resList) {
    if (menuList == null || menuList.size() == 0 || parentIds.empty()) {
        return;
    }
    boolean hasChild = false;
    for (Menu menu : menuList) {
        if (menu.getParentId().equals(parentIds.peek())) {
            resList.add(menu);
            parentIds.push(menu.getId());
            menuList.remove(menu);
            hasChild = true;
            break;
        }
    }
    if (!hasChild) {
        parentIds.pop();
    }
    menuSort(menuList, parentIds, resList);
}
 
开发者ID:DomKing,项目名称:springbootWeb,代码行数:27,代码来源:SecurityController.java

示例5: getNamingContextName

import java.util.Stack; //导入方法依赖的package包/类
/**
 * Get naming context full name.
 */
private String getNamingContextName() {
if (namingContextName == null) {
    Container parent = getParent();
    if (parent == null) {
    namingContextName = getName();
    } else {
    Stack<String> stk = new Stack<String>();
    StringBuilder buff = new StringBuilder();
    while (parent != null) {
        stk.push(parent.getName());
        parent = parent.getParent();
    }
    while (!stk.empty()) {
        buff.append("/" + stk.pop());
    }
    buff.append(getName());
    namingContextName = buff.toString();
    }
}
return namingContextName;
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:25,代码来源:StandardContext.java

示例6: getAllFields

import java.util.Stack; //导入方法依赖的package包/类
/**
 * Including super class fields.
 */
List<VariableElement> getAllFields(TypeElement subclazz) {
    List<VariableElement> fields = new ArrayList<VariableElement>();
    TypeElement cd = null;
    Stack<TypeElement> s = new Stack<TypeElement>();

    cd = subclazz;
    while (true) {
        s.push(cd);
        TypeElement c = (TypeElement) (types.asElement(cd.getSuperclass()));
        if (c == null)
            break;
        cd = c;
    }

    while (!s.empty()) {
        cd = s.pop();
        fields.addAll(ElementFilter.fieldsIn(cd.getEnclosedElements()));
    }

    return fields;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:25,代码来源:JNIWriter.java

示例7: printStack

import java.util.Stack; //导入方法依赖的package包/类
public static void printStack(Stack s,String title,JTextArea t)
{
	Stack s1 = (Stack)s.clone();
	String output = newLineStr + title + ":";
	while (!s1.empty())
	{
		Entry entry = (Entry)s1.pop();
		String str = TabConverter.revert(entry.getPart());
		output += (newLineStr + str);
		int tag = entry.getTag();
		if(tag != -1)
			str = " < " + analyser.Analyser.Tags.getString(String.valueOf(tag)) + " > ";
		else str = "";

		output += (str);
	}

	output += newLineStr + "---------------";
	t.append(output);
}
 
开发者ID:tacola-auceg,项目名称:spellchecker_ta,代码行数:21,代码来源:Utils.java

示例8: isBalanced

import java.util.Stack; //导入方法依赖的package包/类
/**
Checks if a string is balanced or not.

 @param s is a non-null string
 @return true of the input <code>s</code> is balanced and false otherwise.
**/
public static boolean isBalanced(String s){
  Stack<Character> stack = new Stack<Character>();
  HashMap<Character, Character> symbols = new HashMap<Character, Character>();

  symbols.put(')' , '(');
  symbols.put('}' , '{');
  symbols.put(']' , '[');

  for (int i = 0; i < s.length(); i++) {
    char c = s.charAt(i);
    if (symbols.containsValue(c)) {
      stack.push(c);
    }
    if (symbols.containsKey(c)) {
      if (stack.empty()) {
        return false;
      } else {
        Character temp = stack.pop();
        if (temp != symbols.get(c)) {
          return false;
        }
      }
    }
  }
  if (stack.empty()) {
    return true;
  }
  return false;
}
 
开发者ID:hughxie,项目名称:class-code,代码行数:36,代码来源:Balanced.java

示例9: main

import java.util.Stack; //导入方法依赖的package包/类
public static void main(String [] args) throws Exception{
    LinkedList<String> listOfFiles = new LinkedList<>();
    File baseDirectory = new File("");
    Stack<File> dirStack = new Stack<>();
    dirStack.push(baseDirectory);
    System.out.println(baseDirectory.getCanonicalFile());
    while (!dirStack.empty()){
        File currentFile = dirStack.pop().getCanonicalFile();
        if(currentFile.isDirectory()){
            File [] files = currentFile.listFiles();
            for(File f:files){
                dirStack.push(f);
            }
        }else{
            if(currentFile.toString().endsWith(".java")) {
                listOfFiles.add(currentFile.getAbsolutePath());
            }
        }
    }
    listOfFiles.addFirst("src");
    listOfFiles.addFirst("--module-source-path");
    listOfFiles.addFirst("mods");
    listOfFiles.addFirst("-d");
    listOfFiles.addFirst("javac");
    runProcessAndWaitForCompletion(listOfFiles.toArray(new String[0]));
    listOfFiles.clear();
}
 
开发者ID:PacktPublishing,项目名称:Java-SE-9-Road-to-Concurrent-and-High-Performance-Programming,代码行数:28,代码来源:Builder.java

示例10: collectDefinitionsWithAliases

import java.util.Stack; //导入方法依赖的package包/类
/**
 * Collect definitions of l in body including the definitions of aliases of l.
 *                                                                                                                                                                                           
 * In this context an alias is a local that propagates its value to l.
 *
 * @param l the local whose definitions are to collect
 * @param localDefs the LocalDefs object
 * @param body the body that contains the local
 */
protected List<Unit> collectDefinitionsWithAliases(Local l) {
  Set<Local> seenLocals = new HashSet<Local>();
  Stack<Local> newLocals = new Stack<Local>();
  List<Unit> defs = new LinkedList<Unit>();
  newLocals.push(l);

  while (!newLocals.empty()) {
    Local local = newLocals.pop();
    logger.debug("[null local] "+ local);
    if (seenLocals.contains(local))
      continue;
    for (Unit u : collectDefinitions(local)) {
      if (u instanceof AssignStmt) {
        Value r = (Value) ((AssignStmt) u).getRightOp();
        if (r instanceof Local && ! seenLocals.contains((Local) r)) 
          newLocals.push((Local) r); 
      }   
      defs.add(u);
      //  
      @SuppressWarnings("unchecked")
      List<UnitValueBoxPair> usesOf = (List<UnitValueBoxPair>) localUses.getUsesOf(u);
      for (UnitValueBoxPair pair : usesOf) {
        Unit unit = pair.getUnit();
        if (unit instanceof AssignStmt) {
          Value right = (Value) ((AssignStmt) unit).getRightOp();
          Value left = (Value) ((AssignStmt) unit).getLeftOp();
          if (right == local  && left instanceof Local && ! seenLocals.contains((Local) left))
            newLocals.push((Local) left);
        }   
      }   
      //  
    }   
    seenLocals.add(local);
  }   
  return defs;
}
 
开发者ID:Alexandre-Bartel,项目名称:permission-map,代码行数:46,代码来源:LocalDefinition.java

示例11: 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;
	}
 
开发者ID:tacola-auceg,项目名称:spellchecker_ta,代码行数:37,代码来源:Analyser.java

示例12: printListReversingly

import java.util.Stack; //导入方法依赖的package包/类
public void printListReversingly (ListNode head) {
    Stack<ListNode> stack = new Stack<ListNode>();
    ListNode temp = head;
    while (temp != null) {
        stack.push(temp);
        temp = temp.next;
    }

    while (!stack.empty()) {
        ListNode node = stack.peek();
        System.out.print(node.val + " ");
        stack.pop();
    }
}
 
开发者ID:JoeZ-EE,项目名称:Aim2Offer,代码行数:15,代码来源:005_PrintListInReversedOrder.java

示例13: findMimeType

import java.util.Stack; //导入方法依赖的package包/类
/**
 * Find mime type for a given editor kit implementation class.
 * 
 * @param kitClass The editor kit class to get the mime type for.
 * @return The mime type or <code>null</code> if the mime type can't be
 *   resolved for the given kit class.
 */
public String findMimeType(Class kitClass) {
    if (kitClass != null) {
        if (WELL_KNOWN_PARENTS.contains(kitClass.getName())) {
            // these classes are not directly registered as a kit for any mime type
            return null;
        }

        String contextMimeType = null;
        Stack<String> context = contexts.get();
        if (context != null && !context.empty()) {
            contextMimeType = context.peek();
        }
        
        if (contextMimeType == null || contextMimeType.length() == 0) {
            List mimeTypes = getMimeTypesForKitClass(kitClass);
            if (mimeTypes.size() == 0) {
                if (LOG.isLoggable(Level.WARNING) && !DYNAMIC_LANGUAGES.contains(kitClass.getName())) {
                    logOnce(Level.WARNING, "No mime type uses editor kit implementation class: " + kitClass); //NOI18N
                }
                return null;
            } else if (mimeTypes.size() == 1) {
                return (String) mimeTypes.get(0);
            } else {
                if (LOG.isLoggable(Level.WARNING)) {
    //                Throwable t = new Throwable("Stacktrace"); //NOI18N
    //                LOG.log(Level.WARNING, "Ambiguous mime types for editor kit implementation class: " + kitClass + "; mime types: " + mimeTypes, t); //NOI18N
                    logOnce(Level.WARNING, "Ambiguous mime types for editor kit implementation class: " + kitClass + "; mime types: " + mimeTypes); //NOI18N
                }
                return null;
            }
        } else{
            return contextMimeType;
        }
    } else {
        return ""; //NOI18N
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:45,代码来源:KitsTrackerImpl.java

示例14: buildUrnKeyForFile

import java.util.Stack; //导入方法依赖的package包/类
@Nullable
private String buildUrnKeyForFile(@NotNull PsiFile psiFile, @NotNull MagentoComponent magentoComponent) {
    String prefix = null;

    if (magentoComponent instanceof MagentoModule) {
        prefix = MODULE + ((MagentoModule)magentoComponent).getMagentoName() + ":";
    } else {
        ComposerPackageModel composerPackageModel = magentoComponent.getComposerModel();
        if ("magento2-library".equals(composerPackageModel.getType())) {
            prefix = FRAMEWORK;
        }
    }

    if (prefix == null) {
        return null;
    }

    Stack<String> relativePath = new Stack<>();
    relativePath.push(psiFile.getName());

    PsiManager psiManager = magentoComponent.getDirectory().getManager();
    PsiDirectory parentDir = psiFile.getParent();
    while (parentDir != null && !psiManager.areElementsEquivalent(parentDir, magentoComponent.getDirectory())) {
        relativePath.push("/");
        relativePath.push(parentDir.getName());
        parentDir = parentDir.getParentDirectory();
    }

    StringBuilder stringBuilder = new StringBuilder(prefix);
    while (!relativePath.empty()) {
        stringBuilder.append(relativePath.pop());
    }

    return stringBuilder.toString();
}
 
开发者ID:magento,项目名称:magento2-phpstorm-plugin,代码行数:36,代码来源:SettingsForm.java

示例15: doIt

import java.util.Stack; //导入方法依赖的package包/类
/**
 * Read lines one at a time from r.  After reading all lines, output
 * all lines to w, outputting duplicate lines only once.  Note: the order
 * of the output is unspecified and may have nothing to do with the order
 * that lines appear in r.
 * @param r the reader to read from
 * @param w the writer to write to
 * @throws IOException
 */
public static void doIt(BufferedReader r, PrintWriter w) throws IOException {
			Stack<String> stack = new Stack<String>();

       for (String line = r.readLine(); line != null; line = r.readLine()) {
           stack.push(line);
       }

			while (!stack.empty()) {
				w.println(stack.pop());
			}
}
 
开发者ID:hughxie,项目名称:class-code,代码行数:21,代码来源:Part0.java


注:本文中的java.util.Stack.empty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。