Search in sources :

Example 16 with Stack

use of java.util.Stack in project darkFunction-Editor by darkFunction.

the class CommandManager method init.

private void init() {
    undoStack = new Stack();
    redoStack = new Stack();
}
Also used : Stack(java.util.Stack)

Example 17 with Stack

use of java.util.Stack in project buck by facebook.

the class WorkspaceGenerator method writeWorkspace.

public Path writeWorkspace() throws IOException {
    DocumentBuilder docBuilder;
    Transformer transformer;
    try {
        docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        transformer = TransformerFactory.newInstance().newTransformer();
    } catch (ParserConfigurationException | TransformerConfigurationException e) {
        throw new RuntimeException(e);
    }
    DOMImplementation domImplementation = docBuilder.getDOMImplementation();
    final Document doc = domImplementation.createDocument(/* namespaceURI */
    null, "Workspace", /* docType */
    null);
    doc.setXmlVersion("1.0");
    Element rootElem = doc.getDocumentElement();
    rootElem.setAttribute("version", "1.0");
    final Stack<Element> groups = new Stack<>();
    groups.push(rootElem);
    FileVisitor<Map.Entry<String, WorkspaceNode>> visitor = new FileVisitor<Map.Entry<String, WorkspaceNode>>() {

        @Override
        public FileVisitResult preVisitDirectory(Map.Entry<String, WorkspaceNode> dir, BasicFileAttributes attrs) throws IOException {
            Preconditions.checkArgument(dir.getValue() instanceof WorkspaceGroup);
            Element element = doc.createElement("Group");
            element.setAttribute("location", "container:");
            element.setAttribute("name", dir.getKey());
            groups.peek().appendChild(element);
            groups.push(element);
            return FileVisitResult.CONTINUE;
        }

        @Override
        public FileVisitResult visitFile(Map.Entry<String, WorkspaceNode> file, BasicFileAttributes attrs) throws IOException {
            Preconditions.checkArgument(file.getValue() instanceof WorkspaceFileRef);
            WorkspaceFileRef fileRef = (WorkspaceFileRef) file.getValue();
            Element element = doc.createElement("FileRef");
            element.setAttribute("location", "container:" + MorePaths.relativize(MorePaths.normalize(outputDirectory), fileRef.getPath()).toString());
            groups.peek().appendChild(element);
            return FileVisitResult.CONTINUE;
        }

        @Override
        public FileVisitResult visitFileFailed(Map.Entry<String, WorkspaceNode> file, IOException exc) throws IOException {
            return FileVisitResult.TERMINATE;
        }

        @Override
        public FileVisitResult postVisitDirectory(Map.Entry<String, WorkspaceNode> dir, IOException exc) throws IOException {
            groups.pop();
            return FileVisitResult.CONTINUE;
        }
    };
    walkNodeTree(visitor);
    Path projectWorkspaceDir = getWorkspaceDir();
    projectFilesystem.mkdirs(projectWorkspaceDir);
    Path serializedWorkspace = projectWorkspaceDir.resolve("contents.xcworkspacedata");
    try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
        DOMSource source = new DOMSource(doc);
        StreamResult result = new StreamResult(outputStream);
        transformer.transform(source, result);
        String contentsToWrite = outputStream.toString();
        if (MoreProjectFilesystems.fileContentsDiffer(new ByteArrayInputStream(contentsToWrite.getBytes(Charsets.UTF_8)), serializedWorkspace, projectFilesystem)) {
            projectFilesystem.writeContentsToPath(contentsToWrite, serializedWorkspace);
        }
    } catch (TransformerException e) {
        throw new RuntimeException(e);
    }
    Path xcshareddata = projectWorkspaceDir.resolve("xcshareddata");
    projectFilesystem.mkdirs(xcshareddata);
    Path workspaceSettingsPath = xcshareddata.resolve("WorkspaceSettings.xcsettings");
    String workspaceSettings = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\"" + " \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n" + "<plist version=\"1.0\">\n" + "<dict>\n" + "\t<key>IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded</key>\n" + "\t<false/>\n" + "</dict>\n" + "</plist>";
    projectFilesystem.writeContentsToPath(workspaceSettings, workspaceSettingsPath);
    return projectWorkspaceDir;
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) Transformer(javax.xml.transform.Transformer) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) Element(org.w3c.dom.Element) DOMImplementation(org.w3c.dom.DOMImplementation) Document(org.w3c.dom.Document) FileVisitor(java.nio.file.FileVisitor) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) TransformerException(javax.xml.transform.TransformerException) Path(java.nio.file.Path) StreamResult(javax.xml.transform.stream.StreamResult) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Stack(java.util.Stack) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) Map(java.util.Map) SortedMap(java.util.SortedMap)

