Example usage for java.util Stack Stack

List of usage examples for java.util Stack Stack

Introduction

In this page you can find the example usage for java.util Stack Stack.

Prototype

public Stack() 

Source Link

Document

Creates an empty Stack.

Usage

From source file:com.usefullc.platform.common.filter.WebCommonFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest req = (HttpServletRequest) request;
    HttpServletResponse res = (HttpServletResponse) response;
    // String url = req.getRequestURL().toString();
    String url = req.getRequestURI();
    if (canExcute) {

        Stack<ActionHandlerInterceptor> actionStack = new Stack<ActionHandlerInterceptor>();
        ActionHandler actionHandler = new ActionHandler(req, res);
        for (ActionHandlerInterceptor interceptor : interceptorList) {
            String urlPattern = interceptor.getUrlPattern();
            // ?url
            Boolean state = PatternMatchUtils.simpleMatch(urlPattern, url);
            if (!state) {
                continue;
            }/* w  w  w.  jav  a2 s  .c  om*/
            interceptor.beforeHandler(actionHandler);

            // 
            actionStack.push(interceptor);

        }
        boolean actionState = false;
        try {
            chain.doFilter(request, response);
            actionState = true;
        } catch (Exception e) {
            StringWriter sw = new StringWriter();
            PrintWriter print = new PrintWriter(sw);
            e.printStackTrace(print);
            actionHandler.setErrMsg(sw.toString());
        } finally {
            // 
            actionHandler.setState(actionState);
            while (!actionStack.isEmpty()) {
                ActionHandlerInterceptor interceptor = actionStack.pop();
                interceptor.afterHandler(actionHandler);
            }

        }

    } else {
        chain.doFilter(request, response);
    }

}

From source file:com.aperigeek.dropvault.web.rest.SearchService.java

@GET
@Produces("application/json")
public Response query(@HeaderParam("Authorization") String authorization, @QueryParam("q") String query)
        throws IndexException {

    User user;/* w  w w  .java  2s.  c o m*/
    try {
        user = authenticationService.checkAuthentication(authorization);
    } catch (InvalidPasswordException ex) {
        return Response.status(401).header("WWW-Authenticate", "Basic realm=\"Search authentication\"").build();
    } catch (NotAuthorizedException ex) {
        return Response.status(403).build();
    } catch (ProtocolException ex) {
        return Response.status(400).build();
    }

    URI userUri = URI.create(DAV_BASE);

    List<String> uris = new ArrayList<String>();
    List<String> ids = indexService.search(user.getUsername(), user.getPassword(), query);
    for (String id : ids) {
        Resource res = fileService.getResource(id);
        Stack<Resource> path = new Stack<Resource>();
        Resource parent = res;
        while (parent != null) {
            path.push(parent);
            parent = fileService.getParent(parent);
        }

        // Remove the user's root folder, we don't want it in the path
        path.pop();

        UriBuilder builder = UriBuilder.fromUri(userUri);
        while (!path.empty()) {
            Resource e = path.pop();
            builder.path(e.getName());
        }
        uris.add(builder.build().toString());
    }

    JSONArray array = new JSONArray(uris);
    return Response.ok(array.toString()).build();
}

From source file:de.se_rwth.langeditor.util.Misc.java

public static <T> void traverse(T root, Function<T, Collection<? extends T>> childGenerator,
        Consumer<? super T> enter, Consumer<? super T> exit) {

    Set<T> previouslyVisited = new HashSet<>();
    Stack<T> yetToVisit = new Stack<>();
    yetToVisit.push(root);//from  ww w. jav  a  2 s.  co m

    T nextElement;
    while (!yetToVisit.isEmpty()) {
        nextElement = yetToVisit.peek();
        if (!previouslyVisited.contains(nextElement)) {
            enter.accept(nextElement);
            previouslyVisited.add(nextElement);
            yetToVisit.addAll(childGenerator.apply(nextElement));
        } else {
            exit.accept(yetToVisit.pop());
        }
    }
}

From source file:com.autentia.intra.bean.MenuBean.java

