Search in sources :

Example 86 with Stack

use of java.util.Stack in project ACS by ACS-Community.

the class ACSAlarmDAOImpl method processRef.

static Pattern processRef(String abase, String ref) throws PatternSyntaxException {
    Stack stack;
    String[] tmp;
    if (ref.startsWith("/") || abase == null) {
        if (ref.startsWith("/")) {
            tmp = ref.substring(1).split("/");
        } else {
            tmp = ref.split("/");
        }
        stack = new Stack();
    } else {
        tmp = ref.split("/");
        stack = new Stack();
        String[] orig = abase.substring(1).split("/");
        for (int a = 0; a < orig.length; a++) stack.push(orig[a]);
    }
    for (int a = 0; a < tmp.length; a++) {
        String t = tmp[a];
        if (".".equals(t)) {
        // ignore
        } else if ("..".equals(t)) {
            if (stack.size() > 0) {
                String removed = (String) stack.pop();
                if ("**".equals(removed))
                    throw new PatternSyntaxException(".. can't follow **", ref, -1);
            }
        } else {
            stack.push(t);
        }
    }
    StringBuffer sb = new StringBuffer();
    sb.append('^');
    int s = stack.size();
    for (int a = 0; a < s; a++) {
        if (a > 0)
            sb.append("/");
        String t = (String) stack.get(a);
        if (t.indexOf("**") >= 0) {
            if ("**".equals(t)) {
                sb.append(".*");
            } else {
                throw new PatternSyntaxException("** can't appear as a substring", t, -1);
            }
        } else {
            int l = t.length();
            for (int b = 0; b < l; b++) {
                char c = t.charAt(b);
                if (c == '*') {
                    sb.append("[^/]*");
                } else {
                    regexEncodeChar(sb, c);
                }
            }
        }
    }
    sb.append('$');
    return Pattern.compile(sb.toString());
}
Also used : Stack(java.util.Stack) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 87 with Stack

use of java.util.Stack in project TapTargetView by KeepSafe.

the class ToolbarTapTarget method findOverflowView.

private static View findOverflowView(Object instance) {
    final ToolbarProxy toolbar = proxyOf(instance);
    // First we try to find the overflow menu view via drawable matching
    final Drawable overflowDrawable = toolbar.getOverflowIcon();
    if (overflowDrawable != null) {
        final Stack<ViewGroup> parents = new Stack<>();
        parents.push((ViewGroup) toolbar.internalToolbar());
        while (!parents.empty()) {
            ViewGroup parent = parents.pop();
            final int size = parent.getChildCount();
            for (int i = 0; i < size; ++i) {
                final View child = parent.getChildAt(i);
                if (child instanceof ViewGroup) {
                    parents.push((ViewGroup) child);
                    continue;
                }
                if (child instanceof ImageView) {
                    final Drawable childDrawable = ((ImageView) child).getDrawable();
                    if (childDrawable == overflowDrawable) {
                        return child;
                    }
                }
            }
        }
    }
    // desired target
    try {
        final Object actionMenuView = ReflectUtil.getPrivateField(toolbar.internalToolbar(), "mMenuView");
        final Object actionMenuPresenter = ReflectUtil.getPrivateField(actionMenuView, "mPresenter");
        return (View) ReflectUtil.getPrivateField(actionMenuPresenter, "mOverflowButton");
    } catch (NoSuchFieldException e) {
        throw new IllegalStateException("Could not find overflow view for Toolbar!", e);
    } catch (IllegalAccessException e) {
        throw new IllegalStateException("Unable to access overflow view for Toolbar!", e);
    }
}
Also used : ViewGroup(android.view.ViewGroup) Drawable(android.graphics.drawable.Drawable) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) View(android.view.View) Stack(java.util.Stack)

Example 88 with Stack

use of java.util.Stack in project adempiere by adempiere.

the class WDelete method onEvent.