Example 18 with Stack

use of java.util.Stack in project buck by facebook.

the class CxxBoostTest method parseResults.

@Override
protected ImmutableList<TestResultSummary> parseResults(Path exitCode, Path output, Path results) throws Exception {
    ImmutableList.Builder<TestResultSummary> summariesBuilder = ImmutableList.builder();
    // Process the test run output to grab the individual test stdout/stderr and
    // test run times.
    Map<String, String> messages = Maps.newHashMap();
    Map<String, List<String>> stdout = Maps.newHashMap();
    Map<String, Long> times = Maps.newHashMap();
    try (BufferedReader reader = Files.newBufferedReader(output, Charsets.US_ASCII)) {
        Stack<String> testSuite = new Stack<>();
        Optional<String> currentTest = Optional.empty();
        String line;
        while ((line = reader.readLine()) != null) {
            Matcher matcher;
            if ((matcher = SUITE_START.matcher(line)).matches()) {
                String suite = matcher.group(1);
                testSuite.push(suite);
            } else if ((matcher = SUITE_END.matcher(line)).matches()) {
                String suite = matcher.group(1);
                Preconditions.checkState(testSuite.peek().equals(suite));
                testSuite.pop();
            } else if ((matcher = CASE_START.matcher(line)).matches()) {
                String test = Joiner.on(".").join(testSuite) + "." + matcher.group(1);
                currentTest = Optional.of(test);
                stdout.put(test, Lists.newArrayList());
            } else if ((matcher = CASE_END.matcher(line)).matches()) {
                String test = Joiner.on(".").join(testSuite) + "." + matcher.group(1);
                Preconditions.checkState(currentTest.isPresent() && currentTest.get().equals(test));
                String time = matcher.group(2);
                times.put(test, time == null ? 0 : Long.valueOf(time));
                currentTest = Optional.empty();
            } else if (currentTest.isPresent()) {
                if (ERROR.matcher(line).matches()) {
                    messages.put(currentTest.get(), line);
                } else {
                    Preconditions.checkNotNull(stdout.get(currentTest.get())).add(line);
                }
            }
        }
    }
    // Parse the XML result file for the actual test result summaries.
    Document doc = XmlDomParser.parse(results);
    Node testResult = doc.getElementsByTagName("TestResult").item(0);
    Node testSuite = testResult.getFirstChild();
    visitTestSuite(summariesBuilder, messages, stdout, times, "", testSuite);
    return summariesBuilder.build();
}
Also used : Matcher(java.util.regex.Matcher) ImmutableList(com.google.common.collect.ImmutableList) Node(org.w3c.dom.Node) TestResultSummary(com.facebook.buck.test.TestResultSummary) Document(org.w3c.dom.Document) Stack(java.util.Stack) BufferedReader(java.io.BufferedReader) ImmutableList(com.google.common.collect.ImmutableList) NodeList(org.w3c.dom.NodeList) List(java.util.List)

Example 19 with Stack

use of java.util.Stack in project android_frameworks_base by ParanoidAndroid.

the class FilterGraph method runTypeCheck.

private void runTypeCheck() {
    Stack<Filter> filterStack = new Stack<Filter>();
    Set<Filter> processedFilters = new HashSet<Filter>();
    filterStack.addAll(getSourceFilters());
    while (!filterStack.empty()) {
        // Get current filter and mark as processed
        Filter filter = filterStack.pop();
        processedFilters.add(filter);
        // Anchor output formats
        updateOutputs(filter);
        // Perform type check
        if (mLogVerbose)
            Log.v(TAG, "Running type check on " + filter + "...");
        runTypeCheckOn(filter);
        // Push connected filters onto stack
        for (OutputPort port : filter.getOutputPorts()) {
            Filter target = port.getTargetFilter();
            if (target != null && readyForProcessing(target, processedFilters)) {
                filterStack.push(target);
            }
        }
    }
    // Make sure all ports were setup
    if (processedFilters.size() != getFilters().size()) {
        throw new RuntimeException("Could not schedule all filters! Is your graph malformed?");
    }
}
Also used : NullFilter(android.filterpacks.base.NullFilter) Stack(java.util.Stack) HashSet(java.util.HashSet)

Example 20 with Stack

use of java.util.Stack in project qi4j-sdk by Qi4j.

the class AbstractSQLQuerying method traversePropertyPath.

