Example usage for java.lang Iterable Iterable

List of usage examples for java.lang Iterable Iterable

Introduction

In this page you can find the example usage for java.lang Iterable Iterable.

Prototype

Iterable

Source Link

Usage

From source file:com.taobao.android.repatch.InsTructionsReIClassDef.java

@Override
protected Iterable<? extends Instruction> reInstructions(Iterable<? extends Instruction> instructions) {
    final List<Instruction> reinstructions = new ArrayList<Instruction>();
    for (final Instruction instruction : instructions) {
        if (instruction instanceof ReferenceInstruction) {
            Opcode opcode = instruction.getOpcode();
            if (opcode.referenceType == ReferenceType.METHOD) {
                boolean isBasic = false;
                MethodReference methodReference = null;
                try {
                    methodReference = (MethodReference) ((ReferenceInstruction) instruction).getReference();
                    if (methodReference.getDefiningClass().contains("Ljava/lang")
                            || methodReference.getDefiningClass().startsWith("Ljava/util/")
                            || methodReference.getDefiningClass().startsWith("[Ljava/lang")) {
                        reinstructions.add(ImmutableInstruction.of(instruction));
                        continue;
                    }//from   w  w w  .  ja v  a 2s .c  o m
                    String returnType = methodReference.getReturnType();
                    boolean isArray = false;
                    if (returnType.startsWith("[")) {
                        isArray = true;
                    }
                    String methodName = methodReference.getName();
                    if (methodName.equals("InitBundleInfoByVersionIfNeed")) {
                        System.out.println("InitBundleInfoByVersionIfNeed");
                    }
                    if (basicType.containsKey(returnType)) {
                        isBasic = true;
                    }
                    List<? extends CharSequence> paramTypes = methodReference.getParameterTypes();
                    List<CharSequence> dalvikParamTypes = new ArrayList<CharSequence>();

                    List<CharSequence> newParamTypes = new ArrayList<CharSequence>();

                    for (CharSequence charSequence : paramTypes) {
                        if (basicType.containsKey(charSequence.toString())) {
                            newParamTypes.add(charSequence);
                            dalvikParamTypes.add(basicType.get(charSequence.toString()));
                            continue;
                        }
                        boolean isArray1 = charSequence.toString().startsWith("[");
                        dalvikParamTypes.add(DefineUtils.getDalvikClassName(charSequence.toString())
                                + (isArray ? "[]" : ""));
                        newParamTypes.add(DefineUtils.getDefineClassName(
                                classProcessor.classProcess(
                                        DefineUtils.getDalvikClassName(charSequence.toString())).className,
                                isArray1));
                    }
                    final ImmutableMethodReference immutableReference = new ImmutableMethodReference(
                            DefineUtils.getDefineClassName(
                                    classProcessor.classProcess(DefineUtils
                                            .getDalvikClassName(methodReference.getDefiningClass())).className,
                                    false),

                            classProcessor.methodProcess(
                                    DefineUtils.getDalvikClassName(methodReference.getDefiningClass()),
                                    methodReference.getName(),
                                    isBasic ? basicType.get(methodReference.getReturnType())
                                            : DefineUtils.getDalvikClassName(methodReference.getReturnType())
                                                    + (isArray ? "[]" : ""),
                                    StringUtils.join(dalvikParamTypes.toArray(), ",")).methodName,
                            newParamTypes,

                            isBasic ? returnType
                                    : DefineUtils.getDefineClassName(
                                            classProcessor.classProcess(DefineUtils.getDalvikClassName(
                                                    methodReference.getReturnType())).className,
                                            methodReference.getReturnType().startsWith("[")));
                    if (instruction instanceof Instruction3rc) {

                        reinstructions.add(new ImmutableInstruction3rc(instruction.getOpcode(),
                                ((Instruction3rc) instruction).getStartRegister(),
                                ((Instruction3rc) instruction).getRegisterCount(), immutableReference));

                    } else if (instruction instanceof Instruction20bc) {
                        reinstructions.add(new ImmutableInstruction20bc(instruction.getOpcode(),
                                ((Instruction20bc) instruction).getVerificationError(), immutableReference));

                    } else if (instruction instanceof Instruction21c) {
                        reinstructions.add(new ImmutableInstruction21c(instruction.getOpcode(),
                                ((Instruction21c) instruction).getRegisterA(), immutableReference));

                    } else if (instruction instanceof Instruction22c) {
                        reinstructions.add(new ImmutableInstruction22c(instruction.getOpcode(),
                                ((Instruction22c) instruction).getRegisterA(),
                                ((Instruction22c) instruction).getRegisterB(), immutableReference));

                    } else if (instruction instanceof Instruction31c) {
                        reinstructions.add(new ImmutableInstruction31c(instruction.getOpcode(),
                                ((Instruction31c) instruction).getRegisterA(), immutableReference));

                    } else if (instruction instanceof Instruction35c) {
                        reinstructions.add(new ImmutableInstruction35c(instruction.getOpcode(),
                                ((Instruction35c) instruction).getRegisterCount(),
                                ((Instruction35c) instruction).getRegisterC(),
                                ((Instruction35c) instruction).getRegisterD(),
                                ((Instruction35c) instruction).getRegisterE(),
                                ((Instruction35c) instruction).getRegisterF(),
                                ((Instruction35c) instruction).getRegisterG(), immutableReference));

                    }

                } catch (Exception e) {

                }
            } else if (opcode.referenceType == ReferenceType.FIELD) {
                FieldReference fieldReference = null;
                boolean isBasic = false;
                boolean isBasicArray = false;
                fieldReference = (FieldReference) ((ReferenceInstruction) instruction).getReference();
                if (fieldReference.getDefiningClass().startsWith("Ljava/lang/")
                        || fieldReference.getDefiningClass().startsWith("Ljava/util/")
                        || fieldReference.getDefiningClass().startsWith("[Ljava/lang/")) {
                    reinstructions.add(ImmutableInstruction.of(instruction));
                    continue;
                }
                if (basicType.containsKey(fieldReference.getType())) {
                    isBasic = true;
                }

                final ImmutableFieldReference immutableFieldReference = new ImmutableFieldReference(

                        DefineUtils.getDefineClassName(
                                classProcessor.classProcess(DefineUtils
                                        .getDalvikClassName(fieldReference.getDefiningClass())).className,
                                false),
                        classProcessor.filedProcess(
                                DefineUtils.getDalvikClassName(fieldReference.getDefiningClass()),
                                isBasic ? basicType.get(fieldReference.getType())
                                        : DefineUtils.getDalvikClassName(fieldReference.getType()),
                                fieldReference.getName()).fieldName,
                        isBasic ? fieldReference.getType()
                                : DefineUtils.getDefineClassName(
                                        classProcessor.classProcess(DefineUtils
                                                .getDalvikClassName(fieldReference.getType())).className,
                                        fieldReference.getType().startsWith("[")));

                if (instruction instanceof Instruction3rc) {

                    reinstructions.add(new ImmutableInstruction3rc(instruction.getOpcode(),
                            ((Instruction3rc) instruction).getStartRegister(),
                            ((Instruction3rc) instruction).getRegisterCount(), immutableFieldReference));

                } else if (instruction instanceof Instruction20bc) {
                    reinstructions.add(new ImmutableInstruction20bc(instruction.getOpcode(),
                            ((Instruction20bc) instruction).getVerificationError(), immutableFieldReference));

                } else if (instruction instanceof Instruction21c) {
                    reinstructions.add(new ImmutableInstruction21c(instruction.getOpcode(),
                            ((Instruction21c) instruction).getRegisterA(), immutableFieldReference));

                } else if (instruction instanceof Instruction22c) {
                    reinstructions.add(new ImmutableInstruction22c(instruction.getOpcode(),
                            ((Instruction22c) instruction).getRegisterA(),
                            ((Instruction22c) instruction).getRegisterB(), immutableFieldReference));

                } else if (instruction instanceof Instruction31c) {
                    reinstructions.add(new ImmutableInstruction31c(instruction.getOpcode(),
                            ((Instruction31c) instruction).getRegisterA(), immutableFieldReference));

                } else if (instruction instanceof Instruction35c) {
                    reinstructions.add(new ImmutableInstruction35c(instruction.getOpcode(),
                            ((Instruction35c) instruction).getRegisterCount(),
                            ((Instruction35c) instruction).getRegisterC(),
                            ((Instruction35c) instruction).getRegisterD(),
                            ((Instruction35c) instruction).getRegisterE(),
                            ((Instruction35c) instruction).getRegisterF(),
                            ((Instruction35c) instruction).getRegisterG(), immutableFieldReference));

                }

            } else if (opcode.referenceType == ReferenceType.TYPE) {
                TypeReference typeReference = (TypeReference) ((ReferenceInstruction) instruction)
                        .getReference();
                String type = typeReference.getType();
                if (!basicType.containsKey(type) && !type.startsWith("Ljava/lang")
                        && !type.startsWith("Ljava/util/") && !type.startsWith("[Ljava/lang")) {
                    type = DefineUtils.getDefineClassName(
                            classProcessor.classProcess(DefineUtils.getDalvikClassName(type)).className,
                            type.startsWith("["));
                }
                ImmutableTypeReference immutableTypeReference = new ImmutableTypeReference(type);
                if (instruction instanceof Instruction3rc) {

                    reinstructions.add(new ImmutableInstruction3rc(instruction.getOpcode(),
                            ((Instruction3rc) instruction).getStartRegister(),
                            ((Instruction3rc) instruction).getRegisterCount(), immutableTypeReference));

                } else if (instruction instanceof Instruction20bc) {
                    reinstructions.add(new ImmutableInstruction20bc(instruction.getOpcode(),
                            ((Instruction20bc) instruction).getVerificationError(), immutableTypeReference));

                } else if (instruction instanceof Instruction21c) {
                    reinstructions.add(new ImmutableInstruction21c(instruction.getOpcode(),
                            ((Instruction21c) instruction).getRegisterA(), immutableTypeReference));

                } else if (instruction instanceof Instruction22c) {
                    reinstructions.add(new ImmutableInstruction22c(instruction.getOpcode(),
                            ((Instruction22c) instruction).getRegisterA(),
                            ((Instruction22c) instruction).getRegisterB(), immutableTypeReference));

                } else if (instruction instanceof Instruction31c) {
                    reinstructions.add(new ImmutableInstruction31c(instruction.getOpcode(),
                            ((Instruction31c) instruction).getRegisterA(), immutableTypeReference));

                } else if (instruction instanceof Instruction35c) {
                    reinstructions.add(new ImmutableInstruction35c(instruction.getOpcode(),
                            ((Instruction35c) instruction).getRegisterCount(),
                            ((Instruction35c) instruction).getRegisterC(),
                            ((Instruction35c) instruction).getRegisterD(),
                            ((Instruction35c) instruction).getRegisterE(),
                            ((Instruction35c) instruction).getRegisterF(),
                            ((Instruction35c) instruction).getRegisterG(), immutableTypeReference));

                }

            } else if (opcode.referenceType == ReferenceType.STRING) {
                StringReference stringReference = (StringReference) ((ReferenceInstruction) instruction)
                        .getReference();
                String type = stringReference.getString();
                //                    if (!basicType.contains(type) && !type.startsWith("[Ljava/lang")) {
                //                        type = DefineUtils.getDefineClassName(classProcessor.classProcess(DefineUtils.getDalvikClassName(type)).className);
                //                    }
                ImmutableStringReference immutableStringReference = new ImmutableStringReference(type);
                if (instruction instanceof Instruction3rc) {

                    reinstructions.add(new ImmutableInstruction3rc(instruction.getOpcode(),
                            ((Instruction3rc) instruction).getStartRegister(),
                            ((Instruction3rc) instruction).getRegisterCount(), immutableStringReference));

                } else if (instruction instanceof Instruction20bc) {
                    reinstructions.add(new ImmutableInstruction20bc(instruction.getOpcode(),
                            ((Instruction20bc) instruction).getVerificationError(), immutableStringReference));

                } else if (instruction instanceof Instruction21c) {
                    reinstructions.add(new ImmutableInstruction21c(instruction.getOpcode(),
                            ((Instruction21c) instruction).getRegisterA(), immutableStringReference));

                } else if (instruction instanceof Instruction22c) {
                    reinstructions.add(new ImmutableInstruction22c(instruction.getOpcode(),
                            ((Instruction22c) instruction).getRegisterA(),
                            ((Instruction22c) instruction).getRegisterB(), immutableStringReference));

                } else if (instruction instanceof Instruction31c) {
                    reinstructions.add(new ImmutableInstruction31c(instruction.getOpcode(),
                            ((Instruction31c) instruction).getRegisterA(), immutableStringReference));

                } else if (instruction instanceof Instruction35c) {
                    reinstructions.add(new ImmutableInstruction35c(instruction.getOpcode(),
                            ((Instruction35c) instruction).getRegisterCount(),
                            ((Instruction35c) instruction).getRegisterC(),
                            ((Instruction35c) instruction).getRegisterD(),
                            ((Instruction35c) instruction).getRegisterE(),
                            ((Instruction35c) instruction).getRegisterF(),
                            ((Instruction35c) instruction).getRegisterG(), immutableStringReference));

                }

            } else {
                reinstructions.add(ImmutableInstruction.of(instruction));

            }
        } else {
            reinstructions.add(ImmutableInstruction.of(instruction));
        }
    }

    return new Iterable<Instruction>() {
        @Override
        public Iterator<Instruction> iterator() {
            return reinstructions.iterator();

        }

    };
}

