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.openremote.server.route.SubflowRoute.java

public static void pushOntoCorrelationStack(Map<String, Object> headers, String identifier) {
    // Create or get existing stack from headers
    @SuppressWarnings("unchecked")
    Stack<String> subflowCorrelationStack = hasCorrelationStack(headers)
            ? (Stack<String>) headers.get(SUBFLOW_CORRELATION_STACK)
            : new Stack<>();

    LOG.debug("Pushing identifier'" + identifier + "' onto correlation stack: " + subflowCorrelationStack);
    subflowCorrelationStack.push(identifier);
    LOG.debug("Setting correlation stack header: " + subflowCorrelationStack);
    headers.put(SUBFLOW_CORRELATION_STACK, subflowCorrelationStack);
}

From source file:com.jetbrains.pluginUtils.xml.JDOMXIncluder.java

@NotNull
private static List<Content> parseRemote(final Stack<String> bases, final URL remote,
        @Nullable Element fallbackElement) {
    try {/*from ww w  . ja  v  a 2  s  . c  o m*/
        Document doc = JDOMUtil.loadResourceDocument(remote);
        bases.push(remote.toExternalForm());

        Element root = doc.getRootElement();

        final List<Content> list = resolve(root, bases);

        bases.pop();
        return list;
    } catch (JDOMException e) {
        throw new XIncludeException(e);
    } catch (IOException e) {
        if (fallbackElement != null) {
            // TODO[yole] return contents of fallback element (we don't have fallback elements with content ATM)
            return Collections.emptyList();
        }
        throw new XIncludeException(e);
    }
}

From source file:Main.java

public static boolean parseXMLMessage(String msg, HashMap<String, String> strMap) {
    boolean bRet = true;

    // parse xml document.
    XmlPullParserFactory factory;/*from w  w w . j a  v  a2s.  c  o  m*/
    XmlPullParser parser;

    try {
        factory = XmlPullParserFactory.newInstance();
        parser = factory.newPullParser();
        Stack eleStack = new Stack();
        int parserEvent;

        parser.setInput(new StringReader(msg));
        parserEvent = parser.getEventType();

        while (parserEvent != XmlPullParser.END_DOCUMENT) {
            switch (parserEvent) {
            case XmlPullParser.START_TAG:
                String newtag = parser.getName();
                if (newtag.compareTo("xml") != 0) {
                    eleStack.push(newtag);
                }
                break;
            case XmlPullParser.END_TAG:
                if (parser.getName().compareTo("xml") != 0) {
                    eleStack.pop();
                }
                break;
            case XmlPullParser.TEXT:
                String tagkey = "";
                for (int i = 0; i < eleStack.size(); i++) {
                    tagkey += eleStack.elementAt(i);
                    if (i < eleStack.size() - 1)
                        tagkey += "_";
                }
                strMap.put(tagkey, parser.getText());
                break;
            default:
                break;
            }

            parserEvent = parser.next();
        }

        eleStack = null;
        parser = null;
        factory = null;
    } catch (Exception e) {
        e.printStackTrace();
        bRet = false;
    }

    return bRet;
}

From source file:de.tudarmstadt.ukp.dkpro.core.io.penntree.PennTreeUtils.java

public static PennTreeNode parsePennTree(String aTree) {
    StringTokenizer st = new StringTokenizer(aTree, "() ", true);

    PennTreeNode root = null;/*  w  w  w .  jav a 2 s  .c o  m*/
    Stack<PennTreeNode> stack = new Stack<PennTreeNode>();
    boolean seenLabel = false;

    while (st.hasMoreTokens()) {
        String t = st.nextToken().trim();
        if (t.length() == 0) {
            // Skip
        } else if ("(".equals(t)) {
            PennTreeNode n = new PennTreeNode();
            stack.push(n);
            if (root == null) {
                root = n;
            }
            seenLabel = false;
        } else if (")".equals(t)) {
            PennTreeNode n = stack.pop();
            if (!stack.isEmpty()) {
                PennTreeNode p = stack.peek();
                p.addChild(n);
            }
        } else if (seenLabel) {
            // If the node has two labels, its a leaf, add a new terminal node then.
            PennTreeNode p = stack.peek();
            PennTreeNode n = new PennTreeNode();
            n.setLabel(t);
            p.addChild(n);
        } else {
            PennTreeNode n = stack.peek();
            n.setLabel(t);
            seenLabel = true;
        }
    }

    return root;
}

From source file:com.netflix.spinnaker.clouddriver.appengine.artifacts.StorageUtils.java

