Example usage for java.util Stack push

List of usage examples for java.util Stack push

Introduction

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

Prototype

public E push(E item) 

Source Link

Document

Pushes an item onto the top of this stack.

Usage

From source file:org.apache.hadoop.dfs.PermissionChecker.java

private void checkSubAccess(INode inode, FsAction access) throws AccessControlException {
    if (inode == null || !inode.isDirectory()) {
        return;//  ww w .  j a v a2 s.c om
    }

    Stack<INodeDirectory> directories = new Stack<INodeDirectory>();
    for (directories.push((INodeDirectory) inode); !directories.isEmpty();) {
        INodeDirectory d = directories.pop();
        check(d, access);

        for (INode child : d.getChildren()) {
            if (child.isDirectory()) {
                directories.push((INodeDirectory) child);
            }
        }
    }
}

From source file:com.ctriposs.rest4j.tools.idlcheck.Rest4JResourceModelCompatibilityChecker.java

/**
 * Check backwards compatibility between two idl (.restspec.json) files.
 *
 * @param prevRestspecPath previously existing idl file
 * @param currRestspecPath current idl file
 * @param compatLevel compatibility level which affects the return value
 * @return true if the check result conforms the compatibility level requirement
 *         e.g. false if backwards compatible changes are found but the level is equivalent
 *//*from w  ww .  j  ava 2 s . c o m*/
public boolean check(String prevRestspecPath, String currRestspecPath, CompatibilityLevel compatLevel) {
    _prevRestspecPath = prevRestspecPath;
    _currRestspecPath = currRestspecPath;

    Stack<Object> path = new Stack<Object>();
    path.push("");

    ResourceSchema prevRec = null;
    ResourceSchema currRec = null;

    try {
        prevRec = _codec.readResourceSchema(new FileInputStream(prevRestspecPath));
    } catch (FileNotFoundException e) {
        _infoMap.addRestSpecInfo(CompatibilityInfo.Type.RESOURCE_NEW, path, currRestspecPath);
    } catch (IOException e) {
        _infoMap.addRestSpecInfo(CompatibilityInfo.Type.OTHER_ERROR, path, e.getMessage());
    }

    try {
        currRec = _codec.readResourceSchema(new FileInputStream(currRestspecPath));
    } catch (FileNotFoundException e) {
        _infoMap.addRestSpecInfo(CompatibilityInfo.Type.RESOURCE_MISSING, path, prevRestspecPath);
    } catch (Exception e) {
        _infoMap.addRestSpecInfo(CompatibilityInfo.Type.OTHER_ERROR, path, e.getMessage());
    }

    if (prevRec == null || currRec == null) {
        return _infoMap.isCompatible(compatLevel);
    }

    final DataSchemaResolver resolver;
    if (_resolverPath == null) {
        resolver = new DefaultDataSchemaResolver();
    } else {
        resolver = new XmlFileDataSchemaResolver(SchemaParserFactory.instance(), _resolverPath);
    }

    ResourceCompatibilityChecker checker = new ResourceCompatibilityChecker(prevRec, resolver, currRec,
            resolver);
    boolean check = checker.check(compatLevel);
    _infoMap.addAll(checker.getInfoMap());
    return check;
}

From source file:RoomInfo.java

void route(String to) {
    Stack rev = new Stack();
    RoomInfo r;/*  w  w w.  ja va2 s . c  o m*/
    int num = btStack.size();

    // Reverse the stack to display path.
    for (int i = 0; i < num; i++)
        rev.push(btStack.pop());

    for (int i = 0; i < num; i++) {
        r = (RoomInfo) rev.pop();
        System.out.print(r.from + " to ");
    }

    System.out.println(to);
}

From source file:com.linkedin.restli.tools.idlcheck.RestLiResourceModelCompatibilityChecker.java

/**
 * Check backwards compatibility between two idl (.restspec.json) files.
 *
 * @param prevRestspecPath previously existing idl file
 * @param currRestspecPath current idl file
 * @param compatLevel compatibility level which affects the return value
 * @return true if the check result conforms the compatibility level requirement
 *         e.g. false if backwards compatible changes are found but the level is equivalent
 *//*  w ww .  j av  a  2 s.  c o  m*/
