List of usage examples for java.util Stack Stack
public Stack()
From source file:com.espertech.esper.rowregex.EventRowRegexHelper.java
/** * Build a list of start states from the parent node. * @param parent to build start state for * @param variableDefinitions each variable and its expressions * @param variableStreams variable name and its stream number * @return strand of regex state nodes//from www . j a va 2 s . com */ protected static RegexNFAStrandResult recursiveBuildStartStates(RowRegexExprNode parent, Map<String, ExprNode> variableDefinitions, Map<String, Pair<Integer, Boolean>> variableStreams) { Stack<Integer> nodeNumStack = new Stack<Integer>(); RegexNFAStrand strand = recursiveBuildStatesInternal(parent, variableDefinitions, variableStreams, nodeNumStack); // add end state RegexNFAStateEnd end = new RegexNFAStateEnd(); for (RegexNFAStateBase endStates : strand.getEndStates()) { endStates.addState(end); } // assign node num as a counter int nodeNumberFlat = 0; for (RegexNFAStateBase theBase : strand.getAllStates()) { theBase.setNodeNumFlat(nodeNumberFlat++); } return new RegexNFAStrandResult(new ArrayList<RegexNFAState>(strand.getStartStates()), strand.getAllStates()); }
From source file:FlightInfo.java
void route(String to) { int dist = 0; FlightInfo f;//ww w. j av a 2 s .c o m int num = btStack.size(); Stack optTemp = new Stack(); for (int i = 0; i < num; i++) { f = (FlightInfo) btStack.pop(); optTemp.push(f); // save route dist += f.distance; } // If shorter, keep this route if (minDist > dist) { optimal = optTemp; minDist = dist; } }
From source file:com.modelsolv.kaboom.serializer.HalSerializerImpl.java
@Override public String serialize(Object obj, CanonicalObjectReader reader, ResourceDataModel rdm) { objectCount = 0;//w ww . j a v a2 s . c om // The HAL representation we're going to build. Representation rep = createNewRepresentation(obj, reader, rdm); buildObjectRepresentation(rep, obj, reader, rdm, new Stack<Object>()); return rep.toString(halFormat); }
From source file:fr.ritaly.dungeonmaster.item.ItemManager.java
@Override public synchronized void addItem(Item item, Sector sector) { Validate.notNull(item, "The given item is null"); Validate.notNull(sector, "The given sector is null"); if (items == null) { items = new EnumMap<Sector, Stack<Item>>(Sector.class); }//from ww w . jav a2 s . c o m Stack<Item> stack = items.get(sector); if (stack == null) { items.put(sector, stack = new Stack<Item>()); } stack.push(item); fireItemAddedEvent(item, sector); }
From source file:name.martingeisse.ecobuild.moduletool.output.OutputTool.java
@Override public void execute(IModuleToolContext context) throws IOException { FileReader buildScriptReader; try {/* ww w.j av a 2 s .com*/ buildScriptReader = new FileReader(new File(context.getModuleSourceFolder(), "build.txt")); } catch (FileNotFoundException e) { throw new UserMessageBuildException( "Output build script 'build.txt' not found for module " + context.getModuleSourceFolder()); } LineNumberReader lineReader = new LineNumberReader(buildScriptReader); State state = new State(); state.currentFolder = context.getMainBuildFolder(); state.folderStack = new Stack<File>(); while (true) { String line = lineReader.readLine(); if (line == null) { break; } handleLine(context, state, line); } buildScriptReader.close(); }
From source file:logicProteinHypernetwork.networkStates.NetworkEntityToMinimalNetworkStates.java
/** * Calculates all minimally constrained satisfying models using the tableau * algorithm and derives the minimal network states. * //from w ww.j a v a 2 s . c o m * @param e * the network entity * @param f * the minimal network state formula * @param states * the place where all minimal network states are collected */ public void calculateAllTableauPaths(final NetworkEntity e, final Formula<NetworkEntity> f, final Collection<MinimalNetworkState> states) { f.toNegationNormalForm(); Stack<Collection<Formula<NetworkEntity>>> blocked = new Stack<Collection<Formula<NetworkEntity>>>(); blocked.push(new ArrayList<Formula<NetworkEntity>>()); boolean first = true; while (!blocked.isEmpty()) { Tableau<NetworkEntity> tableau = new Tableau<NetworkEntity>(tableauRules, propositionComparator, false); tableau.setFormula(f); Collection<Formula<NetworkEntity>> bs = blocked.pop(); World start = new World(0, propositionComparator); for (Formula<NetworkEntity> b : bs) { tableau.block(start, b); } boolean satisfiable = tableau.proofSearch(); if (!satisfiable && first) { System.err.println("Formula not satisfiable for entity " + e + ". This indicates a circular interaction dependency which is not allowed. Until you fix this, we assume that the entity does not have any competitors or dependencies."); MinimalNetworkState mns = new MinimalNetworkState(); mns.setEntity(e); mns.addNecessary(e); if (e instanceof Interaction) { for (Protein p : ((Interaction) e).getProteins()) mns.addNecessary(p); } states.add(mns); } if (satisfiable) { MinimalNetworkState s = ts.transform(tableau); s.setEntity(e); states.add(s); for (LabelledFormula<NetworkEntity> d : tableau.getDisjunctions()) { Formula<NetworkEntity> active = tableau.getActiveDisjunct(d).getFormula(); int index = active.getParent().indexOf(active); if (index != 0) { // find other children that are not yet pre-blocked for (Formula<NetworkEntity> child : d.getFormula()) { LabelledFormula<NetworkEntity> lf = tableau.getLabelledFormula(d.getWorld(), child); if (lf != null) { for (Formula<NetworkEntity> el : lf.getEliminationExplanation()) { if (el.indexOf( tableau.getActiveDisjunct(tableau.getLabelledFormula(d.getWorld(), el)) .getFormula()) == 0) { Collection<Formula<NetworkEntity>> bs2 = new ArrayList<Formula<NetworkEntity>>( bs); bs2.add(tableau.getActiveDisjunct(d).getFormula()); blocked.push(bs2); } } } } } } } first = false; } }
From source file:cn.edu.sdust.silence.itransfer.filemanage.FileManager.java
/** * Constructs an object of the class//from ww w . j av a 2s . c om * <br> * this class uses a stack to handle the navigation of directories. */ public FileManager() { mDirContent = new ArrayList<String>(); mPathStack = new Stack<String>(); mPathStack.push("/"); mPathStack.push(mPathStack.peek() + "sdcard"); }
From source file:gridool.replication.ReplicationManager.java
public ReplicationManager(@Nonnull GridKernel kernel, @Nonnull DBAccessor dba, @Nonnull GridRouter router, @Nonnull GridConfiguration config) { this.kernel = kernel; this.dba = dba; this.router = router; this.localMasterNode = config.getLocalNode(); this.replicaSelector = ReplicationModuleBuilder.createReplicaSelector(); this.replicaCoordinator = ReplicationModuleBuilder.createReplicaCoordinator(kernel, config); this.replicaNameStack = new Stack<String>(); this.replicaDbMappingCache = new HashMap<String, String>(32); }
From source file:net.servicefixture.fitnesse.FixtureTemplateCreator.java
/** * Generates the test table template for the ServiceFixture and prints out * to standard console.//w ww . ja v a 2s. c o m * * @param clazz */ private void generateServiceFixtureTemplate(Class clazz) throws Exception { ServiceFixture fixture = (ServiceFixture) clazz.newInstance(); Method operation = fixture.getServiceOperation(); if (operation == null) { writeLine("Unable to generate template for fixture:" + fixture.getClass().getName() + " because service operation is unknown."); return; } Class[] parameterTypes = operation.getParameterTypes(); Class returnType = operation.getReturnType(); for (int i = 0; i < parameterTypes.length; i++) { String prefix = "|set|" + getParameterName(parameterTypes[i]); Stack<Class> ancestors = new Stack<Class>(); ancestors.push(CollectionBuilderFactory.getElementType(parameterTypes[i])); addTableRowsForType(ancestors, prefix, CollectionBuilderFactory.getElementType(parameterTypes[i]), true); } writeLine("|invoke||"); if ("void".equals(returnType.getName())) { writeLine("|check|response == null|true|"); } else { writeLine("|check|response != null|true|"); String prefix = "|check|response"; if (CollectionBuilderFactory.isCollectionType(returnType)) { writeLine("|check|response.size() > 0|true|"); writeLine("|check|response.size()||"); prefix = prefix + "[0]"; } Stack<Class> ancestors = new Stack<Class>(); ancestors.push(CollectionBuilderFactory.getElementType(returnType)); addTableRowsForType(ancestors, prefix, CollectionBuilderFactory.getElementType(returnType), false); } }
From source file:com.intel.ssg.dcst.panthera.parse.sql.transformer.SubQUnnestTransformer.java
void transformFilterBlock(QueryInfo qf, TranslateContext context) throws SqlXlateException { if (!this.hasSubQuery(qf)) { LOG.info("skip subq transform:" + qf.toStringTree()); return;/* w ww. j ava 2 s. c o m*/ } FilterBlock fb = qf.getFilterBlockTreeRoot(); if (!(fb instanceof QueryBlock)) { throw new SqlXlateException(null, "Error FilterBlock tree" + fb.toStringTree()); } // prefetch columns from filterBlocks and store them in QueryBlock in FilterBLockContext. fb.prepare(new FilterBlockContext(qf), context, new Stack<CommonTree>()); // process QueryBlock fb.process(new FilterBlockContext(qf), context); }