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


Java Stack.clear方法代码示例

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


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

示例1: readCollectionField

import java.util.Stack; //导入方法依赖的package包/类
/**
 * Read data from the given JSONArray and populate the given Collection
 * 
 * @param json_array
 * @param catalog_db
 * @param collection
 * @param inner_classes
 * @throws Exception
 */
@SuppressWarnings("unchecked")
protected static void readCollectionField(final JSONArray json_array, final Database catalog_db, final Collection collection, final Stack<Class<?>> inner_classes) throws Exception {
    // We need to figure out what the inner type of the collection is
    // If it's a Collection or a Map, then we need to instantiate it before
    // we can call readFieldValue() again for it.
    Class<?> inner_class = inner_classes.pop();
    Collection<Class<?>> inner_interfaces = ClassUtil.getInterfaces(inner_class);
    final Stack<Class<?>> next_inner_classes = new Stack<Class<?>>();
    
    for (int i = 0, cnt = json_array.length(); i < cnt; i++) {
        if (i > 0) next_inner_classes.clear();
        next_inner_classes.addAll(inner_classes);
        assert (next_inner_classes.equals(inner_classes));
        Object value = null;

        // Null
        if (json_array.isNull(i)) {
            value = null;
            // Lists
        } else if (inner_interfaces.contains(List.class)) {
            value = new ArrayList<Object>();
            readCollectionField(json_array.getJSONArray(i), catalog_db, (Collection<?>) value, next_inner_classes);
            // Sets
        } else if (inner_interfaces.contains(Set.class)) {
            value = new HashSet<Object>();
            readCollectionField(json_array.getJSONArray(i), catalog_db, (Collection<?>) value, next_inner_classes);
            // Maps
        } else if (inner_interfaces.contains(Map.class)) {
            value = new HashMap<Object, Object>();
            readMapField(json_array.getJSONObject(i), catalog_db, (Map<Object, Object>) value, next_inner_classes);
            // Values
        } else {
            String json_string = json_array.getString(i);
            value = JSONUtil.getPrimitiveValue(json_string, inner_class, catalog_db);
        }
        collection.add(value);
    } // FOR
    return;
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:49,代码来源:JSONUtil.java

示例2: dirSize

import java.util.Stack; //导入方法依赖的package包/类
private static long dirSize(File file) {
    if (file == null || !file.exists() || !file.isDirectory()) {
        return 0;
    }
    Stack stack = new Stack();
    stack.clear();
    stack.push(file);
    long j = 0;
    while (!stack.isEmpty()) {
        File[] listFiles = ((File) stack.pop()).listFiles();
        long j2 = j;
        int i = 0;
        while (i < listFiles.length) {
            long j3;
            if (listFiles[i].isDirectory()) {
                stack.push(listFiles[i]);
                j3 = j2;
            } else {
                j3 = listFiles[i].length() + j2;
            }
            i++;
            j2 = j3;
        }
        j = j2;
    }
    return j;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:28,代码来源:ResUtil.java

示例3: readMapField

import java.util.Stack; //导入方法依赖的package包/类
/**
 * Read data from the given JSONObject and populate the given Map
 * 
 * @param json_object
 * @param catalog_db
 * @param map
 * @param inner_classes
 * @throws Exception
 */
@SuppressWarnings("unchecked")
protected static void readMapField(final JSONObject json_object, final Database catalog_db, final Map map, final Stack<Class<?>> inner_classes) throws Exception {
    Class<?> key_class = inner_classes.pop();
    Class<?> val_class = inner_classes.pop();
    Collection<Class<?>> val_interfaces = ClassUtil.getInterfaces(val_class);
    final Stack<Class<?>> next_inner_classes = new Stack<Class<?>>();
    
    assert (json_object != null);
    for (String json_key : CollectionUtil.iterable(json_object.keys())) {
        next_inner_classes.clear();
        next_inner_classes.addAll(inner_classes);
        assert (next_inner_classes.equals(inner_classes));

        // KEY
        Object key = JSONUtil.getPrimitiveValue(json_key, key_class, catalog_db);

        // VALUE
        Object object = null;
        if (json_object.isNull(json_key)) {
            // Nothing...
        } else if (val_interfaces.contains(List.class)) {
            object = new ArrayList<Object>();
            readCollectionField(json_object.getJSONArray(json_key), catalog_db, (Collection<?>) object, next_inner_classes);
        } else if (val_interfaces.contains(Set.class)) {
            object = new HashSet<Object>();
            readCollectionField(json_object.getJSONArray(json_key), catalog_db, (Collection<?>) object, next_inner_classes);
        } else if (val_interfaces.contains(Map.class)) {
            object = new HashMap<Object, Object>();
            readMapField(json_object.getJSONObject(json_key), catalog_db, (Map<?,?>) object, next_inner_classes);
        } else {
            String json_string = json_object.getString(json_key);
            try {
                object = JSONUtil.getPrimitiveValue(json_string, val_class, catalog_db);
            } catch (Exception ex) {
                System.err.println("val_interfaces: " + val_interfaces);
                LOG.error("Failed to deserialize value '" + json_string + "' from inner map key '" + json_key + "'");
                throw ex;
            }
        }
        map.put(key, object);
    }
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:52,代码来源:JSONUtil.java

示例4: scanRuleSet

import java.util.Stack; //导入方法依赖的package包/类
public void scanRuleSet() {

          String parent = null; 
          String iterateParent = null;
          String line = null;
          String lineTrimed;
          Stack<String> parentStack = new Stack<>();
          int previousWhitespace = 0;
          int lineNumber = 0;


          while ((line = lineReader.getNextLine()) != null) {

       	   line = line.replaceAll("\\s*(if)*\\s*$", ""); // it trims off whitespace including 'if' at the end of each line due to it could effect on calculating indentation
       	   lineTrimed = line.trim();
       	   int currentWhitespace = 0;
       	   lineNumber++;

               // check the line

               // is it empty?
               if(line.isEmpty()) 
               {
            	   		parentStack.clear();
               }
               else if(line.trim().substring(0, 2).equals("//"))
               {
        	   			//this els if statement is to handle commenting in new line only
            	   		// handling commenting in rule text file needs enhancement later
               }
               
               // does it begin with a white space?
               else if(Character.isWhitespace(line.charAt(0))) 
           	   {
               		currentWhitespace = line.length()-lineTrimed.length(); // calculating indentation level

	                	if (lineTrimed.isEmpty()) // is it a blank line? 
	                	{
	                      // blank line - no parent
	                      parent = null;
	                	} 
	                	else 
	                	{
	                		int indentationDifference = previousWhitespace - currentWhitespace;
	                   	if(indentationDifference == 0 || indentationDifference > 0) //current line is at same level as previous line || current line is in upper level than previous line
	                   	{
	                   		parentStack = handlingStackPop(parentStack, indentationDifference);
	                   		
	                   	}
	                   	else if(indentationDifference < -1) // current line is not a direct child of previous line hence the format is invalid
	                   	{	                   		
	               			//need to handle error
	               			scanFeeder.handleWarning(lineTrimed);
	               			break;	                   		
	                   	}
	                   	
	                   	parent = parentStack.peek();
	           			
	           			String tempLineTrimed = lineTrimed.trim().replaceAll("^(OR\\s?|AND\\s?)?(MANDATORY|OPTIONALLY|POSSIBLY)?(\\s?NOT|\\s?KNOWN)*(NEEDS|WANTS)?", "").trim();
	           			String tempFirstKeywordsGroup = lineTrimed.replace(tempLineTrimed, "").trim();													
	           			parentStack.push(tempLineTrimed.trim()); // due to lineTrimed string contains keywords such as "AND", "OR", "AND KNOWN" or "OR KNOWN" so that it needs removing those keywords for the 'parentStack'
		
		           		// is an indented child	           			
	           			scanFeeder.handleChild(parent, tempLineTrimed, tempFirstKeywordsGroup,lineNumber);	
                    }

               } 
               // does not begin with a white space
               else {
                    // is a parent
           		parentStack.clear();
                   parent = lineTrimed;
                   scanFeeder.handleParent(parent, lineNumber);
                   parentStack.push(parent);
               }
               previousWhitespace = currentWhitespace;
          }
    }
 
开发者ID:DeanLee77,项目名称:Nadia,代码行数:79,代码来源:RuleSetScanner.java

示例5: execute

import java.util.Stack; //导入方法依赖的package包/类
public void execute(Stack<Value> s) throws ShutdownException {
s.clear();
   }
 
开发者ID:BlidiWajdi,项目名称:Mujeed-Arabic-Prolog,代码行数:4,代码来源:ClearSymbol.java


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