From source file:cn.iie.haiep.hbase.value.Bytes.java

/**
 * Iterate over keys within the passed inclusive range.
 *//*from  w w w.  ja  v  a 2  s  .  co  m*/
public static Iterable<byte[]> iterateOnSplits(final byte[] a, final byte[] b, final int num) {
    byte[] aPadded;
    byte[] bPadded;
    if (a.length < b.length) {
        aPadded = padTail(a, b.length - a.length);
        bPadded = b;
    } else if (b.length < a.length) {
        aPadded = a;
        bPadded = padTail(b, a.length - b.length);
    } else {
        aPadded = a;
        bPadded = b;
    }
    if (compareTo(aPadded, bPadded) >= 0) {
        throw new IllegalArgumentException("b <= a");
    }
    if (num <= 0) {
        throw new IllegalArgumentException("num cannot be < 0");
    }
    byte[] prependHeader = { 1, 0 };
    final BigInteger startBI = new BigInteger(add(prependHeader, aPadded));
    final BigInteger stopBI = new BigInteger(add(prependHeader, bPadded));
    final BigInteger diffBI = stopBI.subtract(startBI);
    final BigInteger splitsBI = BigInteger.valueOf(num + 1);
    if (diffBI.compareTo(splitsBI) < 0) {
        return null;
    }
    final BigInteger intervalBI;
    try {
        intervalBI = diffBI.divide(splitsBI);
    } catch (Exception e) {
        LOG.error("Exception caught during division", e);
        return null;
    }

    final Iterator<byte[]> iterator = new Iterator<byte[]>() {
        private int i = -1;

        @Override
        public boolean hasNext() {
            return i < num + 1;
        }

        @Override
        public byte[] next() {
            i++;
            if (i == 0)
                return a;
            if (i == num + 1)
                return b;

            BigInteger curBI = startBI.add(intervalBI.multiply(BigInteger.valueOf(i)));
            byte[] padded = curBI.toByteArray();
            if (padded[1] == 0)
                padded = tail(padded, padded.length - 2);
            else
                padded = tail(padded, padded.length - 1);
            return padded;
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }

    };

    return new Iterable<byte[]>() {
        @Override
        public Iterator<byte[]> iterator() {
            return iterator;
        }
    };
}