/**
 * Get menu tree//from   w  w w .ja va  2 s .c o  m
 *
 * @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_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:aula1.Aula1.java

public static String calculaPolonesaINversa(String entrada, String info) {
    Stack<String> pilha = new Stack<>();
    Stack<Op> operadores = new Stack<>();
    String[] operadoresSuportados = { "+", "-", "*", "/", "^", "(", ")", "sen" };

    for (int i = 0; i < entrada.length(); i++) {
        String s = "";
        if (entrada.charAt(i) == 's') {

            if (entrada.contains("sen")) {
                int ind = entrada.indexOf("sen");
                ind += 2;/*from   w  ww  .  jav  a2s  .com*/
                i = 0;
                entrada = entrada.substring(ind + 1);
                s = "sen";
            }
        } else
            s = String.valueOf(entrada.charAt(i));
        if (Character.isDigit(entrada.charAt(i)) || entrada.charAt(i) == 'x') {
            if (Character.isDigit(entrada.charAt(i))) {
                s = String.valueOf(entrada.charAt(i));
                while (Character.isDigit(entrada.charAt(i + 1))) {
                    s += String.valueOf(entrada.charAt(i + 1));
                    i++;
                }
            }
            pilha.push(s);
        } else if (Arrays.asList(operadoresSuportados).contains(s)) {
            String n1 = "";
            String n2 = "";
            if (s.equals("sen"))
                n1 = pilha.pop();
            else {
                n1 = pilha.pop();
                n2 = pilha.pop();
            }
            String resultado;

            if (n1.equals("x"))
                n1 = info;
            else if (n2.equals("x"))
                n2 = info;
            try {
                switch (s) {
                case "+":
                    resultado = Operadores.soma(n2, n1);
                    pilha.push(resultado);
                    break;
                case "-":
                    resultado = Operadores.sub(n2, n1);
                    pilha.push(resultado);
                    break;
                case "*":
                    resultado = Operadores.M(n2, n1);
                    pilha.push(resultado);
                    break;
                case "/":
                    resultado = Operadores.D(n2, n1);
                    pilha.push(resultado);
                    break;
                case "^":
                    resultado = Operadores.pow(n2, n1);
                    pilha.push(resultado);
                    break;
                case "sen":
                    resultado = Operadores.sen(n1);
                    pilha.push(resultado);
                    break;
                }
            } catch (Exception e) {
                System.out.println("Erro: " + e.getMessage());
            }
        }
    }
    return pilha.peek();
}

From source file:com.sm.query.PredicateEstimator.java

private void init() {
    if (!valueStack.isEmpty())
        valueStack.empty();//from   www .  ja va 2  s  .  co m
    if (!idStack.isEmpty())
        idStack = new Stack<String>();
    if (!estimateStack.isEmpty()) {
        estimateStack.empty();
    }
    if (!sourceStack.isEmpty()) {
        sourceStack.empty();
    }
}

From source file:net.owl_black.vmgparser.VmgParser.java

public VmgParser(File f, String encoding) throws UnsupportedEncodingException, FileNotFoundException {
    if (f == null)
        throw new NullPointerException("Given file is null");

    if (!f.exists())
        throw new FileNotFoundException("Provided VMG file does not exist.");

    lexer = new VmgLexer(f, encoding);
    env_stack = new Stack<String>();
    opt_stack = new Stack<String>();

    //Initialize the list of Date parser.

}

From source file:com.frostwire.android.gui.util.FileUtils.java

/** Given a folder path it'll return all the files contained within it and it's subfolders
 * as a flat set of Files./*from  w w  w  .ja  v a2s  .  c  om*/
 * 
 * Non-recursive implementation, up to 20% faster in tests than recursive implementation. :)
 * 
 * @author gubatron
 * @param folder
 * @param extensions If you only need certain files filtered by their extensions, use this string array (without the "."). or set to null if you want all files. e.g. ["txt","jpg"] if you only want text files and jpegs.
 * 
 * @return The set of files.
 */
