Search in sources :

Example 61 with Stack

use of java.util.Stack in project Algorithms by pedrovgs.

the class BinaryTreePostOrder method getIterative.

public List<BinaryNode> getIterative(BinaryNode root) {
    validateTree(root);
    List<BinaryNode> result = new LinkedList<BinaryNode>();
    Stack<BinaryNode> stack = new Stack<BinaryNode>();
    stack.push(root);
    BinaryNode prev = null;
    while (!stack.empty()) {
        BinaryNode current = stack.peek();
        //keep going down
        if (prev == null || prev.getLeft() == current || prev.getRight() == current) {
            //prev == null is the situation for the root node
            if (current.getLeft() != null) {
                stack.push(current.getLeft());
            } else if (current.getRight() != null) {
                stack.push(current.getRight());
            } else {
                stack.pop();
                result.add(current);
            }
        //Go up the tree from left node need to check if there is a right child
        //if yes, push it to stack otherwise, process parent and pop stack
        } else if (current.getLeft() == prev) {
            if (current.getRight() != null) {
                stack.push(current.getRight());
            } else {
                stack.pop();
                result.add(current);
            }
        //Go up the tree from right node after coming back from right node, process parent node
        //and pop stack.
        } else if (current.getRight() == prev) {
            stack.pop();
            result.add(current);
        }
        prev = current;
    }
    return result;
}
Also used : BinaryNode(com.github.pedrovgs.binarytree.BinaryNode) LinkedList(java.util.LinkedList) Stack(java.util.Stack)

Example 62 with Stack

use of java.util.Stack in project graphdb by neo4j-attic.

the class TreeGraphTest method testBreadthFirst.

@Test
public void testBreadthFirst() throws Exception {
    Traverser traverser = Traversal.description().breadthFirst().traverse(referenceNode());
    Stack<Set<String>> levels = new Stack<Set<String>>();
    levels.push(new HashSet<String>(Arrays.asList("5", "6", "7", "8", "9", "A", "B", "C", "D")));
    levels.push(new HashSet<String>(Arrays.asList("2", "3", "4")));
    levels.push(new HashSet<String>(Arrays.asList("1")));
    assertLevels(traverser, levels);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Traverser(org.neo4j.graphdb.traversal.Traverser) Stack(java.util.Stack) Test(org.junit.Test)

Example 63 with Stack

use of java.util.Stack in project jaggery by wso2.

the class LogHostObject method jsConstructor.

/**
     * Creates a new log object for the requested resource.
     * logger name will be the resource name separated by a . (dot)
     * i.e if resource is /foo/bar/mar.jag
     * the loger name will be
     * JAGGERY.foo.bar.mar
     * <p/>
     * by default the log level is set to debug
     *
     * @param cx
     * @param args
     * @param ctorObj
     * @param inNewExpr
     * @return
     * @throws ScriptException
     */
public static Scriptable jsConstructor(Context cx, Object[] args, Function ctorObj, boolean inNewExpr) throws ScriptException {
    int argsCount = args.length;
    if (argsCount > 1) {
        HostObjectUtil.invalidNumberOfArgs(HOSTOBJECT_NAME, HOSTOBJECT_NAME, argsCount, true);
    }
    String loggerName;
    JaggeryContext context = (JaggeryContext) RhinoEngine.getContextProperty(EngineConstants.JAGGERY_CONTEXT);
    if (argsCount == 1 && (args[0] instanceof String)) {
        loggerName = (String) args[0];
    } else {
        String requestString = ((Stack<String>) context.getProperty(JAGGERY_INCLUDES_CALLSTACK)).peek();
        loggerName = ROOT_LOGGER + requestString.replace(".jag", ":jag").replace(".js", ":js").replace("/", ".");
    }
    LogHostObject logObj = new LogHostObject();
    Logger currentLogger = Logger.getLogger(loggerName);
    String appLogLevel = (String) context.getProperty(LOG_LEVEL);
    if (currentLogger.getLevel() == null) {
        currentLogger.setLevel(Level.toLevel(appLogLevel));
    }
    logObj.logger = currentLogger;
    return logObj;
}
Also used : JaggeryContext(org.jaggeryjs.scriptengine.engine.JaggeryContext) Logger(org.apache.log4j.Logger) Stack(java.util.Stack)

Example 64 with Stack

use of java.util.Stack in project android_frameworks_base by ResurrectionRemix.

the class NotificationHeaderViewWrapper method updateCropToPaddingForImageViews.

/**
     * Since we are deactivating the clipping when transforming the ImageViews don't get clipped
     * anymore during these transitions. We can avoid that by using
     * {@link ImageView#setCropToPadding(boolean)} on all ImageViews.
     */
private void updateCropToPaddingForImageViews() {
    Stack<View> stack = new Stack<>();
    stack.push(mView);
    while (!stack.isEmpty()) {
        View child = stack.pop();
        if (child instanceof ImageView) {
            ((ImageView) child).setCropToPadding(true);
        } else if (child instanceof ViewGroup) {
            ViewGroup group = (ViewGroup) child;
            for (int i = 0; i < group.getChildCount(); i++) {
                stack.push(group.getChildAt(i));
            }
        }
    }
}
Also used : ViewGroup(android.view.ViewGroup) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) TransformableView(com.android.systemui.statusbar.TransformableView) NotificationPanelView(com.android.systemui.statusbar.phone.NotificationPanelView) View(android.view.View) NotificationHeaderView(android.view.NotificationHeaderView) Stack(java.util.Stack)

