Search in sources :

Example 66 with ListIterator

use of java.util.ListIterator in project rest.li by linkedin.

the class URIParamUtils method encodeDataObject.

private static void encodeDataObject(Object obj, URLEscaper.Escaping escaping, UriComponent.Type componentType, StringBuilder stringBuilder) {
    if (obj instanceof DataComplex) {
        if (obj instanceof DataMap) {
            DataMap dataMap = (DataMap) obj;
            stringBuilder.append(URIConstants.OBJ_START);
            if (!dataMap.isEmpty()) {
                List<String> keys = new ArrayList<String>(dataMap.keySet());
                Collections.sort(keys);
                ListIterator<String> iterator = keys.listIterator();
                String currentKey = iterator.next();
                mapEncodingHelper(currentKey, dataMap.get(currentKey), escaping, componentType, stringBuilder);
                while (iterator.hasNext()) {
                    stringBuilder.append(URIConstants.ITEM_SEP);
                    currentKey = iterator.next();
                    mapEncodingHelper(currentKey, dataMap.get(currentKey), escaping, componentType, stringBuilder);
                }
            }
            stringBuilder.append(URIConstants.OBJ_END);
        } else if (obj instanceof DataList) {
            DataList dataList = (DataList) obj;
            stringBuilder.append(URIConstants.LIST_PREFIX);
            stringBuilder.append(URIConstants.OBJ_START);
            if (!dataList.isEmpty()) {
                ListIterator<Object> iterator = dataList.listIterator();
                encodeDataObject(iterator.next(), escaping, componentType, stringBuilder);
                while (iterator.hasNext()) {
                    stringBuilder.append(URIConstants.ITEM_SEP);
                    encodeDataObject(iterator.next(), escaping, componentType, stringBuilder);
                }
            }
            stringBuilder.append(URIConstants.OBJ_END);
        } else {
            throw new IllegalArgumentException(obj.getClass() + " is an unknown subtype of dataComplex.");
        }
    } else {
        stringBuilder.append(encodeString(DataTemplateUtil.stringify(obj), escaping, componentType));
    }
}
Also used : DataComplex(com.linkedin.data.DataComplex) DataList(com.linkedin.data.DataList) ArrayList(java.util.ArrayList) ListIterator(java.util.ListIterator) DataMap(com.linkedin.data.DataMap)

Example 67 with ListIterator

use of java.util.ListIterator in project Openfire by igniterealtime.

the class FlowWriter method A.