From source file:com.taobao.android.repatch.InsTructionsReIClassDef.java

@Override
protected Iterable<? extends DebugItem> reDebugItem(Iterable<? extends DebugItem> debugItems) {
    if (debugItems == null) {
        return null;
    }//from  w  w w.  j a  v  a 2  s  . c o m
    Iterator iterator = debugItems.iterator();
    final List<DebugItem> immableDebugItems = new ArrayList<DebugItem>();
    while (iterator.hasNext()) {
        DebugItem debugItem = (DebugItem) iterator.next();
        if (debugItem instanceof ImmutableStartLocal) {
            String newType = null;
            String type = ((ImmutableStartLocal) debugItem).getType();
            if (!basicType.containsKey(type)) {
                newType = DefineUtils.getDefineClassName(
                        classProcessor.classProcess(DefineUtils.getDalvikClassName(type)).className,
                        type.startsWith("["));
            } else
                newType = type;
            immableDebugItems.add(new ImmutableStartLocal(debugItem.getCodeAddress(),
                    ((ImmutableStartLocal) debugItem).getRegister(),
                    ((ImmutableStartLocal) debugItem).getName(), newType,
                    ((ImmutableStartLocal) debugItem).getSignature()));
        } else if (debugItem instanceof ImmutableEndLocal) {
            String newType = null;
            String type = ((ImmutableEndLocal) debugItem).getType();
            if (!basicType.containsKey(type)) {
                newType = DefineUtils.getDefineClassName(
                        classProcessor.classProcess(DefineUtils.getDalvikClassName(type)).className,
                        type.startsWith("["));
            } else
                newType = type;
            immableDebugItems.add(new ImmutableEndLocal(debugItem.getCodeAddress(),
                    ((ImmutableEndLocal) debugItem).getRegister(), ((ImmutableEndLocal) debugItem).getName(),
                    newType, ((ImmutableEndLocal) debugItem).getSignature()));

        } else if (debugItem instanceof ImmutableRestartLocal) {
            String newType = null;
            String type = ((ImmutableRestartLocal) debugItem).getType();
            if (!basicType.containsKey(type)) {
                newType = DefineUtils.getDefineClassName(
                        classProcessor.classProcess(DefineUtils.getDalvikClassName(type)).className,
                        type.startsWith("["));
            } else
                newType = type;
            immableDebugItems.add(new ImmutableRestartLocal(debugItem.getCodeAddress(),
                    ((ImmutableRestartLocal) debugItem).getRegister(),
                    ((ImmutableRestartLocal) debugItem).getName(), newType,
                    ((ImmutableRestartLocal) debugItem).getSignature()));

        } else
            immableDebugItems.add(debugItem);

    }

    return new Iterable<DebugItem>() {
        @Override
        public Iterator<DebugItem> iterator() {
            return immableDebugItems.iterator();
        }
    };
}