Example 65 with Stack

use of java.util.Stack in project OpenAM by OpenRock.

the class EntityManager method execute.

/**
     * This method will use methods provided by ConfigManager to get "Structure
     * Template" information from the DIT. It will use this information to
     * create the "Structural Entity".
     * 
     * @param principal
     *            The Principal.
     * @param pObject
     *            The persistent object for which the entities apply.
     * @param pGUID
     *            The guid of the parent object.
     * @throws UMSException
     *             if an exception occurs.
     */
public void execute(java.security.Principal principal, PersistentObject pObject, Guid pGUID) throws UMSException {
    String className;
    HashMap hm = null;
    Set set = null;
    Iterator iter = null;
    Attr attr = null;
    AttrSet attrSet = null;
    String[] attrValues;
    if (pObject == null) {
        String msg = i18n.getString(IUMSConstants.PERSISTENT_OBJECT_PARAM_NULL);
        throw new UMSException(msg);
    }
    _principal = principal;
    _pObject = pObject;
    _stack = new Stack();
    className = _pObject.getClass().getName();
    _parentObject = _pObject;
    if (debug.messageEnabled()) {
        debug.message("GETTING ENTITY FOR:CLASS:" + className + ",PARENT:" + pGUID.getDn());
    }
    try {
        set = _configManager.getEntity(pGUID, className);
        if (!set.isEmpty()) {
            if (set.size() > 1) {
                attrSet = findEntity(_pObject, set);
            } else {
                Iterator it = set.iterator();
                if (it.hasNext())
                    attrSet = (AttrSet) it.next();
            }
        } else
            return;
        if (attrSet == null) {
            String[] args = new String[1];
            args[0] = className;
            String msg = i18n.getString(IUMSConstants.STRUCTURE_TEMPLATE_ATTRSET_NULL, args);
            throw new UMSException(msg);
        }
    } catch (ConfigManagerException cme) {
        String[] args = new String[1];
        args[0] = cme.getMessage();
        String msg = i18n.getString(IUMSConstants.CONFIG_MGR_ERROR, args);
        throw new UMSException(msg);
    }
    if (debug.messageEnabled()) {
        debug.message("ENTITY ATTRSET:" + attrSet);
    }
    attr = attrSet.getAttribute(ENTITY_CHILDNODE);
    if (attr == null) {
        return;
    }
    attrValues = attr.getStringValues();
    for (int i = 0; i < attrValues.length; i++) {
        hm = new HashMap();
        hm.put(attrValues[i], _parentObject.getGuid());
        _stack.push(hm);
    }
    while (!_stack.empty()) {
        hm = (HashMap) _stack.pop();
        set = hm.keySet();
        iter = set.iterator();
        String childNodeName = (String) iter.next();
        Guid parentGuid = (Guid) hm.get(childNodeName);
        try {
            Set childSet = _configManager.getEntity(pGUID, childNodeName);
            if (!childSet.isEmpty()) {
                iter = childSet.iterator();
                if (iter.hasNext())
                    attrSet = (AttrSet) iter.next();
            }
            if (childSet.isEmpty() | attrSet == null)
                return;
        } catch (ConfigManagerException cme) {
            String[] args = new String[1];
            args[0] = cme.getMessage();
            String msg = i18n.getString(IUMSConstants.CONFIG_MGR_ERROR, args);
            throw new UMSException(msg);
        }
        // Create Object
        //
        PersistentObject pObj = createObject(attrSet, parentGuid, pGUID);
        attr = attrSet.getAttribute(ENTITY_CHILDNODE);
        if (attr != null) {
            attrValues = attr.getStringValues();
            for (int j = 0; j < attrValues.length; j++) {
                hm = new HashMap();
                hm.put(attrValues[j], pObj.getGuid());
                _stack.push(hm);
            }
        }
    }
}
Also used : AttrSet(com.iplanet.services.ldap.AttrSet) Set(java.util.Set) HashMap(java.util.HashMap) Attr(com.iplanet.services.ldap.Attr) AttrSet(com.iplanet.services.ldap.AttrSet) Stack(java.util.Stack) Iterator(java.util.Iterator)

Aggregations

Stack (java.util.Stack)300 HashSet (java.util.HashSet)50 ArrayList (java.util.ArrayList)47 File (java.io.File)29 IOException (java.io.IOException)23 HashMap (java.util.HashMap)19 Test (org.junit.Test)19 View (android.view.View)18 Set (java.util.Set)17 List (java.util.List)16 LinkedList (java.util.LinkedList)15 ViewGroup (android.view.ViewGroup)14 Map (java.util.Map)13 Iterator (java.util.Iterator)12 Document (org.w3c.dom.Document)11 ImageView (android.widget.ImageView)10 Matcher (java.util.regex.Matcher)10 DocumentBuilder (javax.xml.parsers.DocumentBuilder)9 TestInputHandler (org.apache.maven.plugins.repository.testutil.TestInputHandler)9 PostfixMathCommandI (org.nfunk.jep.function.PostfixMathCommandI)9