public boolean check(String prevRestspecPath, String currRestspecPath, CompatibilityLevel compatLevel) {
    _prevRestspecPath = prevRestspecPath;
    _currRestspecPath = currRestspecPath;

    Stack<Object> path = new Stack<Object>();
    path.push("");

    ResourceSchema prevRec = null;
    ResourceSchema currRec = null;

    try {
        prevRec = _codec.readResourceSchema(new FileInputStream(prevRestspecPath));
    } catch (FileNotFoundException e) {
        _infoMap.addRestSpecInfo(CompatibilityInfo.Type.RESOURCE_NEW, path, currRestspecPath);
    } catch (IOException e) {
        _infoMap.addRestSpecInfo(CompatibilityInfo.Type.OTHER_ERROR, path, e.getMessage());
    }

    try {
        currRec = _codec.readResourceSchema(new FileInputStream(currRestspecPath));
    } catch (FileNotFoundException e) {
        _infoMap.addRestSpecInfo(CompatibilityInfo.Type.RESOURCE_MISSING, path, prevRestspecPath);
    } catch (Exception e) {
        _infoMap.addRestSpecInfo(CompatibilityInfo.Type.OTHER_ERROR, path, e.getMessage());
    }

    if (prevRec == null || currRec == null) {
        return _infoMap.isCompatible(compatLevel);
    }

    final DataSchemaResolver resolver;
    if (_resolverPath == null) {
        resolver = new DefaultDataSchemaResolver();
    } else {
        resolver = new FileDataSchemaResolver(SchemaParserFactory.instance(), _resolverPath);
    }

    ResourceCompatibilityChecker checker = new ResourceCompatibilityChecker(prevRec, resolver, currRec,
            resolver);
    boolean check = checker.check(compatLevel);
    _infoMap.addAll(checker.getInfoMap());
    return check;
}

From source file:BracketChecker.java

public void check() {
    Stack<Character> theStack = new Stack<Character>();

    for (int j = 0; j < input.length(); j++) {
        char ch = input.charAt(j);
        switch (ch) {
        case '{':
        case '[':
        case '(':
            theStack.push(ch);
            break;
        case '}':
        case ']':
        case ')':
            if (!theStack.isEmpty()) {
                char chx = theStack.pop();
                if ((ch == '}' && chx != '{') || (ch == ']' && chx != '[') || (ch == ')' && chx != '('))
                    System.out.println("Error: " + ch + " at " + j);
            } else

                System.out.println("Error: " + ch + " at " + j);
            break;
        default://from  w  w  w .  ja  va2s  . c  o m
            break;
        }
    }
    if (!theStack.isEmpty()) {
        System.out.println("Error: missing right delimiter");
    }
}

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;//from  w  w  w.j a  va 2 s .c  om
    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:FlightInfo.java