// createNodes(arg1, arg2)	
@Override
public void onEvent(Event e) throws Exception {
    boolean commit = !dryRun.isChecked();
    if (e.getTarget().getId().equals(ConfirmPanel.A_CANCEL)) {
        dispose();
    } else if (e.getTarget().equals(clientPick)) {
        String clientIDStr = clientPick.getSelectedItem().getLabel();
        clientId = clientMap.get(clientIDStr);
        Object value = tablePick.getValue();
        generateTree(value, clientId);
    } else if (e.getTarget().getId().equals(ConfirmPanel.A_OK)) {
        //String clientIDStr = clientPick.getText();
        //Integer clientId = clientMap.get(clientIDStr);
        Object objTableID = tablePick.getValue();
        int tableId = 0;
        if (objTableID != null)
            tableId = (Integer) objTableID;
        if (tableId == 0 || clientId == null) {
            FDialog.error(form.getWindowNo(), "Error", "Select client and base table for cascade delete.");
        } else {
            m_totalCount = 0;
            m_trx = Trx.get(Trx.createTrxName("delete"), true);
            String errorMsg = "";
            try {
                @SuppressWarnings("unchecked") Collection<Treeitem> items = tree.getItems();
                Iterator<Treeitem> nodes = items.iterator();
                Stack<DeleteEntitiesModel> stack = new Stack<DeleteEntitiesModel>();
                while (nodes.hasNext()) {
                    stack.push((DeleteEntitiesModel) (((Treeitem) nodes.next()).getValue()));
                }
                while (!stack.empty()) {
                    DeleteEntitiesModel tableData = (DeleteEntitiesModel) stack.pop();
                    m_totalCount += tableData.delete(m_trx);
                }
                if (commit)
                    m_trx.commit(true);
                else
                    m_trx.rollback(true);
            } catch (Exception ex) {
                errorMsg = ex.getLocalizedMessage();
                log.log(Level.WARNING, "Cascade delete failed.", ex);
                m_totalCount = 0;
                m_trx.rollback();
                FDialog.error(form.getWindowNo(), "DeleteError", errorMsg);
                return;
            } finally {
                m_trx.close();
            }
            FDialog.info(form.getWindowNo(), form, "DeleteSuccess", "Records deleted:" + " #" + m_totalCount);
            dispose();
        }
    }
}
Also used : DeleteEntitiesModel(org.adempiere.util.DeleteEntitiesModel) SQLException(java.sql.SQLException) AdempiereException(org.adempiere.exceptions.AdempiereException) Stack(java.util.Stack) Treeitem(org.zkoss.zul.Treeitem)

Example 89 with Stack

use of java.util.Stack in project drill by apache.

the class MaprDBJsonRecordReader method getFieldPathForProjection.

/*
   * Extracts contiguous named segments from the SchemaPath, starting from the
   * root segment and build the FieldPath from it for projection.
   *
   * This is due to bug 22726 and 22727, which cause DB's DocumentReaders to
   * behave incorrectly for sparse lists, hence we avoid projecting beyond the
   * first encountered ARRAY field and let Drill handle the projection.
   */
private static FieldPath getFieldPathForProjection(SchemaPath column) {
    Stack<PathSegment.NameSegment> pathSegments = new Stack<PathSegment.NameSegment>();
    PathSegment seg = column.getRootSegment();
    while (seg != null && seg.isNamed()) {
        pathSegments.push((PathSegment.NameSegment) seg);
        seg = seg.getChild();
    }
    FieldSegment.NameSegment child = null;
    while (!pathSegments.isEmpty()) {
        child = new FieldSegment.NameSegment(pathSegments.pop().getPath(), child, false);
    }
    return new FieldPath(child);
}
Also used : FieldSegment(org.ojai.FieldSegment) FieldPath(org.ojai.FieldPath) PathSegment(org.apache.drill.common.expression.PathSegment) Stack(java.util.Stack)

Example 90 with Stack

use of java.util.Stack in project geode by apache.

the class InternalDataSerializer method initializeWellKnownSerializers.

