List of usage examples for java.util Stack Stack
public Stack()
From source file:logica.Estacion.java
public Estacion(String nombre, Tipo tipo) throws CreacionException { if (tipo == Tipo.BASE) { // Se puede instanciar solo una estacion base /// Chequea la existencia de una Estacion Base if (estacionBaseExiste) throw new CreacionException( "No se pudo instanciar el " + "objeto. No se puede crear mas de una Estacion Base"); // else/*from w w w.ja v a 2s . c o m*/ estacionBaseExiste = true; clase = Tipo.BASE; // Creo la red de estaciones del la estacion. //Maximo 4 estaciones conectadas redEstaciones = new Estacion[4]; } else { // No se puede instanciar una estacion meteorologica sin tener una base /// Chequea la no existencia de una Estacion Base if (!estacionBaseExiste) throw new CreacionException( "No se pudo instanciar el " + "objeto. Se debe crear primero una Estacion Base"); clase = Tipo.MET; // Creo la red de estaciones del la estacion. //Maximo 4 estaciones conectadas redEstaciones = new Estacion[3]; } this.ID = IDsiguiente; IDsiguiente++; if (nombre == null) // Nombre por defecto por si no se le dio uno nombre = "Estacion" + Integer.toString(ID); this.nombre = nombre; LOGGER.log(Level.INFO, String.format("Creanda estacion %s %d ( %s ).", clase.toString(), ID, nombre)); // Creo la red de estaciones del la estacion. int redSize = redEstaciones.length; for (int i = 0; i < redSize; i++) redEstaciones[i] = null; // Creo la pila donde se guardan las mediciones (PaqueteDeDatos) medidasPila = new Stack(); // Creo el treeNode estacionTreeNode = new DefaultMutableTreeNode(this); }
From source file:com.cyclopsgroup.waterview.tool.PopulateToolsValve.java
/** * Override or implement method of parent class or interface * /*from ww w . j a v a 2 s . c o m*/ * @see com.cyclopsgroup.waterview.Valve#invoke(com.cyclopsgroup.waterview.UIRuntime) */ public void invoke(UIRuntime runtime) throws Exception { Stack processedTools = new Stack(); for (Iterator i = toolDefinitions.values().iterator(); i.hasNext();) { ToolDef def = (ToolDef) i.next(); UITool tool = null; try { if (def.lifecycle == ToolLifecycle.REQUEST) { tool = createRequestTool(runtime, def); } else if (def.lifecycle == ToolLifecycle.SESSION) { tool = createSessionTool(runtime, def); } else if (def.lifecycle == ToolLifecycle.APPLICATION) { tool = createApplicationTool(runtime, def); } tool.setName(def.name); processedTools.push(tool); runtime.getPageContext().put(def.name, tool); if (tool instanceof RequestListener) { ((RequestListener) tool).prepareForRequest(runtime); } } catch (Exception e) { getLogger().warn("Tool initialization error", e); } } try { invokeNext(runtime); } catch (Exception e) { throw e; } finally { while (!processedTools.isEmpty()) { UITool tool = (UITool) processedTools.pop(); runtime.getPageContext().remove(tool.getName()); try { if (tool instanceof RequestListener) { ((RequestListener) tool).disposeForRequest(runtime); } } catch (Exception e) { getLogger().warn("Tool disposing error", e); } } } }
From source file:fr.inria.oak.paxquery.common.xml.nodeidentifier.CompactDynamicDeweyScheme.java
public CompactDynamicDeweyScheme(CompactDynamicDeweyID id, CompactDynamicDeweyID lastSibling) { int[] tempPath = new int[id.path.length + 1]; System.arraycopy(id.path, 0, tempPath, 0, id.path.length); tempPath[id.path.length] = lastSibling.n; currentId = tempPath;//from w ww.j a v a 2s . c o m parentId = id.path; int[] tempTag = new int[id.tag.length + 1]; System.arraycopy(id.tag, 0, tempTag, 0, id.tag.length); tempPath[id.tag.length] = -1; currentTag = tempTag; parentTag = id.tag; /*try { parentString = ((CompactDynamicDeweyID)id.getParent()).s; } catch (VIP2PExecutionException e) { Parameters.logger.error("Exception", e); }*/ currentSiblingNo = lastSibling.n; s = new Stack<CompactDynamicDeweyID>(); // Is this needed? s.push(id); lastID = null; // Depth and lastDepth will be wrong but I don't think it's relevant for the update purpose depth = 0; lastDepth = 0; currentChildren = new HashMap<int[], Integer>(); currentChildren.put(parentId, currentSiblingNo); }
From source file:org.lareferencia.xoai.Context.java
/** * Initializes a new context object. /*from ww w . jav a2s . c o m*/ * * @exception SQLException * if there was an error obtaining a database connection */ private void _init() throws SQLException { // Obtain a non-auto-committing connection //connection = DatabaseManager.getConnection(); //connection.setAutoCommit(false); currentUser = null; currentLocale = I18nUtil.DEFAULTLOCALE; extraLogInfo = ""; ignoreAuth = false; objectCache = new HashMap<String, Object>(); specialGroups = new ArrayList<Integer>(); authStateChangeHistory = new Stack<Boolean>(); authStateClassCallHistory = new Stack<String>(); }
From source file:com.clustercontrol.performance.operator.RevercePorlishNotation.java
/** * ?/*from w w w . j a v a 2s.c o m*/ */ @Override public double calc(DataTable currentTable, DataTable previousTable, String deviceName) throws CollectedDataNotFoundException, InvalidValueException { double right = 0D; double left = 0D; double result = 0D; Stack<Double> _stack = new Stack<Double>(); if (this.expArray.length == 1) { result = getVal(expArray[0], currentTable, previousTable, deviceName); } else { for (int i = 0; i < this.expArray.length; i++) { try { if (expArray[i] instanceof OPERATOR) { right = _stack.pop(); left = _stack.pop(); switch ((OPERATOR) expArray[i]) { case ADDITION: result = left + right; break; case SUBTRACTION: result = left - right; break; case MULTIPLICATION: result = left * right; break; case DIVISION: if (right == 0) { log.warn("0-devided, expression=" + expression); // 0-devide???????NaN? return Double.NaN; } result = left / right; break; } _stack.push(new Double(result)); } else { _stack.push(getVal(expArray[i], currentTable, previousTable, deviceName)); } } catch (CollectedDataNotFoundException | IllegalStateException | EmptyStackException e) { log.warn("calc [" + expression + "], " + e.getClass().getName() + ", " + e.getMessage()); throw new InvalidValueException(e.getMessage()); } catch (Exception e) { log.warn("calc [" + expression + "], " + e.getClass().getName() + ", " + e.getMessage(), e); throw new InvalidValueException(e.getMessage()); } } if (_stack.size() > 1) { String messages = "expression is invalid, expression-" + expression; log.warn("calc : " + messages); throw new InvalidValueException(messages); } } return result; }
From source file:com.datatorrent.stram.plan.logical.DelayOperatorTest.java
@Test public void testInvalidDelayDetection() { LogicalPlan dag = new LogicalPlan(); GenericTestOperator opB = dag.addOperator("B", GenericTestOperator.class); GenericTestOperator opC = dag.addOperator("C", GenericTestOperator.class); GenericTestOperator opD = dag.addOperator("D", GenericTestOperator.class); DefaultDelayOperator opDelay = dag.addOperator("opDelay", DefaultDelayOperator.class); dag.addStream("BtoC", opB.outport1, opC.inport1); dag.addStream("CtoD", opC.outport1, opD.inport1); dag.addStream("CtoDelay", opC.outport2, opDelay.input); dag.addStream("DelayToD", opDelay.output, opD.inport2); List<List<String>> invalidDelays = new ArrayList<>(); dag.findInvalidDelays(dag.getMeta(opB), invalidDelays, new Stack<OperatorMeta>()); assertEquals("operator invalid delay", 1, invalidDelays.size()); try {/*from w w w.j a v a 2 s . c om*/ dag.validate(); fail("validation should fail"); } catch (ValidationException e) { // expected } dag = new LogicalPlan(); opB = dag.addOperator("B", GenericTestOperator.class); opC = dag.addOperator("C", GenericTestOperator.class); opD = dag.addOperator("D", GenericTestOperator.class); opDelay = dag.addOperator("opDelay", DefaultDelayOperator.class); dag.setOperatorAttribute(opDelay, Context.OperatorContext.APPLICATION_WINDOW_COUNT, 2); dag.addStream("BtoC", opB.outport1, opC.inport1); dag.addStream("CtoD", opC.outport1, opD.inport1); dag.addStream("CtoDelay", opC.outport2, opDelay.input); dag.addStream("DelayToC", opDelay.output, opC.inport2); invalidDelays = new ArrayList<>(); dag.findInvalidDelays(dag.getMeta(opB), invalidDelays, new Stack<OperatorMeta>()); assertEquals("operator invalid delay", 1, invalidDelays.size()); try { dag.validate(); fail("validation should fail"); } catch (ValidationException e) { // expected } dag = new LogicalPlan(); opB = dag.addOperator("B", GenericTestOperator.class); opC = dag.addOperator("C", GenericTestOperator.class); opD = dag.addOperator("D", GenericTestOperator.class); opDelay = dag.addOperator("opDelay", DefaultDelayOperator.class); dag.addStream("BtoC", opB.outport1, opC.inport1); dag.addStream("CtoD", opC.outport1, opD.inport1); dag.addStream("CtoDelay", opC.outport2, opDelay.input).setLocality(DAG.Locality.THREAD_LOCAL); dag.addStream("DelayToC", opDelay.output, opC.inport2).setLocality(DAG.Locality.THREAD_LOCAL); try { dag.validate(); fail("validation should fail"); } catch (ValidationException e) { // expected } }
From source file:com.siberhus.web.ckeditor.utils.PathUtils.java
public static String normalizePath(String path) { String tokens[] = StringUtils.split(path, File.separator); List<String> tokenList = Arrays.asList(tokens); Stack<String> tokenStack = new Stack<String>(); for (String token : tokenList) { if (".".equals(token)) { // skip } else if ("..".equals(token)) { tokenStack.pop();//from w w w. ja v a 2 s . c om } else { tokenStack.push(token); } } String result = ""; if (path.startsWith(File.separator)) { result += File.separator; } result += StringUtils.join(tokenStack, File.separator); if (path.endsWith(File.separator)) { result += File.separator; } return result.toString(); }
From source file:com.google.testing.pogen.parser.template.RegexVariableExtractor.java
/** * Constructs an instance to extract template variables with the specified positions of excluded * parts and the given attribute name for memorizing the value. * /*from ww w . j a v a2 s .c o m*/ * @param repeatedParts the {@link RangeSet} of the positions of repeated parts * @param excludedRanges the {@link RangeSet} of the positions of excluded parts * @param attributeName the name of the attribute to be assigned for tags containing template * variables * @param variablePattern a regular expression for extracting template variables * @throws TemplateParseException if the specified template is in bad format */ public RegexVariableExtractor(RangeSet<Integer> repeatedRanges, RangeSet<Integer> excludedRanges, String attributeName, Pattern variablePattern) throws TemplateParseException { this.repeatedRanges = repeatedRanges; this.excludedRanges = excludedRanges; this.attributeName = attributeName; this.tagInfoStack = new Stack<HtmlTagInfo>(); this.sortedHtmlTagInfos = new ArrayList<HtmlTagInfo>(); this.variablePattern = variablePattern; // CyberNeko HTML Parser supports AUGMENTATIONS try { setFeature(AUGMENTATIONS, true); } catch (SAXNotRecognizedException e) { throw new TemplateParseException(e); } catch (SAXNotSupportedException e) { throw new TemplateParseException(e); } }
From source file:com.autentia.tnt.bean.MenuBean.java
/** * Get menu tree// w w w .j a v a 2s .c om * @return menu tree */ public TreeNode getMenu() { // Create menu only the first time if (menu == null) { Principal creds = SpringUtils.getPrincipal(); Stack<TreeNode> path = new Stack<TreeNode>(); menu = new TreeNodeBase("menu", "Menu", false); path.push(menu); if (openNode(path, creds, null, "admin")) { addLeaf(path, creds, Permission.Entity_Menu(User.class), "users"); addLeaf(path, creds, Permission.Entity_Menu(UserCategory.class), "userCategorys"); addLeaf(path, creds, null, "changePassword"); addLeaf(path, creds, Permission.Entity_Menu(Department.class), "departments"); // addLeaf( path, creds, Permission.Entity_Menu(Setting.class), "settings" ); closeNode(path); } if (openNode(path, creds, null, "masterTables")) { addLeaf(path, creds, Permission.Entity_Menu(AccountEntryType.class), "accountEntryTypes"); addLeaf(path, creds, Permission.Entity_Menu(OrganizationType.class), "organizationTypes"); addLeaf(path, creds, Permission.Entity_Menu(InteractionType.class), "interactionTypes"); addLeaf(path, creds, Permission.Entity_Menu(OrganizationISOCategory.class), "organizationISOCategorys"); addLeaf(path, creds, Permission.Entity_Menu(ContractType.class), "contractTypes"); addLeaf(path, creds, Permission.Entity_Menu(Magazine.class), "magazines"); addLeaf(path, creds, Permission.Entity_Menu(OfferRejectReason.class), "offerRejectReasons"); closeNode(path); } if (openNode(path, creds, null, "billing")) { addLeaf(path, creds, Permission.Entity_Menu(Bill.class), "bills"); addLeaf(path, creds, Permission.Entity_Menu(Account.class), "accounts"); addLeaf(path, creds, Permission.Entity_Menu(AccountEntry.class), "accountEntrys"); addLeaf(path, creds, Permission.Entity_Menu(PeriodicalAccountEntry.class), "periodicalAccountEntrys"); addLeaf(path, creds, Permission.Action_NOF, "nof"); addLeaf(path, creds, Permission.Entity_Menu(FinancialRatio.class), "financialRatios"); closeNode(path); } if (openNode(path, creds, null, "contacts")) { addLeaf(path, creds, Permission.Entity_Menu(Organization.class), "organizations"); addLeaf(path, creds, Permission.Entity_Menu(Interaction.class), "interactions"); addLeaf(path, creds, Permission.Entity_Menu(Contact.class), "contacts"); addLeaf(path, creds, Permission.Entity_Menu(Offer.class), "offers"); addLeaf(path, creds, Permission.Entity_Menu(Project.class), "projects"); closeNode(path); } if (openNode(path, creds, null, "quality")) { addLeaf(path, creds, Permission.Action_ListQualityDocuments, "qualityDocuments"); closeNode(path); } if (openNode(path, creds, null, "bulletin")) { addLeaf(path, creds, Permission.Entity_Menu(BulletinBoard.class), "bulletinBoards"); addLeaf(path, creds, Permission.Entity_Menu(CompanyState.class), "companyStates"); addLeaf(path, creds, Permission.Entity_Menu(BulletinBoardCategory.class), "bulletinBoardCategorys"); addLeaf(path, creds, Permission.Entity_Menu(Idea.class), "ideas"); closeNode(path); } if (openNode(path, creds, null, "activity")) { addLeaf(path, creds, Permission.Entity_Menu(Activity.class), "activitys"); addLeaf(path, creds, Permission.Entity_Menu(Objective.class), "objectives"); closeNode(path); } if (openNode(path, creds, null, "reports")) { addLeaf(path, creds, Permission.Action_GeneralReports, "generalReports"); addLeaf(path, creds, Permission.Action_BitacoreReports, "bitacoreReports"); addLeaf(path, creds, Permission.Action_BillReports, "billReports"); addLeaf(path, creds, Permission.Action_ProjectReports, "projectReports"); addLeaf(path, creds, Permission.Action_InteractionReports, "interactionReports"); addLeaf(path, creds, Permission.Action_OrganizationReports, "organizationReports"); addLeaf(path, creds, Permission.Action_OfferReports, "offerReports"); addLeaf(path, creds, Permission.Action_OwnReports, "ownReports"); addLeaf(path, creds, Permission.Action_PersonalReports, "personalReports"); closeNode(path); } if (openNode(path, creds, null, "publish")) { addLeaf(path, creds, Permission.Entity_Menu(Tutorial.class), "tutorials"); addLeaf(path, creds, Permission.Entity_Menu(Publication.class), "publications"); closeNode(path); } if (openNode(path, creds, null, "holiday")) { addLeaf(path, creds, Permission.Entity_Menu(Holiday.class), "holidays"); addLeaf(path, creds, Permission.Entity_Menu(RequestHoliday.class), "requestHolidays"); addLeaf(path, creds, Permission.Entity_Menu(AdminHoliday.class), "adminHolidays"); closeNode(path); } if (openNode(path, creds, null, "utils")) { addLeaf(path, creds, Permission.Entity_Menu(Book.class), "books"); addLeaf(path, creds, Permission.Entity_Menu(Inventary.class), "inventarys"); closeNode(path); } } return menu; }
From source file:de.codesourcery.jasm16.ast.ASTUtils.java
public static Iterator<ASTNode> createInOrderIterator(ASTNode node) { if (node == null) { throw new IllegalArgumentException("node must not be NULL"); }//from w w w . ja v a 2 s .com final Stack<ASTNode> stack = new Stack<ASTNode>(); stack.push(node); return new Iterator<ASTNode>() { @Override public boolean hasNext() { return !stack.isEmpty(); } /* A (1) * |\ *(5) E B (2) * |\ *(4) D C (3) */ @Override public ASTNode next() { if (stack.isEmpty()) { throw new NoSuchElementException(); } ASTNode result = stack.pop(); final List<ASTNode> children = result.getChildren(); Collections.reverse(children); for (ASTNode child : children) { stack.push(child); } return result; } @Override public void remove() { throw new UnsupportedOperationException(); } }; }