void route(String to) {
    int dist = 0;
    FlightInfo f;/*from www .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.autentia.bcbp.elements.ConditionalItemsUnique.java

public ConditionalItemsUnique(String passengerDescription, String sourceCheckin,
        String sourceBoardingPassIssuance, String dateOfIssueOfBoardingPass, String documentType,
        String airlineDesignatorOfBoardingPassIssuer, String baggageTagLicencePlateNumber,
        String firstNCBaggageTagLicencePlateNumber, String secondNCBaggageTagLicencePlateNumber) {
    super();//from  w w  w .  j av a2 s . c om

    Stack<Item> items = new Stack<Item>();

    items.push(new Item(passengerDescription, passengerDescriptionLength, 142, PaddingType.String));
    items.push(new Item(sourceCheckin, sourceCheckinLength, 143, PaddingType.String));
    items.push(new Item(sourceBoardingPassIssuance, sourceBoardingPassIssuanceLength, 18, PaddingType.String));
    items.push(new Item(dateOfIssueOfBoardingPass, dateOfIssueOfBoardingPassLength, 108, PaddingType.Number));
    items.push(new Item(documentType, documentTypeLength, 19, PaddingType.String));
    items.push(new Item(airlineDesignatorOfBoardingPassIssuer, airlineDesignatorOfBoardingPassIssuerLength, 20,
            PaddingType.String));
    items.push(new Item(baggageTagLicencePlateNumber, baggageTagLicencePlateNumberLength, 236,
            PaddingType.String));
    items.push(new Item(firstNCBaggageTagLicencePlateNumber, firstNCBaggageTagLicencePlateNumberLength, 89,
            PaddingType.String));
    items.push(new Item(secondNCBaggageTagLicencePlateNumber, secondNCBaggageTagLicencePlateNumberLength, 118,
            PaddingType.String));

    final StringBuilder codeBuilder = new StringBuilder();
    boolean starting = true;
    while (!items.isEmpty()) {
        Item item = items.pop();
        if (starting && StringUtils.isNotBlank(item.getEncoded()) || !removeEndingEmptyElements)
            starting = false;
        if (!starting)
            codeBuilder.insert(0, item.getEncoded());
    }

    final String baseCode = codeBuilder.toString();

    if (StringUtils.isBlank(baseCode))
        code = "";
    else
        code = ">"
                + BCBPversion + StringUtils
                        .leftPad(Integer.toHexString(baseCode.length()), variableSizeLength, "0").toUpperCase()
                + baseCode;
}

From source file:com.glaf.batch.job.BatchJob.java

public void execute(JobExecution execution) {
    IJobService jobService = ContextFactory.getBean("jobService");
    if (execution.getSteps() != null && !execution.getSteps().isEmpty()) {
        List<StepExecution> steps = execution.getSteps();
        Collections.sort(steps);/*from  w  w  w.  ja  v a 2  s.  c  om*/
        /**
         * ??
         */
        Stack<StepExecution> stack = new Stack<StepExecution>();
        for (int i = steps.size() - 1; i >= 0; i--) {
            stack.push(steps.get(i));
        }

        while (!stack.empty()) {
            StepExecution step = stack.peek();
            if (!jobService.stepExecutionCompleted(step.getJobStepKey())) {
                boolean success = false;
                int retry = 0;
                while (retry < 3 && !success) {
                    retry++;
                    try {
                        jobService.startStepExecution(step.getJobStepKey());
                        if (StringUtils.isNotEmpty(step.getJobClass())) {
                            Object object = ClassUtils.instantiateObject(step.getJobClass());
                            if (object instanceof IStep) {
                                IStep ix = (IStep) object;
                                ix.execute(step);
                                if (jobService.stepExecutionCompleted(step.getJobStepKey())) {
                                    /**
                                     * ????
                                     */
                                    stack.pop();
                                    success = true;
                                    retry = Integer.MAX_VALUE;
                                    break;
                                }
                            }
                        }
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
                if (!success) {
                    throw new RuntimeException(
                            step.getStepKey() + " " + step.getStepName() + " execute failed.");
                }
            }
        }
    }
}

From source file:com.autentia.bcbp.elements.ConditionalItemsRepeated.java

private ConditionalItemsRepeated(String airlineNumericCode, String serialNumber, String selecteeIndicator,
        String internationalDocumentVerification, String marketingCarrierDesignator,
        String frecuentFlyerAirlineDesignator, String frecuentFlyerNumber, String iDADIndicator,
        String freeBaggageAllowance, String fastTrack) {

    Stack<Item> items = new Stack<Item>();

    items.push(new Item(airlineNumericCode, airlineNumericCodeLength, 142, PaddingType.Number));
    items.push(new Item(serialNumber, serialNumberLength, 143, PaddingType.Number));
    items.push(new Item(selecteeIndicator, selecteeIndicatorLength, 18, PaddingType.String));
    items.push(new Item(internationalDocumentVerification, internationalDocumentVerificationLength, 108,
            PaddingType.String));
    items.push(new Item(marketingCarrierDesignator, marketingCarrierDesignatorLength, 19, PaddingType.String));
    items.push(new Item(frecuentFlyerAirlineDesignator, frecuentFlyerAirlineDesignatorLength, 20,
            PaddingType.String));
    items.push(new Item(frecuentFlyerNumber, frecuentFlyerNumberLength, 236, PaddingType.String));
    items.push(new Item(iDADIndicator, IDADIndicatorLength, 89, PaddingType.String));
    items.push(new Item(freeBaggageAllowance, freeBaggageAllowanceLength, 118, PaddingType.String));
    items.push(new Item(fastTrack, fastTrackLength, 254, PaddingType.String));

    final StringBuilder codeBuilder = new StringBuilder();
    boolean starting = true;
    while (!items.isEmpty()) {
        Item item = items.pop();/*from  www. jav  a 2  s . c  o  m*/
        if (starting && StringUtils.isNotBlank(item.getEncoded()) || !removeEndingEmptyElements)
            starting = false;
        if (!starting)
            codeBuilder.insert(0, item.getEncoded());
    }

    final String baseCode = codeBuilder.toString();
    if (StringUtils.isBlank(baseCode)) {
        code = "";
    } else {
        code = StringUtils.leftPad(Integer.toHexString(baseCode.length()), variableSizeLength, "0")
                .toUpperCase() + baseCode;
    }
}