From source file:com.ery.ertc.estorm.util.Bytes.java

/**
 * Iterate over keys within the passed range.
 *//*from  w w  w  . j av  a  2s  .  com*/
public static Iterable<byte[]> iterateOnSplits(final byte[] a, final byte[] b, boolean inclusive,
        final int num) {
    byte[] aPadded;
    byte[] bPadded;
    if (a.length < b.length) {
        aPadded = padTail(a, b.length - a.length);
        bPadded = b;
    } else if (b.length < a.length) {
        aPadded = a;
        bPadded = padTail(b, a.length - b.length);
    } else {
        aPadded = a;
        bPadded = b;
    }
    if (compareTo(aPadded, bPadded) >= 0) {
        throw new IllegalArgumentException("b <= a");
    }
    if (num <= 0) {
        throw new IllegalArgumentException("num cannot be < 0");
    }
    byte[] prependHeader = { 1, 0 };
    final BigInteger startBI = new BigInteger(add(prependHeader, aPadded));
    final BigInteger stopBI = new BigInteger(add(prependHeader, bPadded));
    BigInteger diffBI = stopBI.subtract(startBI);
    if (inclusive) {
        diffBI = diffBI.add(BigInteger.ONE);
    }
    final BigInteger splitsBI = BigInteger.valueOf(num + 1);
    if (diffBI.compareTo(splitsBI) < 0) {
        return null;
    }
    final BigInteger intervalBI;
    try {
        intervalBI = diffBI.divide(splitsBI);
    } catch (Exception e) {
        LOG.error("Exception caught during division", e);
        return null;
    }

    final Iterator<byte[]> iterator = new Iterator<byte[]>() {
        private int i = -1;

        @Override
        public boolean hasNext() {
            return i < num + 1;
        }

        @Override
        public byte[] next() {
            i++;
            if (i == 0)
                return a;
            if (i == num + 1)
                return b;

            BigInteger curBI = startBI.add(intervalBI.multiply(BigInteger.valueOf(i)));
            byte[] padded = curBI.toByteArray();
            if (padded[1] == 0)
                padded = tail(padded, padded.length - 2);
            else
                padded = tail(padded, padded.length - 1);
            return padded;
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }

    };

    return new Iterable<byte[]>() {
        @Override
        public Iterator<byte[]> iterator() {
            return iterator;
        }
    };
}

