List of usage examples for java.util Stack push
public E push(E item)
From source file:gr.abiss.calipso.wicket.customattrs.CustomAttributeUtils.java
/** * Parses the given user intput to create the custom attribute lookup values (options) and their translations, * then add them to the given CustomAttribute. * @param optionsTextIput// w w w .j a v a 2 s . c om * @param attribute * @param languages */ public static void parseOptionsIntoAttribute(Map<String, String> optionsTextIput, CustomAttribute attribute, List<Language> languages) { //logger.info("parseOptionsIntoAttribute, attribute: "+attribute); // add options attribute.setPersistedVersion(attribute.getVersion()); attribute.setVersion(attribute.getVersion() + 1); attribute.removeAllLookupValues(); List<CustomAttributeLookupValue> optionsList = new LinkedList<CustomAttributeLookupValue>(); String languageId = null; for (Language language : languages) { if (languageId == null) { languageId = language.getId(); } String input = optionsTextIput.get(language.getId()); //logger.info("textAreaOptions.get(language.getId(): "+input); if (StringUtils.isNotBlank(input)) { Stack<CustomAttributeLookupValue> parents = new Stack<CustomAttributeLookupValue>(); String[] lines = input.split("\\r?\\n"); int listIndex = -1; for (int j = 0; j < lines.length; j++) { listIndex++; // count whitespace characters to determine level String line = lines[j]; //logger.info("Reading option line: "+line); int countLevel = 1; int limit = line.length(); for (int i = 0; i < limit; ++i) { if (Character.isWhitespace(line.charAt(i))) { ++countLevel; } else { break; } } String translatedName = line.substring(countLevel - 1).trim(); //logger.info("translatedName: "+translatedName); // build CustomAttributeLookupValue if it doesn't already exist CustomAttributeLookupValue lookupValue; if (language.getId().equalsIgnoreCase(languageId)) { //logger.info("creating new lookupValue and adding to list index " + listIndex + " for " + translatedName); lookupValue = new CustomAttributeLookupValue(); optionsList.add(lookupValue); } else { //logger.info("trying to get lookupValue from list index " + listIndex + "for "+translatedName); lookupValue = optionsList.get(listIndex); } lookupValue.setShowOrder(listIndex); if (language.getId().equalsIgnoreCase("en")) { lookupValue.setName(translatedName); lookupValue.setValue(translatedName); } lookupValue.setLevel(countLevel); // fix parent/child while ((!parents.isEmpty()) && parents.peek().getLevel() >= lookupValue.getLevel()) { parents.pop(); } // pile it if (lookupValue.getLevel() > 1) { //logger.info("Adding child "+lookupValue.getName() + "to parent " +parents.peek()); parents.peek().addChild(lookupValue); } parents.push(lookupValue); // add the translation //logger.info("Adding lookup value "+language.getId()+" translation: "+translatedName); lookupValue.addNameTranslation(language.getId(), translatedName); //logger.info("translations afre now: "+lookupValue.getNameTranslations()); } } //Set<CustomAttributeLookupValue> lookupValueSet = new HashSet<CustomAttributeLookupValue>(); //lookupValueSet.addAll(optionsList); } // update attribute lookup values attribute.removeAllLookupValues(); /* List<CustomAttributeLookupValue> toRemove = new LinkedList<CustomAttributeLookupValue>(); for(CustomAttributeLookupValue value : attribute.getAllowedLookupValues()){ toRemove.add(value); } attribute.removeAll(toRemove);*/ for (CustomAttributeLookupValue value : optionsList) { //logger.info("Adding lookupValue with translations: "+value.getNameTranslations()); attribute.addAllowedLookupValue(value); } //logger.info("Added lookup values: "+attribute.getAllowedLookupValues()); }
From source file:com.taobao.tdhs.jdbc.sqlparser.ParseSQL.java
private boolean checkSpecialStr(String sqlstring, String searchStr) { //????searchStr Stack<String> stack = new Stack<String>(); boolean exist_danyinhao = false; for (int i = 0; i < sqlstring.length(); i++) { ///*from w ww. j av a2s . c o m*/ if (sqlstring.substring(i, i + 1).equals("'") == false) { stack.push(sqlstring.substring(i, i + 1)); } //' if (sqlstring.substring(i, i + 1).equals("'")) { //?\,?,\,,?? int count = 0; int k = i; boolean real_danyinhao; while (k - 1 >= 0 && sqlstring.substring(k - 1, k).equals("\\") == true) { k--; count++; } //System.out.println("\\:"+count); if (count % 2 == 0) { //?? real_danyinhao = true; } else { //???,value real_danyinhao = false; stack.push(sqlstring.substring(i, i + 1)); } if (real_danyinhao == true) { if (exist_danyinhao == false) { exist_danyinhao = true; stack.push(sqlstring.substring(i, i + 1)); } else { boolean find_real_danyinhao = false; while (find_real_danyinhao == false) { while (!stack.pop().equals("'")) { ; } //???,??\ if (stack.isEmpty() == false && stack.peek().equals("\\")) { //?,??? count = 0; while (stack.peek().equals("\\")) { stack.pop(); count++; } if (count % 2 == 0) { //? find_real_danyinhao = true; } else { //? find_real_danyinhao = false; } } else { // find_real_danyinhao = true; } } exist_danyinhao = false; } } } } //end for logger.debug(stack.toString()); if (stack.isEmpty() == false && stack.search(searchStr) > -1) { stack.clear(); return true; } else { return false; } }
From source file:com.hippo.vector.VectorDrawable.java
private void inflateInternal(Context context, XmlPullParser parser, AttributeSet attrs) throws XmlPullParserException, IOException { final VectorDrawableState state = mVectorState; final VPathRenderer pathRenderer = state.mVPathRenderer; boolean noPathTag = true; // Use a stack to help to build the group tree. // The top of the stack is always the current group. final Stack<VGroup> groupStack = new Stack<>(); groupStack.push(pathRenderer.mRootGroup); int eventType = parser.getEventType(); while (eventType != XmlPullParser.END_DOCUMENT) { if (eventType == XmlPullParser.START_TAG) { final String tagName = parser.getName(); final VGroup currentGroup = groupStack.peek(); if (SHAPE_PATH.equals(tagName)) { final VFullPath path = new VFullPath(); path.inflate(context, attrs); currentGroup.mChildren.add(path); if (path.getPathName() != null) { pathRenderer.mVGTargetsMap.put(path.getPathName(), path); }//from ww w . j a va 2s .co m noPathTag = false; state.mChangingConfigurations |= path.mChangingConfigurations; } else if (SHAPE_CLIP_PATH.equals(tagName)) { final VClipPath path = new VClipPath(); path.inflate(context, attrs); currentGroup.mChildren.add(path); if (path.getPathName() != null) { pathRenderer.mVGTargetsMap.put(path.getPathName(), path); } state.mChangingConfigurations |= path.mChangingConfigurations; } else if (SHAPE_GROUP.equals(tagName)) { VGroup newChildGroup = new VGroup(); newChildGroup.inflate(context, attrs); currentGroup.mChildren.add(newChildGroup); groupStack.push(newChildGroup); if (newChildGroup.getGroupName() != null) { pathRenderer.mVGTargetsMap.put(newChildGroup.getGroupName(), newChildGroup); } state.mChangingConfigurations |= newChildGroup.mChangingConfigurations; } } else if (eventType == XmlPullParser.END_TAG) { final String tagName = parser.getName(); if (SHAPE_GROUP.equals(tagName)) { groupStack.pop(); } } eventType = parser.next(); } // Print the tree out for debug. if (DBG_VECTOR_DRAWABLE) { printGroupTree(pathRenderer.mRootGroup, 0); } if (noPathTag) { final StringBuilder tag = new StringBuilder(); if (tag.length() > 0) { tag.append(" or "); } tag.append(SHAPE_PATH); throw new XmlPullParserException("no " + tag + " defined"); } }
From source file:org.alfresco.filesys.repo.CifsHelper.java
private void addDescendents(List<NodeRef> pathRootNodeRefs, Stack<String> pathElements, List<NodeRef> results) { if (pathElements.isEmpty()) { // if this method is called with an empty path element stack, then the // current context nodes are the results to be added results.addAll(pathRootNodeRefs); return;// w w w. j av a 2 s . c om } // take the first path element off the stack String pathElement = pathElements.pop(); // iterate over each path root node for (NodeRef pathRootNodeRef : pathRootNodeRefs) { // deal with cyclic relationships by not traversing down any node already in the results if (results.contains(pathRootNodeRef)) { continue; } // get direct descendents along the path List<NodeRef> directDescendents = getDirectDescendents(pathRootNodeRef, pathElement); // recurse onto the descendents addDescendents(directDescendents, pathElements, results); } // restore the path element stack pathElements.push(pathElement); }
From source file:gdt.data.store.Entigrator.java
private static String[] intersect(String[] list1, String[] list2) { if (list2 == null || list1 == null) { return null; }/*from ww w.ja va 2 s. c o m*/ Stack<String> s1 = new Stack<String>(); Stack<String> s2 = new Stack<String>(); for (String aList2 : list2) s2.push(aList2); String line$; boolean found; String member$ = null; while (!s2.isEmpty()) { try { found = false; line$ = s2.pop().toString(); if (line$ == null) continue; for (String aList1 : list1) { member$ = aList1; if (line$.equals(member$)) { found = true; break; } } if (found) Support.addItem(member$, s1); //} } catch (Exception e) { Logger.getLogger(Entigrator.class.getName()).info(":intersect:" + e.toString()); } } int cnt = s1.size(); if (cnt < 1) return new String[0]; String[] res = new String[cnt]; for (int i = 0; i < cnt; i++) res[i] = s1.pop().toString(); return res; }
From source file:org.apache.jackrabbit.core.nodetype.NodeTypeRegistry.java
static void checkForCircularInheritance(Name[] supertypes, Stack<Name> inheritanceChain, Map<Name, QNodeTypeDefinition> ntDefCache) throws InvalidNodeTypeDefException, RepositoryException { for (Name nt : supertypes) { int pos = inheritanceChain.lastIndexOf(nt); if (pos >= 0) { StringBuilder buf = new StringBuilder(); for (int j = 0; j < inheritanceChain.size(); j++) { if (j == pos) { buf.append("--> "); }//from w ww . java 2 s. c o m buf.append(inheritanceChain.get(j)); buf.append(" extends "); } buf.append("--> "); buf.append(nt); throw new InvalidNodeTypeDefException("circular inheritance detected: " + buf.toString()); } try { QNodeTypeDefinition ntd = ntDefCache.get(nt); Name[] sta = ntd.getSupertypes(); if (sta.length > 0) { // check recursively inheritanceChain.push(nt); checkForCircularInheritance(sta, inheritanceChain, ntDefCache); inheritanceChain.pop(); } } catch (NoSuchNodeTypeException nsnte) { String msg = "unknown supertype: " + nt; log.debug(msg); throw new InvalidNodeTypeDefException(msg, nsnte); } } }
From source file:com.taobao.tdhs.jdbc.sqlparser.ParseSQL.java
public TreeNode parseWhere(TreeNode rootnode, String str_where, int loop) { // // w w w . j a va 2s. c o m loop++; if (loop > 10000) return null; String str = str_where.trim(); TreeNode node = new TreeNode(); int addr_and; int addr_or; // ??,?? if (str.substring(0, 1).equalsIgnoreCase("(")) { // ??? // SQL??in,??? Stack<String> stack = new Stack<String>(); int k = 0; String tmp_s; while (k < str.length()) { tmp_s = str.substring(k, k + 1); if (!tmp_s.equalsIgnoreCase(")")) // stack.push(tmp_s); else { // ,?? while (!stack.pop().equalsIgnoreCase("(")) { ; } // ?,,? if (stack.isEmpty()) break; } k++; } // end while if (k == str.length() - 1) { // ?? return parseWhere(rootnode, str.substring(1, k), loop); } else { // ??,and or, if (str.substring(k + 1, k + 6).equalsIgnoreCase(" and ")) { node.node_content = "and"; node.node_type = 4; node.left_node = parseWhere(node, str.substring(1, k), loop); node.right_node = parseWhere(node, str.substring(k + 6), loop); node.parent_node = rootnode; } else if (str.substring(k + 1, k + 5).equalsIgnoreCase(" or ")) { node.node_content = "or"; node.node_type = 4; node.left_node = parseWhere(node, str.substring(1, k), loop); node.right_node = parseWhere(node, str.substring(k + 5), loop); node.parent_node = rootnode; } return node; } } else { addr_and = StringUtils.indexOfIgnoreCase(str, " and "); addr_or = StringUtils.indexOfIgnoreCase(str, " or "); if (addr_and > 0 && addr_or > 0) if (addr_and < addr_or) { // and node.node_content = "and"; node.node_type = 4; node.parent_node = rootnode; node.left_node = parseBase(node, str.substring(0, addr_and).trim()); node.right_node = parseWhere(node, str.substring(addr_and + 5), loop); return node; } else { // or node.node_content = "or"; node.node_type = 4; node.parent_node = rootnode; node.left_node = parseBase(node, str.substring(0, addr_or).trim()); node.right_node = parseWhere(node, str.substring(addr_or + 4), loop); return node; } else if (addr_and > 0) { node.node_content = "and"; node.node_type = 4; node.parent_node = rootnode; node.left_node = parseBase(node, str.substring(0, addr_and).trim()); node.right_node = parseWhere(node, str.substring(addr_and + 5), loop); return node; } else if (addr_or > 0) { node.node_content = "or"; node.node_type = 4; node.parent_node = rootnode; node.left_node = parseBase(node, str.substring(0, addr_or).trim()); node.right_node = parseWhere(node, str.substring(addr_or + 4), loop); return node; } else { // ?? return parseBase(rootnode, str); } } }
From source file:de.betterform.agent.web.event.EventQueue.java
public List<XMLEvent> aggregateEventList() { // Stack is used to "navigate" through the event list LinkedList<XMLEvent> aggregatedFocusList = new LinkedList<XMLEvent>(); Stack<XMLEvent> aggregatedInsertEventsStack = new Stack(); Stack<XMLEvent> aggregatedEmbedEventsStack = new Stack(); ArrayList<XMLEvent> aggregatedEventList = new ArrayList<XMLEvent>(eventList.size()); for (XMLEvent xmlEvent : this.loadEmbedEventList) { aggregatedEventList.add(xmlEvent); }//from w ww. jav a 2s . c o m this.loadEmbedEventList.clear(); for (int i = 0; i < eventList.size(); i++) { XercesXMLEvent xmlEvent = (XercesXMLEvent) eventList.get(i); XercesXMLEvent xmlEventToAdd = new XercesXMLEvent(); // Map PROTOTYPE_CLONED event to betterform-insert-repeatitem or betterform-insert-itemset event // and copy event properties to new created XMLEvent if (xmlEvent.getType().equals(BetterFormEventNames.PROTOTYPE_CLONED)) { if (xmlEvent.getContextInfo("targetName").equals(XFormsConstants.ITEMSET)) { xmlEventToAdd.initXMLEvent("betterform-insert-itemset", xmlEvent.getBubbles(), xmlEvent.getCancelable(), xmlEvent.getContextInfo()); } else { xmlEventToAdd.initXMLEvent("betterform-insert-repeatitem", xmlEvent.getBubbles(), xmlEvent.getCancelable(), xmlEvent.getContextInfo()); } xmlEventToAdd.target = xmlEvent.target; xmlEvent.addProperty("generatedIds", new HashMap()); aggregatedEventList.add(xmlEventToAdd); // push XMLEvent to Stack for further processing aggregatedInsertEventsStack.push(xmlEventToAdd); } // add all generated ids to surrounding betterform-insert-repeatitem or betterform-insert-itemset event else if (xmlEvent.getType().equals(BetterFormEventNames.ID_GENERATED) && aggregatedInsertEventsStack.size() > 0) { XMLEvent aggregatingInsertEvent = aggregatedInsertEventsStack.peek(); ((HashMap) aggregatingInsertEvent.getContextInfo("generatedIds")) .put(xmlEvent.getContextInfo("originalId"), xmlEvent.getContextInfo("targetId")); } // add insert position to surrounding betterform-insert-repeatitem or betterform-insert-itemset event else if (xmlEvent.getType().equals(BetterFormEventNames.ITEM_INSERTED)) { XMLEvent tmpEvent = aggregatedInsertEventsStack.pop(); tmpEvent.addProperty("position", xmlEvent.getContextInfo("position")); tmpEvent.addProperty("label", xmlEvent.getContextInfo("label")); tmpEvent.addProperty("value", xmlEvent.getContextInfo("value")); } else if (xmlEvent.getType().equals(BetterFormEventNames.EMBED)) { aggregatedEventList.add(xmlEvent); aggregatedEmbedEventsStack.push(xmlEvent); } else if (xmlEvent.getType().equals(BetterFormEventNames.EMBED_DONE)) { aggregatedEmbedEventsStack.pop().addProperty("targetElement", xmlEvent.getContextInfo("targetElement")); aggregatedEventList.add(xmlEvent); } else if (xmlEvent.getType().equals(XFormsEventNames.FOCUS)) { aggregatedFocusList.push(xmlEvent); } /* else if(xmlEvent.getType().equals(BetterFormEventNames.INDEX_CHANGED)){ aggregatedFocusList.push(xmlEvent); }*/ // all other events within eventList are simply copied to the new eventlist else { aggregatedEventList.add(xmlEvent); } } while (!aggregatedFocusList.isEmpty()) { aggregatedEventList.add(aggregatedFocusList.pollLast()); } return aggregatedEventList; }
From source file:net.mojodna.searchable.AbstractBeanIndexer.java
/** * Create fields for each property.// w w w .j a v a 2 s . c o m * * @param doc Document to add fields to. * @param fieldname Field name to use. * @param prop Property value. * @param descriptor Property descriptor. * @param stack Stack containing parent field names. * @param inheritedBoost Inherited boost factor. * @return Document with additional fields. * @throws IndexingException */ protected Document addFields(final Document doc, final String fieldname, final Object prop, final PropertyDescriptor descriptor, final Stack<String> stack, final float inheritedBoost) throws IndexingException { if (prop instanceof Date) { // handle Dates specially float boost = SearchableUtils.getBoost(descriptor); // TODO allow resolution to be specified in annotation // TODO serialize as canonical date (for Solr) final Field field = new Field(getFieldname(fieldname, stack), DateTools.dateToString((Date) prop, DateTools.Resolution.SECOND), Field.Store.YES, Field.Index.UN_TOKENIZED); field.setBoost(inheritedBoost * boost); doc.add(field); } else if (prop instanceof Iterable) { // create multiple fields for things that can be iterated over float boost = SearchableUtils.getBoost(descriptor); for (final Object o : (Iterable) prop) { addFields(doc, fieldname, o, descriptor, stack, inheritedBoost * boost); } } else if (prop instanceof Object[]) { // create multiple fields for arrays of things float boost = SearchableUtils.getBoost(descriptor); for (final Object o : (Object[]) prop) { addFields(doc, fieldname, o, descriptor, stack, inheritedBoost * boost); } } else if (prop instanceof Searchable) { // nested Searchables stack.push(fieldname); processBean(doc, (Searchable) prop, stack, inheritedBoost * SearchableUtils.getBoost(descriptor)); stack.pop(); } else { final String value = prop.toString(); float boost = SearchableUtils.getBoost(descriptor); final Field field = new Field(getFieldname(fieldname, stack), value, SearchableUtils.isStored(descriptor), SearchableUtils.getIndexStyle(descriptor), isVectorized(descriptor)); field.setBoost(inheritedBoost * boost); doc.add(field); } return doc; }
From source file:com.google.dart.compiler.metrics.Tracer.java
TraceEvent startImpl(EventType type, String... data) { if (!enabled) { return dummyEvent; }//from www .j a va 2 s . c o m if (data.length % 2 == 1) { throw new IllegalArgumentException("Unmatched data argument"); } Stack<TraceEvent> threadPendingEvents = pendingEvents.get(); TraceEvent parent = null; if (!threadPendingEvents.isEmpty()) { parent = threadPendingEvents.peek(); } else { // reset the thread CPU time base for top-level events (so events can be // properly sequenced chronologically) threadCpuTimeKeeper.resetTimeBase(); } TraceEvent newEvent = new TraceEvent(parent, type, data); // Add a field to the top level event in order to track the base time // so we can re-normalize the data if (threadPendingEvents.size() == 0) { long baseTime = logProcessCpuTime ? processCpuTimeKeeper.zeroTimeMillis() : (logThreadCpuTime ? threadCpuTimeKeeper.zeroTimeMillis() : elapsedTimeKeeper.zeroTimeMillis()); newEvent.addData("baseTime", "" + baseTime); } threadPendingEvents.push(newEvent); return newEvent; }