public static Collection<File> getAllFolderFiles(File folder, String[] extensions) {
    Set<File> results = new HashSet<File>();
    Stack<File> subFolders = new Stack<File>();
    File currentFolder = folder;
    while (currentFolder != null && currentFolder.isDirectory() && currentFolder.canRead()) {
        File[] fs = null;
        try {
            fs = currentFolder.listFiles();
        } catch (SecurityException e) {
        }

        if (fs != null && fs.length > 0) {
            for (File f : fs) {
                if (!f.isDirectory()) {
                    if (extensions == null || FilenameUtils.isExtension(f.getName(), extensions)) {
                        results.add(f);
                    }
                } else {
                    subFolders.push(f);
                }
            }
        }

        if (!subFolders.isEmpty()) {
            currentFolder = subFolders.pop();
        } else {
            currentFolder = null;
        }
    }
    return results;
}

From source file:fr.inria.oak.paxquery.common.xml.nodeidentifier.CompactDynamicDeweyScheme.java

public CompactDynamicDeweyScheme(CompactDynamicDeweyID id) {
    int[] tempPath = new int[id.path.length + 1];
    System.arraycopy(id.path, 0, tempPath, 0, id.path.length);
    tempPath[id.path.length] = 0;//  w ww  .  j  av  a2s  .c o  m
    currentId = tempPath;
    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 = 0;
    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:com.baidu.rigel.biplatform.parser.CompileSection.java

protected void compileSection(String key, String section) throws InvokeFunctionException {

    int i = 0;//from w  w  w .  j ava  2s .c om
    char c = ' ';

    StringBuilder currentToken = new StringBuilder();
    boolean isFunction = false;

    FunctionNode function = null;

    Stack<Node> resolveSectionNodes = new Stack<Node>();
    while (i < section.length()) {
        c = section.charAt(i);
        switch (c) {
        case ' ':
            // skip blank character
            break;

        case '(':
            // ?token??section
            if (currentToken.length() > 0) {
                isFunction = true;
                String funName = currentToken.toString();
                try {
                    function = NodeFactory.makeFunctionNodeByFunctionName(funName);
                } catch (InstantiationException | IllegalAccessException | IllegalArgumentException
                        | InvocationTargetException e) {
                    throw new InvokeFunctionException(funName, e.getMessage());
                }
            }
            currentToken.setLength(0);
            break;
        case ',':
            // ???????
            sectionProcess(resolveSectionNodes, resolveToken(currentToken.toString()), null);
            function.getArgs().add(arrangeNodes(resolveSectionNodes));
            currentToken.setLength(0);
            break;
        case ')':
            sectionProcess(resolveSectionNodes, resolveToken(currentToken.toString()), null);
            // ???
            if (isFunction) {
                if (!resolveSectionNodes.isEmpty()) {
                    function.getArgs().add(arrangeNodes(resolveSectionNodes));
                }
                resolveNodes.put(key, function);
            } else {
                resolveNodes.put(key, arrangeNodes(resolveSectionNodes));
            }
            currentToken.setLength(0);
            break;
        case '*': //42
            sectionProcess(resolveSectionNodes, resolveToken(currentToken.toString()),
                    new MultiplyCalculateNode());
            currentToken.setLength(0);
            break;
        case '/': //47
            sectionProcess(resolveSectionNodes, resolveToken(currentToken.toString()),
                    new DivideCalculateNode());
            currentToken.setLength(0);
            break;
        case '+': //43
            sectionProcess(resolveSectionNodes, resolveToken(currentToken.toString()), new AddCalculateNode());
            currentToken.setLength(0);
            break;
        case '-': //45
            sectionProcess(resolveSectionNodes, resolveToken(currentToken.toString()),
                    new SubtractCalculateNode());
            currentToken.setLength(0);
            break;
        default:
            currentToken.append(c);
            break;
        }

        i++;
    }
    // ???
    if (currentToken.length() > 0) {
        sectionProcess(resolveSectionNodes, resolveToken(currentToken.toString()), null);
        resolveNodes.put(key, arrangeNodes(resolveSectionNodes));
    }
}