From source file:org.apache.hadoop.hbase.util.Bytes.java

/**
 * Iterate over keys within the passed range.
 *//* w w w  . ja  v a2  s .  co  m*/
public static Iterable<byte[]> iterateOnSplits(final byte[] a, final byte[] b, boolean inclusive,
        final int num) {
    byte[] aPadded;
    byte[] bPadded;
    if (a.length < b.length) {
        aPadded = padTail(a, b.length - a.length);
        bPadded = b;
    } else if (b.length < a.length) {
        aPadded = a;
        bPadded = padTail(b, a.length - b.length);
    } else {
        aPadded = a;
        bPadded = b;
    }
    if (compareTo(aPadded, bPadded) >= 0) {
        throw new IllegalArgumentException("b <= a");
    }
    if (num <= 0) {
        throw new IllegalArgumentException("num cannot be <= 0");
    }
    byte[] prependHeader = { 1, 0 };
    final BigInteger startBI = new BigInteger(add(prependHeader, aPadded));
    final BigInteger stopBI = new BigInteger(add(prependHeader, bPadded));
    BigInteger diffBI = stopBI.subtract(startBI);
    if (inclusive) {
        diffBI = diffBI.add(BigInteger.ONE);
    }
    final BigInteger splitsBI = BigInteger.valueOf(num + 1);
    if (diffBI.compareTo(splitsBI) < 0) {
        return null;
    }
    final BigInteger intervalBI;
    try {
        intervalBI = diffBI.divide(splitsBI);
    } catch (Exception e) {
        LOG.error("Exception caught during division", e);
        return null;
    }

    final Iterator<byte[]> iterator = new Iterator<byte[]>() {
        private int i = -1;

        @Override
        public boolean hasNext() {
            return i < num + 1;
        }

        @Override
        public byte[] next() {
            i++;
            if (i == 0)
                return a;
            if (i == num + 1)
                return b;

            BigInteger curBI = startBI.add(intervalBI.multiply(BigInteger.valueOf(i)));
            byte[] padded = curBI.toByteArray();
            if (padded[1] == 0)
                padded = tail(padded, padded.length - 2);
            else
                padded = tail(padded, padded.length - 1);
            return padded;
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }

    };

    return new Iterable<byte[]>() {
        @Override
        public Iterator<byte[]> iterator() {
            return iterator;
        }
    };
}