private static void initializeWellKnownSerializers() {
    // ArrayBlockingQueue does not have zero-arg constructor
    // LinkedBlockingQueue does have zero-arg constructor but no way to get capacity
    classesToSerializers.put("java.lang.String", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            try {
                writeString((String) o, out);
            } catch (UTFDataFormatException ex) {
                // See bug 30428
                String s = "While writing a String of length " + ((String) o).length();
                UTFDataFormatException ex2 = new UTFDataFormatException(s);
                ex2.initCause(ex);
                throw ex2;
            }
            return true;
        }
    });
    classesToSerializers.put("java.net.InetAddress", new WellKnownDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            InetAddress address = (InetAddress) o;
            out.writeByte(INET_ADDRESS);
            writeInetAddress(address, out);
            return true;
        }
    });
    classesToSerializers.put("java.net.Inet4Address", new WellKnownDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            InetAddress address = (InetAddress) o;
            out.writeByte(INET_ADDRESS);
            writeInetAddress(address, out);
            return true;
        }
    });
    classesToSerializers.put("java.net.Inet6Address", new WellKnownDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            InetAddress address = (InetAddress) o;
            out.writeByte(INET_ADDRESS);
            writeInetAddress(address, out);
            return true;
        }
    });
    classesToSerializers.put("java.lang.Class", new WellKnownDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            Class c = (Class) o;
            if (c.isPrimitive()) {
                writePrimitiveClass(c, out);
            } else {
                out.writeByte(CLASS);
                writeClass(c, out);
            }
            return true;
        }
    });
    classesToSerializers.put("java.lang.Boolean", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            Boolean value = (Boolean) o;
            out.writeByte(BOOLEAN);
            writeBoolean(value, out);
            return true;
        }
    });
    classesToSerializers.put("java.lang.Character", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            Character value = (Character) o;
            out.writeByte(CHARACTER);
            writeCharacter(value, out);
            return true;
        }
    });
    classesToSerializers.put("java.lang.Byte", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            Byte value = (Byte) o;
            out.writeByte(BYTE);
            writeByte(value, out);
            return true;
        }
    });
    classesToSerializers.put("java.lang.Short", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            Short value = (Short) o;
            out.writeByte(SHORT);
            writeShort(value, out);
            return true;
        }
    });
    classesToSerializers.put("java.lang.Integer", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            Integer value = (Integer) o;
            out.writeByte(INTEGER);
            writeInteger(value, out);
            return true;
        }
    });
    classesToSerializers.put("java.lang.Long", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            Long value = (Long) o;
            out.writeByte(LONG);
            writeLong(value, out);
            return true;
        }
    });
    classesToSerializers.put("java.lang.Float", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            Float value = (Float) o;
            out.writeByte(FLOAT);
            writeFloat(value, out);
            return true;
        }
    });
    classesToSerializers.put("java.lang.Double", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            Double value = (Double) o;
            out.writeByte(DOUBLE);
            writeDouble(value, out);
            return true;
        }
    });
    // boolean[]
    classesToSerializers.put(// boolean[]
    "[Z", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            out.writeByte(BOOLEAN_ARRAY);
            writeBooleanArray((boolean[]) o, out);
            return true;
        }
    });
    // byte[]
    classesToSerializers.put(// byte[]
    "[B", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            byte[] array = (byte[]) o;
            out.writeByte(BYTE_ARRAY);
            writeByteArray(array, out);
            return true;
        }
    });
    // char[]
    classesToSerializers.put(// char[]
    "[C", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            out.writeByte(CHAR_ARRAY);
            writeCharArray((char[]) o, out);
            return true;
        }
    });
    // double[]
    classesToSerializers.put(// double[]
    "[D", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            double[] array = (double[]) o;
            out.writeByte(DOUBLE_ARRAY);
            writeDoubleArray(array, out);
            return true;
        }
    });
    // float[]
    classesToSerializers.put(// float[]
    "[F", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            float[] array = (float[]) o;
            out.writeByte(FLOAT_ARRAY);
            writeFloatArray(array, out);
            return true;
        }
    });
    // int[]
    classesToSerializers.put(// int[]
    "[I", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            int[] array = (int[]) o;
            out.writeByte(INT_ARRAY);
            writeIntArray(array, out);
            return true;
        }
    });
    // long[]
    classesToSerializers.put(// long[]
    "[J", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            long[] array = (long[]) o;
            out.writeByte(LONG_ARRAY);
            writeLongArray(array, out);
            return true;
        }
    });
    // short[]
    classesToSerializers.put(// short[]
    "[S", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            short[] array = (short[]) o;
            out.writeByte(SHORT_ARRAY);
            writeShortArray(array, out);
            return true;
        }
    });
    // String[]
    classesToSerializers.put(// String[]
    "[Ljava.lang.String;", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            String[] array = (String[]) o;
            out.writeByte(STRING_ARRAY);
            writeStringArray(array, out);
            return true;
        }
    });
    classesToSerializers.put(TimeUnit.NANOSECONDS.getClass().getName(), new WellKnownDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            out.writeByte(TIME_UNIT);
            out.writeByte(TIME_UNIT_NANOSECONDS);
            return true;
        }
    });
    classesToSerializers.put(TimeUnit.MICROSECONDS.getClass().getName(), new WellKnownDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            out.writeByte(TIME_UNIT);
            out.writeByte(TIME_UNIT_MICROSECONDS);
            return true;
        }
    });
    classesToSerializers.put(TimeUnit.MILLISECONDS.getClass().getName(), new WellKnownDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            out.writeByte(TIME_UNIT);
            out.writeByte(TIME_UNIT_MILLISECONDS);
            return true;
        }
    });
    classesToSerializers.put(TimeUnit.SECONDS.getClass().getName(), new WellKnownDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            out.writeByte(TIME_UNIT);
            out.writeByte(TIME_UNIT_SECONDS);
            return true;
        }
    });
    classesToSerializers.put("java.util.Date", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            Date date = (Date) o;
            out.writeByte(DATE);
            writeDate(date, out);
            return true;
        }
    });
    classesToSerializers.put("java.io.File", new WellKnownDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            File file = (File) o;
            out.writeByte(FILE);
            writeFile(file, out);
            return true;
        }
    });
    classesToSerializers.put("java.util.ArrayList", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            ArrayList list = (ArrayList) o;
            out.writeByte(ARRAY_LIST);
            writeArrayList(list, out);
            return true;
        }
    });
    classesToSerializers.put("java.util.LinkedList", new WellKnownDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            LinkedList list = (LinkedList) o;
            out.writeByte(LINKED_LIST);
            writeLinkedList(list, out);
            return true;
        }
    });
    classesToSerializers.put("java.util.Vector", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            out.writeByte(VECTOR);
            writeVector((Vector) o, out);
            return true;
        }
    });
    classesToSerializers.put("java.util.Stack", new WellKnownDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            out.writeByte(STACK);
            writeStack((Stack) o, out);
            return true;
        }
    });
    classesToSerializers.put("java.util.HashSet", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            HashSet list = (HashSet) o;
            out.writeByte(HASH_SET);
            writeHashSet(list, out);
            return true;
        }
    });
    classesToSerializers.put("java.util.LinkedHashSet", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            out.writeByte(LINKED_HASH_SET);
            writeLinkedHashSet((LinkedHashSet) o, out);
            return true;
        }
    });
    classesToSerializers.put("java.util.HashMap", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            HashMap list = (HashMap) o;
            out.writeByte(HASH_MAP);
            writeHashMap(list, out);
            return true;
        }
    });
    classesToSerializers.put("java.util.IdentityHashMap", new WellKnownDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            out.writeByte(IDENTITY_HASH_MAP);
            writeIdentityHashMap((IdentityHashMap) o, out);
            return true;
        }
    });
    classesToSerializers.put("java.util.Hashtable", new WellKnownPdxDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            out.writeByte(HASH_TABLE);
            writeHashtable((Hashtable) o, out);
            return true;
        }
    });
    classesToSerializers.put("java.util.Properties", new WellKnownDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            Properties props = (Properties) o;
            out.writeByte(PROPERTIES);
            writeProperties(props, out);
            return true;
        }
    });
    classesToSerializers.put("java.util.TreeMap", new WellKnownDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            out.writeByte(TREE_MAP);
            writeTreeMap((TreeMap) o, out);
            return true;
        }
    });
    classesToSerializers.put("java.util.TreeSet", new WellKnownDS() {

        @Override
        public boolean toData(Object o, DataOutput out) throws IOException {
            out.writeByte(TREE_SET);
            writeTreeSet((TreeSet) o, out);
            return true;
        }
    });
    if (is662SerializationEnabled()) {
        classesToSerializers.put("java.math.BigInteger", new WellKnownDS() {

            @Override
            public boolean toData(Object o, DataOutput out) throws IOException {
                out.writeByte(BIG_INTEGER);
                writeBigInteger((BigInteger) o, out);
                return true;
            }
        });
        classesToSerializers.put("java.math.BigDecimal", new WellKnownDS() {

            @Override
            public boolean toData(Object o, DataOutput out) throws IOException {
                out.writeByte(BIG_DECIMAL);
                writeBigDecimal((BigDecimal) o, out);
                return true;
            }
        });
        classesToSerializers.put("java.util.UUID", new WellKnownDS() {

            @Override
            public boolean toData(Object o, DataOutput out) throws IOException {
                out.writeByte(UUID);
                writeUUID((UUID) o, out);
                return true;
            }
        });
        classesToSerializers.put("java.sql.Timestamp", new WellKnownDS() {

            @Override
            public boolean toData(Object o, DataOutput out) throws IOException {
                out.writeByte(TIMESTAMP);
                writeTimestamp((Timestamp) o, out);
                return true;
            }
        });
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DataOutput(java.io.DataOutput) CopyOnWriteHashMap(org.apache.geode.internal.util.concurrent.CopyOnWriteHashMap) IdentityHashMap(java.util.IdentityHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) IdentityHashMap(java.util.IdentityHashMap) ArrayList(java.util.ArrayList) Properties(java.util.Properties) Timestamp(java.sql.Timestamp) TreeSet(java.util.TreeSet) UUID(java.util.UUID) Vector(java.util.Vector) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet) Hashtable(java.util.Hashtable) IOException(java.io.IOException) GemFireIOException(org.apache.geode.GemFireIOException) TreeMap(java.util.TreeMap) Date(java.util.Date) LinkedList(java.util.LinkedList) BigDecimal(java.math.BigDecimal) Stack(java.util.Stack) BigInteger(java.math.BigInteger) UTFDataFormatException(java.io.UTFDataFormatException) BigInteger(java.math.BigInteger) ObjectStreamClass(java.io.ObjectStreamClass) InetAddress(java.net.InetAddress) File(java.io.File)

Aggregations

Stack (java.util.Stack)245 HashSet (java.util.HashSet)42 ArrayList (java.util.ArrayList)37 File (java.io.File)23 IOException (java.io.IOException)22 View (android.view.View)18 Test (org.junit.Test)18 ViewGroup (android.view.ViewGroup)14 HashMap (java.util.HashMap)14 Set (java.util.Set)12 LinkedList (java.util.LinkedList)11 List (java.util.List)11 ImageView (android.widget.ImageView)10 Map (java.util.Map)10 Document (org.w3c.dom.Document)10 TestInputHandler (org.apache.maven.plugins.repository.testutil.TestInputHandler)9 PostfixMathCommandI (org.nfunk.jep.function.PostfixMathCommandI)9 DocumentBuilder (javax.xml.parsers.DocumentBuilder)8 NotificationPanelView (com.android.systemui.statusbar.phone.NotificationPanelView)7 TreeSet (java.util.TreeSet)7