public void A(AudioPacket a) {
    int i = a.J();
    if (i == 0) {
        G.error("Negative acknowledgment");
        D("Negative acknowledgment");
        return;
    }
    int j = L;
    int k = a.J();
    int l = L + 1;
    if (k > N) {
        G.error((new StringBuilder()).append("Acknowledgment received ").append(k).append(" superior than the current sending stage ").append(N).append(" on flowWriter ").append(J).toString());
        L = N;
    } else if (k <= L) {
        if (a.I() == 0)
            G.debug((new StringBuilder()).append("Acknowledgment ").append(k).append(" obsolete on flowWriter ").append(J).toString());
    } else {
        L = k;
    }
    int i1 = L;
    int j1 = a.H();
    while (a.I() > 0) i1 += a.J() + a.J() + 2;
    if (j1 != a.H())
        a.E(j1);
    int k1 = 0;
    int l1 = 0;
    boolean flag = false;
    boolean flag1 = true;
    boolean flag2 = false;
    synchronized (O) {
        ListIterator listiterator = O.listIterator();
        do {
            if (flag2 || !listiterator.hasNext())
                break;
            I i2 = (I) listiterator.next();
            if (i2.B().size() == 0) {
                G.error((new StringBuilder()).append("Message ").append(l + 1).append(" is bad formatted on flowWriter ").append(J).toString());
            } else {
                Integer[] ainteger = (Integer[]) i2.B().keySet().toArray(new Integer[0]);
                Integer integer = ainteger[0];
                int j2 = 0;
                do {
                    if (j2 >= ainteger.length)
                        break;
                    if (L >= l) {
                        i2.B().remove(ainteger[0]);
                        ainteger = (Integer[]) i2.B().keySet().toArray(new Integer[0]);
                        j2 = 0;
                        if (j2 < ainteger.length)
                            integer = ainteger[j2];
                        D++;
                        l++;
                        continue;
                    }
                    do {
                        if (flag2 || k1 != 0)
                            break;
                        if (k1 == 0)
                            if (a.I() > 0) {
                                k1 = a.J() + 1;
                                l1 = k + 1;
                                k = l1 + k1 + a.J();
                            } else {
                                flag2 = true;
                                break;
                            }
                        if (l1 > N) {
                            G.error((new StringBuilder()).append("Lost information received ").append(l1).append(" have not been yet sent on flowWriter ").append(J).toString());
                            flag2 = true;
                            break;
                        }
                        if (l1 > L)
                            break;
                        k1--;
                        l1++;
                    } while (true);
                    if (flag2)
                        break;
                    if (l1 != l) {
                        if (flag) {
                            l++;
                            if (j2 < ainteger.length - 1) {
                                j2++;
                                integer = ainteger[j2];
                            }
                            flag1 = true;
                        } else {
                            L = l;
                        }
                    } else if (!i2.A()) {
                        if (flag) {
                            j2++;
                            integer = ainteger[j2];
                            l++;
                            flag1 = true;
                        } else {
                            G.debug((new StringBuilder()).append("FlowWriter ").append(J).append(" : message ").append(l).append(" lost").toString());
                            D--;
                            M++;
                            L = l;
                        }
                        k1--;
                        l1++;
                    } else {
                        flag = true;
                        if (((Integer) i2.B().get(integer)).intValue() >= i1 || k == l1 + 2) {
                            l++;
                            flag1 = true;
                            k1--;
                            l1++;
                            if (j2 < ainteger.length - 1) {
                                j2++;
                                integer = ainteger[j2];
                            }
                        } else {
                            G.debug((new StringBuilder()).append("FlowWriter ").append(J).append(" : stage ").append(l).append(" repeated").toString());
                            int k2 = integer.intValue();
                            Packet b1 = i2.A(k2);
                            int i3 = b1.I();
                            i2.B().put(integer, Integer.valueOf(N));
                            int j3 = i3;
                            byte byte0 = 0;
                            if (k2 > 0)
                                byte0 |= com.jcumulus.server.rtmfp.publisher.E.M.intValue();
                            if (j2 < ainteger.length - 1) {
                                j2++;
                                integer = ainteger[j2];
                                byte0 |= com.jcumulus.server.rtmfp.publisher.E.C.intValue();
                                j3 = integer.intValue() - k2;
                            }
                            com.jcumulus.server.rtmfp.stream.B b2 = H.B();
                            int k3 = j3 + 4;
                            if (!flag1 && k3 > b2.D()) {
                                H.A(false);
                                flag1 = true;
                            }
                            if (flag1)
                                k3 += D(l);
                            if (k3 > b2.D())
                                H.A(false);
                            k3 -= 3;
                            A(H.A(((byte) (flag1 ? 16 : 17)), k3, null), l, byte0, flag1, b1, j3);
                            i3 -= j3;
                            flag1 = false;
                            k1--;
                            l1++;
                            l++;
                        }
                    }
                } while (true);
                if (i2.B().size() == 0) {
                    if (i2.A())
                        F--;
                    if (D > 0) {
                        Packet b = i2.D();
                        int l2 = b.I();
                        A(D, M, b, l2);
                        D = M = 0;
                    }
                    listiterator.remove();
                }
            }
        } while (true);
    }
    if (k1 > 0 && a.I() > 0)
        G.error((new StringBuilder()).append("Some lost information received have not been yet sent on flowWriter ").append(J).toString());
    if (F == 0)
        A.B();
    else if (L > j || flag)
        A.A();
}
Also used : ListIterator(java.util.ListIterator)

Example 68 with ListIterator

use of java.util.ListIterator in project TextJustify-Android by bluejamesbond.

the class StringDocumentLayout method onMeasure.