From source file:org.apache.kylin.common.util.Bytes.java

/**
 * Iterate over keys within the passed range.
 *///ww  w.  ja  v a  2s  . c o m
public static Iterable<byte[]> iterateOnSplits(final byte[] a, final byte[] b, boolean inclusive,
        final int num) {
    byte[] aPadded;
    byte[] bPadded;
    if (a.length < b.length) {
        aPadded = padTail(a, b.length - a.length);
        bPadded = b;
    } else if (b.length < a.length) {
        aPadded = a;
        bPadded = padTail(b, a.length - b.length);
    } else {
        aPadded = a;
        bPadded = b;
    }
    if (compareTo(aPadded, bPadded) >= 0) {
        throw new IllegalArgumentException("b <= a");
    }
    if (num <= 0) {
        throw new IllegalArgumentException("num cannot be <= 0");
    }
    byte[] prependHeader = { 1, 0 };
    final BigInteger startBI = new BigInteger(add(prependHeader, aPadded));
    final BigInteger stopBI = new BigInteger(add(prependHeader, bPadded));
    BigInteger diffBI = stopBI.subtract(startBI);
    if (inclusive) {
        diffBI = diffBI.add(BigInteger.ONE);
    }
    final BigInteger splitsBI = BigInteger.valueOf(num + 1L);
    if (diffBI.compareTo(splitsBI) < 0) {
        return null;
    }
    final BigInteger intervalBI;
    try {
        intervalBI = diffBI.divide(splitsBI);
    } catch (Exception e) {
        LOG.error("Exception caught during division", e);
        return null;
    }

    final Iterator<byte[]> iterator = new Iterator<byte[]>() {
        private int i = -1;

        @Override
        public boolean hasNext() {
            return i < num + 1;
        }

        @Override
        public byte[] next() {
            i++;
            if (i == 0)
                return a;
            if (i == num + 1)
                return b;

            BigInteger curBI = startBI.add(intervalBI.multiply(BigInteger.valueOf(i)));
            byte[] padded = curBI.toByteArray();
            if (padded[1] == 0)
                padded = tail(padded, padded.length - 2);
            else
                padded = tail(padded, padded.length - 1);
            return padded;
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }

    };

    return new Iterable<byte[]>() {
        @Override
        public Iterator<byte[]> iterator() {
            return iterator;
        }
    };
}