public static void untarStreamToPath(InputStream inputStream, String basePath) throws IOException {
    class DirectoryTimestamp {
        public DirectoryTimestamp(File d, long m) {
            directory = d;//from   w w w. j  a va2 s. co m
            millis = m;
        }

        public File directory;
        public long millis;
    }
    ;
    // Directories come in hierarchical order within the stream, but
    // we need to set their timestamps after their children have been written.
    Stack<DirectoryTimestamp> directoryStack = new Stack<DirectoryTimestamp>();

    File baseDirectory = new File(basePath);
    baseDirectory.mkdir();

    TarArchiveInputStream tarStream = new TarArchiveInputStream(inputStream);
    for (TarArchiveEntry entry = tarStream.getNextTarEntry(); entry != null; entry = tarStream
            .getNextTarEntry()) {
        File target = new File(baseDirectory, entry.getName());
        if (entry.isDirectory()) {
            directoryStack.push(new DirectoryTimestamp(target, entry.getModTime().getTime()));
            continue;
        }
        writeStreamToFile(tarStream, target);
        target.setLastModified(entry.getModTime().getTime());
    }

    while (!directoryStack.empty()) {
        DirectoryTimestamp info = directoryStack.pop();
        info.directory.setLastModified(info.millis);
    }
    tarStream.close();
}

From source file:graphene.util.fs.FileUtils.java

public static void deleteRecursively(final File directory) throws IOException {
        final Stack<File> stack = new Stack<>();
        final List<File> temp = new LinkedList<>();
        stack.push(directory.getAbsoluteFile());
        while (!stack.isEmpty()) {
            final File top = stack.pop();
            File[] files = top.listFiles();
            if (files != null) {
                for (final File child : files) {
                    if (child.isFile()) {
                        if (!deleteFile(child)) {
                            throw new IOException("Failed to delete " + child.getCanonicalPath());
                        }/*from   www. j a  v  a2s  .  com*/
                    } else {
                        temp.add(child);
                    }
                }
            }
            files = top.listFiles();
            if ((files == null) || (files.length == 0)) {
                if (!deleteFile(top)) {
                    throw new IOException("Failed to delete " + top.getCanonicalPath());
                }
            } else {
                stack.push(top);
                for (final File f : temp) {
                    stack.push(f);
                }
            }
            temp.clear();
        }
    }

From source file:Main.java

public static void replaceFragment(FragmentManager fragmentManager, int frameId, Fragment fragmentToShow,
        String fragmentTag, Stack<Fragment> fragmentStack) {
    if (fragmentToShow == null) {
        return;//from www  .  j  ava 2s .c o m
    }

    List<Fragment> fragmentList = fragmentManager.getFragments();
    for (Fragment fragment : fragmentList) {
        if (fragment == null) {
            continue;
        }
        fragmentManager.beginTransaction().remove(fragment).commit();

        if (!fragmentStack.empty()) {
            fragmentStack.pop();
        }
    }

    fragmentManager.beginTransaction().add(frameId, fragmentToShow, fragmentTag).commit();

    fragmentStack.push(fragmentToShow);
}

From source file:com.sqewd.open.dal.core.persistence.db.EntityHelper.java

public static void setEntity(final StructEntityReflect enref, final HashMap<String, AbstractEntity> entities,
        final ResultSet rs) throws Exception {
    Class<?> type = Class.forName(enref.Class);
    Object obj = type.newInstance();
    if (!(obj instanceof AbstractEntity))
        throw new Exception("Unsupported Entity type [" + type.getCanonicalName() + "]");
    AbstractEntity entity = (AbstractEntity) obj;
    AbstractJoinGraph gr = AbstractJoinGraph.lookup(type);

    for (StructAttributeReflect attr : enref.Attributes) {
        Stack<KeyValuePair<Class<?>>> path = new Stack<KeyValuePair<Class<?>>>();
        Class<?> at = attr.Field.getType();
        KeyValuePair<Class<?>> ak = new KeyValuePair<Class<?>>();
        ak.setValue(entity.getClass());/*from w  w  w  .j  a v  a 2s . c  om*/
        ak.setKey(attr.Column);
        path.push(ak);

        if (attr.Reference == null || attr.Reference.Type != EnumRefereceType.One2Many) {
            setColumnValue(rs, attr, entity, gr, path);
        } else if (attr.Reference != null) {
            // Object ao = createListInstance(entity, attr);
            Class<?> rt = Class.forName(attr.Reference.Class);
            Object ro = rt.newInstance();
            if (!(ro instanceof AbstractEntity))
                throw new Exception(
                        "Reference [" + attr.Column + "] is of invalid type. [" + at.getCanonicalName()
                                + "] does not extend from [" + AbstractEntity.class.getCanonicalName() + "]");
            AbstractEntity ae = (AbstractEntity) getColumnValue(rs, attr, entity, gr, path);
            addListValue(ae, entity, attr);
        }

    }
    String key = entity.getEntityKey();
    if (!entities.containsKey(key)) {
        entities.put(entity.getEntityKey(), entity);
    } else {
        AbstractEntity target = entities.get(key);
        for (StructAttributeReflect attr : enref.Attributes) {
            if (attr.Reference.Type == EnumRefereceType.One2Many) {
                copyToList(entity, target, attr);
            }
        }
    }
}

From source file:cz.incad.kramerius.rest.api.k5.client.search.SearchResource.java