@Override
public boolean onMeasure(IProgress<Float> progress, ICancel<Boolean> cancelled) {
    boolean done = true;
    String textCpy = this.text.toString();
    if (textChange) {
        chunks.clear();
        int start = 0;
        while (start > -1) {
            int next = textCpy.indexOf('\n', start);
            if (next < 0) {
                chunks.add(textCpy.substring(start, textCpy.length()));
            } else {
                chunks.add(textCpy.substring(start, next++));
            }
            start = next;
        }
        textChange = false;
    }
    // Empty out any existing tokens
    List<Token> tokensList = new ConcurrentModifiableLinkedList<>();
    Paint paint = getPaint();
    paint.setTextAlign(Paint.Align.LEFT);
    // Get basic settings widget properties
    int lineNumber = 0;
    float width = params.parentWidth - params.insetPaddingRight - params.insetPaddingLeft;
    float lineHeight = getTokenAscent(0) + getTokenDescent(0);
    float x, prog = 0, chunksLen = chunks.size();
    float y = params.insetPaddingTop + getTokenAscent(0);
    float spaceOffset = paint.measureText(" ") * params.wordSpacingMultiplier;
    main: for (String paragraph : chunks) {
        if (cancelled.isCancelled()) {
            done = false;
            break;
        }
        progress.onUpdate(prog++ / chunksLen);
        if (lineNumber >= params.maxLines) {
            break;
        }
        // Start at x = 0 for drawing textCpy
        x = params.insetPaddingLeft;
        String trimParagraph = paragraph.trim();
        // If the line contains only spaces or line breaks
        if (trimParagraph.length() == 0) {
            tokensList.add(new LineBreak(lineNumber++, y));
            y += lineHeight;
            continue;
        }
        float wrappedWidth = paint.measureText(trimParagraph);
        // Line fits, then don't wrap
        if (wrappedWidth < width) {
            // activeCanvas.drawText(paragraph, x, y, paint);
            tokensList.add(new SingleLine(lineNumber++, x, y, trimParagraph));
            y += lineHeight;
            continue;
        }
        // Allow leading spaces
        int start = 0;
        int overallCounter = 0;
        ConcurrentModifiableLinkedList<Unit> units = tokenize(paragraph);
        ListIterator<Unit> unitIterator = units.listIterator();
        ListIterator<Unit> justifyIterator = units.listIterator();
        while (true) {
            x = params.insetPaddingLeft;
            // Line doesn't fit, then apply wrapping
            LineAnalysis format = fit(justifyIterator, start, spaceOffset, width);
            int tokenCount = format.end - format.start;
            boolean leftOverTokens = justifyIterator.hasNext();
            if (tokenCount == 0 && leftOverTokens) {
                new PlainDocumentException("Cannot fit word(s) into one line. Font size too large?").printStackTrace();
                done = false;
                break main;
            }
            // Draw each word here
            float offset = 0;
            switch(params.textAlignment) {
                case CENTER:
                    {
                        x += format.remainWidth / 2;
                        break;
                    }
                case RIGHT:
                    {
                        x += format.remainWidth;
                        break;
                    }
                case JUSTIFIED:
                    {
                        offset = tokenCount > 2 && leftOverTokens ? format.remainWidth / (tokenCount - 1) : 0;
                        break;
                    }
                default:
                    {
                    // LEFT
                    }
            }
            for (int i = format.start; i < format.end; i++) {
                Unit unit = unitIterator.next();
                unit.x = x;
                unit.y = y;
                unit.lineNumber = lineNumber;
                x += offset + paint.measureText(unit.unit) + spaceOffset;
                // Add to all tokens
                tokensList.add(unit);
            }
            // Increment to next line
            y += lineHeight;
            // Next line
            lineNumber++;
            if (lineNumber >= params.maxLines) {
                break main;
            }
            // Check cancelled
            if (cancelled.isCancelled()) {
                done = false;
                break;
            }
            // continue
            if (leftOverTokens) {
                // Next start index for tokens
                start = format.end;
                continue;
            }
            // paragraph
            break;
        }
    }
    Token[] tokensArr = new Token[tokensList.size()];
    tokensList.toArray(tokensArr);
    tokensList.clear();
    lineCount = lineNumber;
    tokens = tokensArr;
    params.changed = !done;
    measuredHeight = (int) (y - getTokenAscent(0) + params.insetPaddingBottom);
    return done;
}
Also used : TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) ListIterator(java.util.ListIterator) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 69 with ListIterator