From source file:mondrian.olap.Util.java

/**
 * Applies a collection of filters to an iterable.
 *
 * @param iterable Iterable/* w ww.ja va2  s  .  co m*/
 * @param conds Zero or more conditions
 * @param <T>
 * @return Iterable that returns only members of underlying iterable for
 *     for which all conditions evaluate to true
 */
public static <T> Iterable<T> filter(final Iterable<T> iterable, final Functor1<Boolean, T>... conds) {
    final Functor1<Boolean, T>[] conds2 = optimizeConditions(conds);
    if (conds2.length == 0) {
        return iterable;
    }
    return new Iterable<T>() {
        public Iterator<T> iterator() {
            return new Iterator<T>() {
                final Iterator<T> iterator = iterable.iterator();
                T next;
                boolean hasNext = moveToNext();

                private boolean moveToNext() {
                    outer: while (iterator.hasNext()) {
                        next = iterator.next();
                        for (Functor1<Boolean, T> cond : conds2) {
                            if (!cond.apply(next)) {
                                continue outer;
                            }
                        }
                        return true;
                    }
                    return false;
                }

                public boolean hasNext() {
                    return hasNext;
                }

                public T next() {
                    T t = next;
                    hasNext = moveToNext();
                    return t;
                }

                public void remove() {
                    throw new UnsupportedOperationException();
                }
            };
        }
    };
}

From source file:org.wso2.carbon.registry.app.RegistryAdapter.java

/**
 * Method to get an iterator of entries.
 *
 * @param request the request context.// w w w .j a v  a2  s.  c om
 *
 * @return an iterator of resources.
 * @throws ResponseContextException if the operation failed.
 */
public Iterable<Resource> getEntries(final RequestContext request) throws ResponseContextException {
    Resource resource = ((ResourceTarget) request.getTarget()).getResource();

    final String[] splitPath = (String[]) request.getAttribute(RequestContext.Scope.REQUEST,
            APPConstants.PARAMETER_SPLIT_PATH);
    if (splitPath != null && APPConstants.PARAMETER_COMMENTS.equals(splitPath[1])) {
        // Looking for comments, not the resource itself
        try {
            resource = getSecureRegistry(request).get(
                    resource.getPath() + RegistryConstants.URL_SEPARATOR + APPConstants.PARAMETER_COMMENTS);
        } catch (RegistryException e) {
            throw new ResponseContextException(new StackTraceResponseContext(e));
        }

    }

    if (resource instanceof Collection) {
        final Resource r = resource;
        return new Iterable<Resource>() {
            public Iterator<Resource> iterator() {
                try {
                    return new ResourceIterator((Object[]) r.getContent(), getSecureRegistry(request));
                } catch (RegistryException e) {
                    return null;
                }
            }
        };
    }

    return null;
}

From source file:com.oltpbenchmark.benchmarks.seats.SEATSLoader.java

public Iterable<FlightId> getFlightIds() {
    return (new Iterable<FlightId>() {
        @Override/*from  w ww .  j a v  a  2 s . c om*/
        public Iterator<FlightId> iterator() {
            return (new Iterator<FlightId>() {
                private int idx = 0;
                private final int cnt = seats_remaining.size();

                @Override
                public boolean hasNext() {
                    return (idx < this.cnt);
                }

                @Override
                public FlightId next() {
                    return (seats_remaining.get(this.idx++));
                }

                @Override
                public void remove() {
                    // Not implemented
                }
            });
        }
    });
}

From source file:io.minio.MinioClient.java