public static JSONObject changeJSONResult(String rawString, String context, List<JSONDecorator> decs)
        throws UnsupportedEncodingException, JSONException {

    //List<JSONDecorator> decs = this.jsonDecoratorAggregates.getDecorators();
    List<JSONArray> docsArrays = new ArrayList<JSONArray>();

    JSONObject resultJSONObject = new JSONObject(rawString);
    Stack<JSONObject> prcStack = new Stack<JSONObject>();
    prcStack.push(resultJSONObject);/*from  w  ww.j  ava 2s  . c o m*/
    while (!prcStack.isEmpty()) {
        JSONObject popped = prcStack.pop();
        //Iterator keys = popped.keys();
        for (Iterator keys = popped.keys(); keys.hasNext();) {
            Object kobj = (Object) keys.next();
            String key = (String) kobj;
            Object obj = popped.get(key);
            boolean docsKey = key.equals("docs");
            if (docsKey && (obj instanceof JSONArray)) {
                docsArrays.add((JSONArray) obj);
            }
            if (obj instanceof JSONObject) {
                prcStack.push((JSONObject) obj);
            }
            if (obj instanceof JSONArray) {
                JSONArray arr = (JSONArray) obj;
                for (int i = 0, ll = arr.length(); i < ll; i++) {
                    Object arrObj = arr.get(i);
                    if (arrObj instanceof JSONObject) {
                        prcStack.push((JSONObject) arrObj);
                    }

                }
            }

        }
    }

    for (JSONArray docs : docsArrays) {
        for (int i = 0, ll = docs.length(); i < ll; i++) {
            JSONObject docJSON = (JSONObject) docs.get(i);
            // check master pid
            changeMasterPidInJSON(docJSON);

            // fiter protected fields
            filterFieldsInJSON(docJSON);

            // decorators
            decorators(context, decs, docJSON);

            // replace pids
            replacePidsInJSON(docJSON);
        }
    }
    return resultJSONObject;
}

From source file:org.alfresco.service.cmr.calendar.CalendarTimezoneHelper.java

/**
 * Turns an iCal event into event + timezone parameters.
 * This is very closely tied to the SPP / VTI implementation,
 *  and should be replaced with something more general.
 * Until then, it is deliberately not public.
 *  //from ww w .  j  a  va2 s.c  o m
 * @param icalText iCal text for the event, and the TZ (prefixed)
 */
protected static Map<String, String> getICalParams(String icalText) {
    // Split the iCal file by lines
    String[] segregatedLines = icalText.split("\r\n");
    if (segregatedLines.length == 1 && icalText.indexOf('\n') > 0) {
        segregatedLines = icalText.split("\n");
    }

    // Perform a stack based parsing of it
    Map<String, String> result = new HashMap<String, String>();
    int attendeeNum = 0;
    Stack<String> stack = new Stack<String>();
    for (String line : segregatedLines) {
        String[] keyValue = icalLineKeyValue(line);
        if (keyValue.length >= 2) {
            if (keyValue[0].equals("BEGIN")) {
                stack.push(keyValue[1]);
                continue;
            }
            if (keyValue[0].equals("END")) {
                stack.pop();
                continue;
            }

            if (!stack.isEmpty() && stack.peek().equals(ICAL_SECTION_EVENT)) {
                if (keyValue[0].contains(";")) {
                    // Capture the extra details as suffix keys, they're sometimes needed
                    int splitAt = keyValue[0].indexOf(';');
                    String mainKey = keyValue[0].substring(0, splitAt);

                    if (splitAt < keyValue[0].length() - 2) {
                        // Grab each ;k=v part and store as mainkey-k=v
                        String[] extras = keyValue[0].substring(splitAt + 1).split(";");
                        for (String extra : extras) {
                            splitAt = extra.indexOf('=');
                            if (splitAt > -1
                                    && !result.containsKey(mainKey + "-" + extra.substring(0, splitAt - 1))) {
                                result.put(mainKey + "-" + extra.substring(0, splitAt - 1),
                                        extra.substring(splitAt + 1));
                            }
                        }
                    }

                    // Use the main key for the core value
                    keyValue[0] = mainKey;
                }
                if (keyValue[0].equals("ATTENDEE")) {
                    keyValue[0] = keyValue[0] + attendeeNum;
                    attendeeNum++;
                }

                if (!result.containsKey(keyValue[0])) {
                    result.put(keyValue[0], keyValue[keyValue.length - 1]);
                }
            }

            if (!stack.isEmpty() && stack.peek().equals(ICAL_SECTION_TIMEZONE)
                    && !result.containsKey("TZ-" + keyValue[0])) {
                // Store the top level timezone details with a TZ prefix
                result.put("TZ-" + keyValue[0], keyValue[keyValue.length - 1]);
            }
            if (stack.size() >= 2 && stack.get(stack.size() - 2).equals(ICAL_SECTION_TIMEZONE)
                    && (stack.peek().equals(ICAL_SECTION_TZ_STANDARD)
                            || stack.peek().equals(ICAL_SECTION_TZ_DAYLIGHT))
                    && !result.containsKey("TZ-" + stack.peek() + "-" + keyValue[0])) {
                // Store the timezone details with a TZ prefix + details type
                result.put("TZ-" + stack.peek() + "-" + keyValue[0], keyValue[keyValue.length - 1]);
            }
        }
    }
    return result;
}