use of java.util.ListIterator in project hazelcast by hazelcast.

the class BinaryCompatibilityTest method equals.

public static boolean equals(Object a, Object b) {
    if (a == b) {
        return true;
    }
    if (a == null || b == null) {
        return false;
    }
    if (a.getClass().isArray() && b.getClass().isArray()) {
        int length = Array.getLength(a);
        if (length > 0 && !a.getClass().getComponentType().equals(b.getClass().getComponentType())) {
            return false;
        }
        if (Array.getLength(b) != length) {
            return false;
        }
        for (int i = 0; i < length; i++) {
            if (!equals(Array.get(a, i), Array.get(b, i))) {
                return false;
            }
        }
        return true;
    }
    if (a instanceof List && b instanceof List) {
        ListIterator e1 = ((List) a).listIterator();
        ListIterator e2 = ((List) b).listIterator();
        while (e1.hasNext() && e2.hasNext()) {
            Object o1 = e1.next();
            Object o2 = e2.next();
            if (!equals(o1, o2)) {
                return false;
            }
        }
        return !(e1.hasNext() || e2.hasNext());
    }
    return a.equals(b);
}
Also used : List(java.util.List) LinkedList(java.util.LinkedList) ListIterator(java.util.ListIterator)

Example 70 with ListIterator

use of java.util.ListIterator in project j2objc by google.

the class AbstractListTest method test_subListII.

/**
	 * @tests java.util.AbstractList#subList(int, int)
	 */
public void test_subListII() {
    // Test each of the SubList operations to ensure a
    // ConcurrentModificationException does not occur on an AbstractList
    // which does not update modCount
    SimpleList mList = new SimpleList();
    mList.add(new Object());
    mList.add(new Object());
    List sList = mList.subList(0, 2);
    // calls add(int, Object)
    sList.add(new Object());
    sList.get(0);
    sList.add(0, new Object());
    sList.get(0);
    sList.addAll(Arrays.asList(new String[] { "1", "2" }));
    sList.get(0);
    sList.addAll(0, Arrays.asList(new String[] { "3", "4" }));
    sList.get(0);
    sList.remove(0);
    sList.get(0);
    ListIterator lit = sList.listIterator();
    lit.add(new Object());
    lit.next();
    lit.remove();
    lit.next();
    // calls removeRange()
    sList.clear();
    sList.add(new Object());
    // test the type of sublist that is returned
    List al = new ArrayList();
    for (int i = 0; i < 10; i++) {
        al.add(new Integer(i));
    }
    assertTrue("Sublist returned should have implemented Random Access interface", al.subList(3, 7) instanceof RandomAccess);
    List ll = new LinkedList();
    for (int i = 0; i < 10; i++) {
        ll.add(new Integer(i));
    }
    assertTrue("Sublist returned should not have implemented Random Access interface", !(ll.subList(3, 7) instanceof RandomAccess));
}
Also used : ArrayList(java.util.ArrayList) RandomAccess(java.util.RandomAccess) List(java.util.List) AbstractList(java.util.AbstractList) LinkedList(java.util.LinkedList) ArrayList(java.util.ArrayList) ListIterator(java.util.ListIterator) LinkedList(java.util.LinkedList)

Aggregations

ListIterator (java.util.ListIterator)121 ArrayList (java.util.ArrayList)42 List (java.util.List)41 LinkedList (java.util.LinkedList)26 Iterator (java.util.Iterator)21 Map (java.util.Map)12 Handler (com.sun.jsftemplating.annotation.Handler)8 AbstractList (java.util.AbstractList)7 HashMap (java.util.HashMap)7 AbstractSequentialList (java.util.AbstractSequentialList)6 IOException (java.io.IOException)5 RandomAccess (java.util.RandomAccess)5 SelectResults (org.apache.geode.cache.query.SelectResults)5 Test (org.junit.Test)5 File (java.io.File)4 HashSet (java.util.HashSet)4 NoSuchElementException (java.util.NoSuchElementException)4 SipURI (javax.sip.address.SipURI)4 ArgumentIntKey (lucee.runtime.type.scope.ArgumentIntKey)4 StructTypeImpl (org.apache.geode.cache.query.internal.types.StructTypeImpl)4