/**
 * Lists object information as {@code Iterable<Result><Item>>} in given bucket, prefix and recursive flag.
 *
 * </p><b>Example:</b><br>
 * <pre>{@code Iterable<Result<Item>> myObjects = minioClient.listObjects("my-bucketname");
 * for (Result<Item> result : myObjects) {
 *   Item item = result.get();//from   w  ww. ja va 2  s  .  c om
 *   System.out.println(item.lastModified() + ", " + item.size() + ", " + item.objectName());
 * } }</pre>
 *
 * @param bucketName Bucket name.
 * @param prefix     Prefix string.  List objects whose name starts with `prefix`.
 * @param recursive when false, emulates a directory structure where each listing returned is either a full object
 *                  or part of the object's key up to the first '/'. All objects wit the same prefix up to the first
 *                  '/' will be merged into one entry.
 *
 * @return an iterator of Result Items.
 *
 * @see #listObjects(String bucketName)
 * @see #listObjects(String bucketName, String prefix)
 */
public Iterable<Result<Item>> listObjects(final String bucketName, final String prefix,
        final boolean recursive) {
    return new Iterable<Result<Item>>() {
        @Override
        public Iterator<Result<Item>> iterator() {
            return new Iterator<Result<Item>>() {
                private String lastObjectName;
                private ListBucketResult listBucketResult;
                private Result<Item> error;
                private Iterator<Item> itemIterator;
                private Iterator<Prefix> prefixIterator;
                private boolean completed = false;

                private synchronized void populate() {
                    String delimiter = "/";
                    if (recursive) {
                        delimiter = null;
                    }

                    String marker = null;
                    if (this.listBucketResult != null) {
                        if (delimiter != null) {
                            marker = listBucketResult.nextMarker();
                        } else {
                            marker = this.lastObjectName;
                        }
                    }

                    this.listBucketResult = null;
                    this.itemIterator = null;
                    this.prefixIterator = null;

                    try {
                        this.listBucketResult = listObjects(bucketName, marker, prefix, delimiter, null);
                    } catch (InvalidBucketNameException | NoSuchAlgorithmException | InsufficientDataException
                            | IOException | InvalidKeyException | NoResponseException | XmlPullParserException
                            | ErrorResponseException | InternalException e) {
                        this.error = new Result<>(null, e);
                    } finally {
                        if (this.listBucketResult != null) {
                            this.itemIterator = this.listBucketResult.contents().iterator();
                            this.prefixIterator = this.listBucketResult.commonPrefixes().iterator();
                        } else {
                            this.itemIterator = new LinkedList<Item>().iterator();
                            this.prefixIterator = new LinkedList<Prefix>().iterator();
                        }
                    }
                }

                @Override
                public boolean hasNext() {
                    if (this.completed) {
                        return false;
                    }

                    if (this.error == null && this.itemIterator == null && this.prefixIterator == null) {
                        populate();
                    }

                    if (this.error == null && !this.itemIterator.hasNext() && !this.prefixIterator.hasNext()
                            && this.listBucketResult.isTruncated()) {
                        populate();
                    }

                    if (this.error != null) {
                        return true;
                    }

                    if (this.itemIterator.hasNext()) {
                        return true;
                    }

                    if (this.prefixIterator.hasNext()) {
                        return true;
                    }

                    this.completed = true;
                    return false;
                }

                @Override
                public Result<Item> next() {
                    if (this.completed) {
                        throw new NoSuchElementException();
                    }

                    if (this.error == null && this.itemIterator == null && this.prefixIterator == null) {
                        populate();
                    }

                    if (this.error == null && !this.itemIterator.hasNext() && !this.prefixIterator.hasNext()
                            && this.listBucketResult.isTruncated()) {
                        populate();
                    }

                    if (this.error != null) {
                        this.completed = true;
                        return this.error;
                    }

                    if (this.itemIterator.hasNext()) {
                        Item item = this.itemIterator.next();
                        this.lastObjectName = item.objectName();
                        return new Result<>(item, null);
                    }

                    if (this.prefixIterator.hasNext()) {
                        Prefix prefix = this.prefixIterator.next();
                        Item item;
                        try {
                            item = new Item(prefix.prefix(), true);
                        } catch (XmlPullParserException e) {
                            // special case: ignore the error as we can't propagate the exception in next()
                            item = null;
                        }

                        return new Result<>(item, null);
                    }

                    this.completed = true;
                    throw new NoSuchElementException();
                }

                @Override
                public void remove() {
                    throw new UnsupportedOperationException();
                }
            };
        }
    };
}