protected Integer traversePropertyPath(PropertyFunction<?> reference, Integer lastTableIndex, Integer nextAvailableIndex, SQLVendor vendor, TableReferenceBuilder builder, JoinType joinStyle) {
    Stack<QualifiedName> qNameStack = new Stack<>();
    Stack<PropertyFunction<?>> refStack = new Stack<>();
    while (reference != null) {
        qNameStack.add(QualifiedName.fromAccessor(reference.accessor()));
        refStack.add(reference);
        if (reference.traversedProperty() == null && (reference.traversedAssociation() != null || reference.traversedManyAssociation() != null)) {
            Integer lastAssoTableIndex = this.traverseAssociationPath(new TraversedAssoOrManyAssoRef(reference), lastTableIndex, nextAvailableIndex, vendor, builder, joinStyle, true);
            if (lastAssoTableIndex > lastTableIndex) {
                lastTableIndex = lastAssoTableIndex;
                nextAvailableIndex = lastTableIndex + 1;
            }
        }
        reference = reference.traversedProperty();
    }
    PropertyFunction<?> prevRef = null;
    String schemaName = this._state.schemaName().get();
    TableReferenceFactory t = vendor.getTableReferenceFactory();
    BooleanFactory b = vendor.getBooleanFactory();
    ColumnsFactory c = vendor.getColumnsFactory();
    while (!qNameStack.isEmpty()) {
        QualifiedName qName = qNameStack.pop();
        PropertyFunction<?> ref = refStack.pop();
        if (!qName.type().equals(Identity.class.getName())) {
            QNameInfo info = this._state.qNameInfos().get().get(qName);
            if (info == null) {
                throw new InternalError("No qName info found for qName [" + qName + "].");
            }
            String prevTableAlias = TABLE_NAME_PREFIX + lastTableIndex;
            String nextTableAlias = TABLE_NAME_PREFIX + nextAvailableIndex;
            TableReferenceByName nextTable = t.table(t.tableName(schemaName, info.getTableName()), t.tableAlias(nextTableAlias));
            // @formatter:off
            if (prevRef == null) {
                builder.addQualifiedJoin(joinStyle, nextTable, t.jc(b.booleanBuilder(b.eq(c.colName(prevTableAlias, DBNames.ENTITY_TABLE_PK_COLUMN_NAME), c.colName(nextTableAlias, DBNames.ENTITY_TABLE_PK_COLUMN_NAME))).and(b.isNull(c.colName(nextTableAlias, DBNames.QNAME_TABLE_PARENT_QNAME_COLUMN_NAME))).createExpression()));
            } else {
                builder.addQualifiedJoin(joinStyle, nextTable, t.jc(b.booleanBuilder(b.eq(c.colName(prevTableAlias, DBNames.ALL_QNAMES_TABLE_PK_COLUMN_NAME), c.colName(nextTableAlias, DBNames.QNAME_TABLE_PARENT_QNAME_COLUMN_NAME))).and(b.eq(c.colName(prevTableAlias, DBNames.ENTITY_TABLE_PK_COLUMN_NAME), c.colName(nextTableAlias, DBNames.ENTITY_TABLE_PK_COLUMN_NAME))).createExpression()));
            }
            // @formatter:on
            lastTableIndex = nextAvailableIndex;
            ++nextAvailableIndex;
            prevRef = ref;
        }
    }
    return lastTableIndex;
}
Also used : TableReferenceByName(org.sql.generation.api.grammar.query.TableReferenceByName) QualifiedName(org.qi4j.api.common.QualifiedName) ColumnsFactory(org.sql.generation.api.grammar.factories.ColumnsFactory) BooleanFactory(org.sql.generation.api.grammar.factories.BooleanFactory) Stack(java.util.Stack) TableReferenceFactory(org.sql.generation.api.grammar.factories.TableReferenceFactory) PropertyFunction(org.qi4j.api.query.grammar.PropertyFunction) QNameInfo(org.qi4j.index.sql.support.common.QNameInfo)

Aggregations

Stack (java.util.Stack)245 HashSet (java.util.HashSet)42 ArrayList (java.util.ArrayList)37 File (java.io.File)23 IOException (java.io.IOException)22 View (android.view.View)18 Test (org.junit.Test)18 ViewGroup (android.view.ViewGroup)14 HashMap (java.util.HashMap)14 Set (java.util.Set)12 LinkedList (java.util.LinkedList)11 List (java.util.List)11 ImageView (android.widget.ImageView)10 Map (java.util.Map)10 Document (org.w3c.dom.Document)10 TestInputHandler (org.apache.maven.plugins.repository.testutil.TestInputHandler)9 PostfixMathCommandI (org.nfunk.jep.function.PostfixMathCommandI)9 DocumentBuilder (javax.xml.parsers.DocumentBuilder)8 NotificationPanelView (com.android.systemui.statusbar.phone.NotificationPanelView)7 TreeSet (java.util.TreeSet)7