List of usage examples for java.util Deque pop
E pop();
From source file:org.interreg.docexplore.util.ZipUtils.java
public static void zip(File directory, File[] files, File zipfile, float[] progress, float progressOffset, float progressAmount, int level) throws Exception { URI base = directory.toURI(); Deque<File> queue = new LinkedList<File>(); OutputStream out = new FileOutputStream(zipfile, false); Closeable res = null;//from w w w . jav a 2 s. c om try { int nEntries = count(files, queue, 0); while (!queue.isEmpty()) { File dir = queue.pop(); nEntries = count(dir.listFiles(), queue, nEntries); } ZipArchiveOutputStream zout = (ZipArchiveOutputStream) new ArchiveStreamFactory() .createArchiveOutputStream(ArchiveStreamFactory.ZIP, out); zout.setLevel(level); res = zout; int cnt = zip(files, queue, base, 0, nEntries, progress, progressOffset, progressAmount, zout); while (!queue.isEmpty()) { File dir = queue.pop(); cnt = zip(dir.listFiles(), queue, base, cnt, nEntries, progress, progressOffset, progressAmount, zout); } } finally { res.close(); } }
From source file:org.jasig.portal.layout.TransientUserLayoutXMLEventReader.java
@Override protected XMLEvent getPeekEvent(XMLEvent event) { //Not the most efficient way of doing this since the whole deque is built but we only need the first element. final Deque<XMLEvent> additionalEvents = this.getAdditionalEvents(event); if (additionalEvents != null) { return additionalEvents.pop(); }//from ww w . j a v a 2 s.c o m return null; }
From source file:org.lilyproject.repository.impl.AbstractTypeManager.java
private void collectSubTypes(SchemaId recordTypeId, Set<SchemaId> result, Deque<SchemaId> parents, boolean recursive) throws InterruptedException { // the parent-stack is to protect against endless loops in the type hierarchy. If a type is a subtype // of itself, it will not be included in the result. Thus if record type A extends (directly or indirectly) // from A, and we search the subtypes of A, then the resulting set will not include A. parents.push(recordTypeId);/*from ww w .j ava 2 s . c o m*/ Set<SchemaId> subtypes = schemaCache.findDirectSubTypes(recordTypeId); for (SchemaId subtype : subtypes) { if (!parents.contains(subtype)) { result.add(subtype); if (recursive) { collectSubTypes(subtype, result, parents, recursive); } } else { // Loop detected in type hierarchy, log a warning about this log.warn(formatSupertypeLoopError(subtype, parents)); } } parents.pop(); }
From source file:org.lilyproject.repository.impl.HBaseTypeManager.java
private RecordType updateRecordType(RecordType recordType, boolean refreshSubtypes, Deque<SchemaId> parents) throws RepositoryException, InterruptedException { // First update the record type RecordType updatedRecordType = updateRecordType(recordType); if (!refreshSubtypes) { return updatedRecordType; }/*from w w w .j a va2s . c om*/ parents.push(updatedRecordType.getId()); try { Set<SchemaId> subtypes = findDirectSubtypes(updatedRecordType.getId()); for (SchemaId subtype : subtypes) { if (!parents.contains(subtype)) { RecordType subRecordType = getRecordTypeById(subtype, null); for (Map.Entry<SchemaId, Long> supertype : subRecordType.getSupertypes().entrySet()) { if (supertype.getKey().equals(updatedRecordType.getId())) { if (!supertype.getValue().equals(updatedRecordType.getVersion())) { subRecordType.addSupertype(updatedRecordType.getId(), updatedRecordType.getVersion()); // Store the change, and recursively adjust the pointers in this record type's subtypes as well updateRecordType(subRecordType, true, parents); } break; } } } else { // Loop detected in type hierarchy, log a warning about this log.warn(formatSupertypeLoopError(subtype, parents)); } } } catch (RepositoryException e) { throw new RepositoryException("Error while refreshing subtypes of record type " + recordType.getName(), e); } parents.pop(); return updatedRecordType; }
From source file:org.lunarray.model.descriptor.builder.annotation.resolver.entity.def.DefaultEntityResolver.java
/** {@inheritDoc} */ @Override/*from w w w .j av a 2s .com*/ public DescribedEntity<?> resolveEntity(final Class<?> entityType) { DefaultEntityResolver.LOGGER.debug("Resolving entity {}", entityType); Validate.notNull(entityType, "Entity type may not be null."); @SuppressWarnings("unchecked") final EntityBuilder<?> builder = DescribedEntity.createBuilder().entityType((Class<Object>) entityType); final List<Class<?>> hierarchy = new LinkedList<Class<?>>(); if (this.searchHierarchyResolver) { final Deque<Class<?>> types = new LinkedList<Class<?>>(); final Set<Class<?>> processed = new HashSet<Class<?>>(); types.add(entityType); while (!types.isEmpty()) { final Class<?> next = types.pop(); hierarchy.add(next); final Class<?> superType = next.getSuperclass(); if (!CheckUtil.isNull(superType) && !processed.contains(superType)) { types.add(superType); } for (final Class<?> interfaceType : next.getInterfaces()) { if (!processed.contains(interfaceType)) { types.add(interfaceType); } } processed.add(next); } } else { hierarchy.add(entityType); } for (final Class<?> type : hierarchy) { for (final Annotation a : type.getAnnotations()) { builder.addAnnotation(a); } } final DescribedEntity<?> result = builder.build(); DefaultEntityResolver.LOGGER.debug("Resolved entity {} for type {}", result, entityType); return result; }
From source file:org.molasdin.wbase.xml.parser.light.basic.BasicParser.java
@Override public Element parse(String value) throws ParserException { Deque<BasicElement> elements = new LinkedList<BasicElement>(); int index = 0; boolean leftAngleFound = false; int leftAngleIndex = 0; boolean possibleCloseTag = false; int closeSlashIndex = 0; BasicElement rootElement = new BasicElement(); rootElement.setValid(true);/* ww w . j a va2 s . com*/ elements.push(rootElement); while (index < value.length()) { if (value.charAt(index) == '<') { //if '<' is before '<' if (leftAngleFound) { //treat it as '<' symbol //build string from the first '<' till the current String entry = value.substring(leftAngleIndex, index); appendText(entry, elements.peekFirst()); invokeHandlers(value, leftAngleIndex, ErrorType.LESS_FOUND, ""); } leftAngleFound = true; leftAngleIndex = index; possibleCloseTag = false; } else if (value.charAt(index) == '/') { //if '<' has been found if (leftAngleFound) { //slash may be in closing tag closeSlashIndex = index; possibleCloseTag = true; } else { appendText("/", elements.peekFirst()); } } else if (value.charAt(index) == '>') { //if '>' without '<' before if (!leftAngleFound) { //treat '>' as symbol appendText(">", elements.peekFirst()); invokeHandlers(value, index, ErrorType.GREATER_FOUND, ""); } else { leftAngleFound = false; BasicElement elem = elements.peekFirst(); //check if it is a closing tag if (possibleCloseTag && isEmptyRange(value, leftAngleIndex + 1, closeSlashIndex)) { String tag = StringUtils.trim(value.substring(leftAngleIndex + 2, index)); //if tag is most possible closing if (!elem.isValid()) { //check first opening elem = elements.pop(); if (!elem.tagName().equals(tag)) { BasicElement tmp = elem; elem = elements.pop(); //check outer opening if (!elem.tagName().equals(tag)) { throw new BadClosingTag(elem.tagName(), tag); } invokeHandlers(value, -1, ErrorType.NO_CLOSING, tmp.tagName()); elem.consumeContent(tmp); elem.setValid(true); } } else { //closing tag without opening throw new BadClosingTag("", tag); } elem.setClosed(true); elem.setValid(true); elem.setValidClosing(true); } else { //tag is most possible opening or self closing int rightOffset = index; if (possibleCloseTag) { //check if tag is closing but with characters between "<" and "/" if (!elem.isValid()) { String possibleTag = value.substring(closeSlashIndex + 1, index); if (elem.tagName().equals(possibleTag)) { throw new CharactersInClosing(leftAngleIndex); } } //check if "/" is in attributes if (value.substring(closeSlashIndex + 1, rightOffset).trim().length() == 0) { rightOffset = closeSlashIndex; } else { //tag is no closing possibleCloseTag = false; } } //possible start tag String tagName = value.substring(leftAngleIndex + 1, rightOffset); //if no tag but '<>' if (tagName.length() == 0) { //add them to characters String entry = value.substring(leftAngleIndex, index + 1); appendText(entry, elem); invokeHandlers(value, leftAngleIndex, ErrorType.EMPTY_TAG_FOUND, entry); } else { Pair<String, List<Pair<String, String>>> tag = extractTag(tagName); if (tag == null || tag.getLeft() == null) { invokeHandlers(value, leftAngleIndex, ErrorType.INVALID_TEXT_IN_TAG_NAME, String.valueOf(index)); String entry = value.substring(leftAngleIndex, index + 1); appendText(entry, elements.peekFirst()); } else { tagName = tag.getLeft(); //if tag is allowed if (!predicate.evaluate(tagName)) { throw new DisallowedTagFound(tagName); } //add new element with this tag BasicElement newElem = new BasicElement(); newElem.setTagName(tagName); newElem.setAttributes(tag.getRight()); elements.peekFirst().addChild(newElem); if (possibleCloseTag) { newElem.setClosed(true); newElem.setShortenIfEmpty(true); newElem.setValid(true); newElem.setValidClosing(true); } else { elements.push(newElem); } } } } possibleCloseTag = false; } } else if (!leftAngleFound) { //characters block BasicElement elem = elements.peekFirst(); //if other elements exist between tag characters parts elem.addCharacter(value.charAt(index)); /* if (elementTextBreak) { elementTextBreak = false; elem.addCharacter(value.charAt(index)); } else { elem.lastCharacters().append(value.charAt(index)); }*/ } index++; } //if last '<' has not been closed if (leftAngleFound) { //treat it as symbol appendText(value.substring(leftAngleIndex, value.length()), elements.peekFirst()); invokeHandlers(value, leftAngleIndex, ErrorType.LESS_FOUND, ""); } //find unclosed elements if (elements.size() > 1) { for (BasicElement elem : elements) { if (elem == rootElement) { continue; } if (!elem.isClosed() && !elem.isValid()) { invokeHandlers(value, -1, ErrorType.NO_CLOSING, elem.tagName()); ((BasicElement) elem.parent()).consumeContent(elem); } } } return rootElement; }
From source file:org.nuxeo.ecm.platform.routing.core.impl.GraphRouteImpl.java
/** * Finds which transitions are re-looping (feedback arc set). *///from ww w.j av a2 s.co m protected void computeLoopTransitions(String startNodeId) throws DocumentRouteException { if (startNodeId == null) { // incomplete graph return; } /* * Depth-first search. In the todo stack, each element records a list of the siblings left to visit at that * depth. After visiting the last sibling, we go back to the parent and at this point mark it as visited in * post-traversal order. */ List<String> postOrder = new LinkedList<String>(); Deque<Deque<String>> stack = new LinkedList<Deque<String>>(); Deque<String> first = new LinkedList<String>(); first.add(startNodeId); stack.push(first); Set<String> done = new HashSet<String>(); for (;;) { // find next sibling String nodeId = stack.peek().peek(); if (nodeId == null) { // last sibling done // go back up one level and mark post-traversal order stack.pop(); // pop empty children if (stack.isEmpty()) { // we are done break; } nodeId = stack.peek().pop(); // pop parent postOrder.add(nodeId); // mark post-traversal order } else if (done.add(nodeId)) { // traverse the next sibling Deque<String> children = new LinkedList<String>(); for (Transition t : getNode(nodeId).getOutputTransitions()) { children.add(t.target); } // add children to stack and recurse stack.push(children); } else { // already traversed stack.peek().pop(); // skip it } } // reverse the post-order to find the topological ordering Collections.reverse(postOrder); Map<String, Integer> ordering = new HashMap<String, Integer>(); int i = 1; for (String nodeId : postOrder) { ordering.put(nodeId, Integer.valueOf(i++)); } // walk the graph and all transitions again // and mark as looping the transitions pointing to a node // with a smaller order that the source done.clear(); Deque<String> todo = new LinkedList<String>(); todo.add(startNodeId); while (!todo.isEmpty()) { String nodeId = todo.pop(); if (done.add(nodeId)) { int source = ordering.get(nodeId).intValue(); for (Transition t : getNode(nodeId).getOutputTransitions()) { todo.push(t.target); // compare orders to detected feeback arcs int target = ordering.get(t.target).intValue(); if (target <= source) { t.loop = true; } } } } }
From source file:org.polymap.model2.store.geotools.FeatureTypeBuilder.java
protected ComplexType buildComplexType(Class<? extends Composite> compositeClass, String indent) throws Exception { // fields -> properties Collection<PropertyDescriptor> properties = new ArrayList(); // super classes and mixins Deque<Class> stack = new ArrayDeque(); stack.push(compositeClass);// w ww. j a v a 2s .c om while (!stack.isEmpty()) { Class type = stack.pop(); log.debug(indent + "Composite: " + type); // super class if (type.getSuperclass() != null && !Entity.class.equals(type.getSuperclass()) && !Composite.class.equals(type.getSuperclass())) { stack.push(type.getSuperclass()); } // mixins CompositeInfoImpl typeInfo = new CompositeInfoImpl(type); //log.debug( indent + " " + "Mixins: " + typeInfo.getMixins() ); stack.addAll(typeInfo.getMixins()); // fields for (Field field : type.getDeclaredFields()) { // Property or CollectionProperty if (Property.class.isAssignableFrom(field.getType()) || CollectionProperty.class.isAssignableFrom(field.getType())) { PropertyInfoImpl propInfo = new PropertyInfoImpl(field); Class<?> binding = propInfo.getType(); // attribute if (binding.isPrimitive() || binding.equals(String.class) || Number.class.isAssignableFrom(binding) || Boolean.class.isAssignableFrom(binding) || Date.class.isAssignableFrom(binding) || binding.isEnum()) { if (binding.isEnum()) { binding = String.class; } AttributeType propType = buildAttributeType(field, binding); AttributeDescriptor desc = factory.createAttributeDescriptor(propType, propType.getName(), 0, propInfo.getMaxOccurs(), propInfo.isNullable(), propInfo.getDefaultValue()); properties.add(desc); log.debug(indent + " " + "Attribute: " + desc); } // geometry else if (Geometry.class.isAssignableFrom(binding)) { AttributeType propType = buildAttributeType(field, binding); GeometryType geomType = factory.createGeometryType(propType.getName(), propType.getBinding(), crs, propType.isIdentified(), propType.isAbstract(), propType.getRestrictions(), propType.getSuper(), propType.getDescription()); GeometryDescriptor desc = factory.createGeometryDescriptor(geomType, geomType.getName(), 0, 1, propInfo.isNullable(), propInfo.getDefaultValue()); properties.add(desc); log.debug(indent + " " + "Geometry: " + desc); } // complex else if (Composite.class.isAssignableFrom(binding)) { ComplexType propType = buildComplexType((Class<? extends Composite>) binding, indent + " "); AttributeDescriptor desc = factory.createAttributeDescriptor(propType, nameInStore(field), 0, propInfo.getMaxOccurs(), propInfo.isNullable(), propInfo.getDefaultValue()); properties.add(desc); log.debug(indent + " " + "Complex Property: " + desc); } else { throw new RuntimeException("Property value type is not supported: " + binding); } } } } NameInStore nameInStore = compositeClass.getAnnotation(NameInStore.class); Name name = buildName(nameInStore != null ? nameInStore.value() : compositeClass.getSimpleName()); boolean isIdentified = false; boolean isAbstract = false; List<Filter> restrictions = null; AttributeType superType = null; Description annotation = compositeClass.getAnnotation(Description.class); InternationalString description = annotation != null ? SimpleInternationalString.wrap(annotation.value()) : null; return factory.createComplexType(name, properties, isIdentified, isAbstract, restrictions, superType, description); }
From source file:org.polymap.rhei.form.BasePageContainer.java
protected void updateEnabled() { if (pageBody == null || pageBody.isDisposed()) { return;/*from w w w. ja v a 2s. c o m*/ } Deque<Control> deque = new LinkedList(Collections.singleton(pageBody)); while (!deque.isEmpty()) { Control control = deque.pop(); String variant = (String) control.getData(RWT.CUSTOM_VARIANT); log.debug("VARIANT: " + variant + " (" + control.getClass().getSimpleName() + ")"); log.warn("!!! NOT YET (RE)IMPLEMENTED !!!"); // // form fields // if (variant == null // || variant.equals( CSS_FORMFIELD ) || variant.equals( CSS_FORMFIELD_DISABLED ) // || variant.equals( CUSTOM_VARIANT_VALUE ) || variant.equals( CUSTOM_VARIANT_VALUE )) { // UIUtils.setVariant( control, enabled ? CSS_FORMFIELD : CSS_FORMFIELD_DISABLED ); // } // // form // else if (variant.equals( CSS_FORM ) || variant.equals( CSS_FORM_DISABLED )) { // UIUtils.setVariant( control, enabled ? CSS_FORM : CSS_FORM_DISABLED ); // } // // labeler Label // String labelVariant = (String)control.getData( WidgetUtil.CUSTOM_VARIANT ); // if (control instanceof Label // && (labelVariant.equals( CSS_FORMFIELD ) || labelVariant.equals( CSS_FORMFIELD_DISABLED ))) { // control.setFont( enabled // ? JFaceResources.getFontRegistry().get( JFaceResources.DEFAULT_FONT ) // : JFaceResources.getFontRegistry().getBold( JFaceResources.DEFAULT_FONT ) ); // // if (!enabled) { // control.setBackground( Graphics.getColor( 0xED, 0xEF, 0xF1 ) ); // } // } // Composite if (control instanceof Composite) { control.setEnabled(enabled); deque.addAll(Arrays.asList(((Composite) control).getChildren())); } variant = (String) control.getData(RWT.CUSTOM_VARIANT); log.debug(" -> " + variant + " (" + control.getClass().getSimpleName() + ")"); } }
From source file:org.polymap.rhei.form.batik.BatikFilterContainer.java
@Override protected void updateEnabled() { if (pageBody == null || pageBody.isDisposed()) { return;//w w w .ja v a 2 s . c o m } Deque<Control> deque = new LinkedList(Collections.singleton(pageBody)); while (!deque.isEmpty()) { Control control = deque.pop(); String variant = (String) control.getData(RWT.CUSTOM_VARIANT); log.debug("VARIANT: " + variant + " (" + control.getClass().getSimpleName() + ")"); // form fields if (variant == null || variant.equals(BatikFormContainer.CSS_FORMFIELD) || variant.equals(BatikFormContainer.CSS_FORMFIELD_DISABLED) || variant.equals(BaseFieldComposite.CUSTOM_VARIANT_VALUE)) { UIUtils.setVariant(control, enabled ? BatikFormContainer.CSS_FORMFIELD : BatikFormContainer.CSS_FORMFIELD_DISABLED); } // form else if (variant.equals(BatikFormContainer.CSS_FORM) || variant.equals(BatikFormContainer.CSS_FORM_DISABLED)) { UIUtils.setVariant(control, enabled ? BatikFormContainer.CSS_FORM : BatikFormContainer.CSS_FORM_DISABLED); } // // labeler Label // String labelVariant = (String)control.getData( WidgetUtil.CUSTOM_VARIANT ); // if (control instanceof Label // && (labelVariant.equals( CSS_FORMFIELD ) || labelVariant.equals( CSS_FORMFIELD_DISABLED ))) { // control.setFont( enabled // ? JFaceResources.getFontRegistry().get( JFaceResources.DEFAULT_FONT ) // : JFaceResources.getFontRegistry().getBold( JFaceResources.DEFAULT_FONT ) ); // // if (!enabled) { // control.setBackground( Graphics.getColor( 0xED, 0xEF, 0xF1 ) ); // } // } // Composite if (control instanceof Composite) { control.setEnabled(enabled); deque.addAll(Arrays.asList(((Composite) control).getChildren())); } variant = (String) control.getData(RWT.CUSTOM_VARIANT); log.debug(" -> " + variant + " (" + control.getClass().getSimpleName() + ")"); } }