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();
}
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;
}
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();
}
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?");
}
}
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;
}
Aggregations