Example usage for com.google.common.collect Iterators forArray

List of usage examples for com.google.common.collect Iterators forArray

Introduction

In this page you can find the example usage for com.google.common.collect Iterators forArray.

Prototype

public static <T> UnmodifiableIterator<T> forArray(final T... array) 

Source Link

Document

Returns an iterator containing the elements of array in order.

Usage

From source file:org.pshdl.model.impl.AbstractHDLTernary.java

@Override
public Iterator<IHDLObject> deepIterator() {
    return new Iterator<IHDLObject>() {

        private int pos = 0;
        private Iterator<? extends IHDLObject> current;

        @Override// w w w .  j  av  a2 s  .  co m
        public boolean hasNext() {
            if ((current != null) && !current.hasNext()) {
                current = null;
            }
            while (current == null) {
                switch (pos++) {
                case 0:
                    if (ifExpr != null) {
                        current = Iterators.concat(Iterators.forArray(ifExpr), ifExpr.deepIterator());
                    }
                    break;
                case 1:
                    if (thenExpr != null) {
                        current = Iterators.concat(Iterators.forArray(thenExpr), thenExpr.deepIterator());
                    }
                    break;
                case 2:
                    if (elseExpr != null) {
                        current = Iterators.concat(Iterators.forArray(elseExpr), elseExpr.deepIterator());
                    }
                    break;
                default:
                    return false;
                }
            }
            return (current != null) && current.hasNext();
        }

        @Override
        public IHDLObject next() {
            return current.next();
        }

        @Override
        public void remove() {
            throw new IllegalArgumentException("Not supported");
        }

    };
}

From source file:org.pshdl.model.impl.AbstractHDLEnumDeclaration.java

@Override
public Iterator<IHDLObject> deepIterator() {
    return new Iterator<IHDLObject>() {

        private int pos = 0;
        private Iterator<? extends IHDLObject> current;

        @Override/*from  w  w w . ja v a 2s  .  co m*/
        public boolean hasNext() {
            if ((current != null) && !current.hasNext()) {
                current = null;
            }
            while (current == null) {
                switch (pos++) {
                case 0:
                    if ((annotations != null) && (annotations.size() != 0)) {
                        final List<Iterator<? extends IHDLObject>> iters = Lists
                                .newArrayListWithCapacity(annotations.size());
                        for (final HDLAnnotation o : annotations) {
                            iters.add(Iterators.forArray(o));
                            iters.add(o.deepIterator());
                        }
                        current = Iterators.concat(iters.iterator());
                    }
                    break;
                case 1:
                    if (hEnum != null) {
                        current = Iterators.concat(Iterators.forArray(hEnum), hEnum.deepIterator());
                    }
                    break;
                default:
                    return false;
                }
            }
            return (current != null) && current.hasNext();
        }

        @Override
        public IHDLObject next() {
            return current.next();
        }

        @Override
        public void remove() {
            throw new IllegalArgumentException("Not supported");
        }

    };
}

From source file:org.pshdl.model.impl.AbstractHDLInterfaceDeclaration.java

@Override
public Iterator<IHDLObject> deepIterator() {
    return new Iterator<IHDLObject>() {

        private int pos = 0;
        private Iterator<? extends IHDLObject> current;

        @Override// w w  w.  ja  va 2 s  .  c om
        public boolean hasNext() {
            if ((current != null) && !current.hasNext()) {
                current = null;
            }
            while (current == null) {
                switch (pos++) {
                case 0:
                    if ((annotations != null) && (annotations.size() != 0)) {
                        final List<Iterator<? extends IHDLObject>> iters = Lists
                                .newArrayListWithCapacity(annotations.size());
                        for (final HDLAnnotation o : annotations) {
                            iters.add(Iterators.forArray(o));
                            iters.add(o.deepIterator());
                        }
                        current = Iterators.concat(iters.iterator());
                    }
                    break;
                case 1:
                    if (hIf != null) {
                        current = Iterators.concat(Iterators.forArray(hIf), hIf.deepIterator());
                    }
                    break;
                default:
                    return false;
                }
            }
            return (current != null) && current.hasNext();
        }

        @Override
        public IHDLObject next() {
            return current.next();
        }

        @Override
        public void remove() {
            throw new IllegalArgumentException("Not supported");
        }

    };
}

From source file:org.pshdl.model.impl.AbstractHDLSwitchCaseStatement.java

@Override
public Iterator<IHDLObject> deepIterator() {
    return new Iterator<IHDLObject>() {

        private int pos = 0;
        private Iterator<? extends IHDLObject> current;

        @Override/*from w  ww.j  a  va 2s .  co  m*/
        public boolean hasNext() {
            if ((current != null) && !current.hasNext()) {
                current = null;
            }
            while (current == null) {
                switch (pos++) {
                case 0:
                    if (label != null) {
                        current = Iterators.concat(Iterators.forArray(label), label.deepIterator());
                    }
                    break;
                case 1:
                    if ((dos != null) && (dos.size() != 0)) {
                        final List<Iterator<? extends IHDLObject>> iters = Lists
                                .newArrayListWithCapacity(dos.size());
                        for (final HDLStatement o : dos) {
                            iters.add(Iterators.forArray(o));
                            iters.add(o.deepIterator());
                        }
                        current = Iterators.concat(iters.iterator());
                    }
                    break;
                default:
                    return false;
                }
            }
            return (current != null) && current.hasNext();
        }

        @Override
        public IHDLObject next() {
            return current.next();
        }

        @Override
        public void remove() {
            throw new IllegalArgumentException("Not supported");
        }

    };
}

From source file:org.pshdl.model.impl.AbstractHDLRange.java

@Override
public Iterator<IHDLObject> deepIterator() {
    return new Iterator<IHDLObject>() {

        private int pos = 0;
        private Iterator<? extends IHDLObject> current;

        @Override//from  www.j a va 2s  .co  m
        public boolean hasNext() {
            if ((current != null) && !current.hasNext()) {
                current = null;
            }
            while (current == null) {
                switch (pos++) {
                case 0:
                    if (from != null) {
                        current = Iterators.concat(Iterators.forArray(from), from.deepIterator());
                    }
                    break;
                case 1:
                    if (inc != null) {
                        current = Iterators.concat(Iterators.forArray(inc), inc.deepIterator());
                    }
                    break;
                case 2:
                    if (dec != null) {
                        current = Iterators.concat(Iterators.forArray(dec), dec.deepIterator());
                    }
                    break;
                case 3:
                    if (to != null) {
                        current = Iterators.concat(Iterators.forArray(to), to.deepIterator());
                    }
                    break;
                default:
                    return false;
                }
            }
            return (current != null) && current.hasNext();
        }

        @Override
        public IHDLObject next() {
            return current.next();
        }

        @Override
        public void remove() {
            throw new IllegalArgumentException("Not supported");
        }

    };
}

From source file:org.pshdl.model.impl.AbstractHDLSwitchStatement.java

@Override
public Iterator<IHDLObject> deepIterator() {
    return new Iterator<IHDLObject>() {

        private int pos = 0;
        private Iterator<? extends IHDLObject> current;

        @Override//from   w  w  w. jav  a2 s. c  o m
        public boolean hasNext() {
            if ((current != null) && !current.hasNext()) {
                current = null;
            }
            while (current == null) {
                switch (pos++) {
                case 0:
                    if (caseExp != null) {
                        current = Iterators.concat(Iterators.forArray(caseExp), caseExp.deepIterator());
                    }
                    break;
                case 1:
                    if ((cases != null) && (cases.size() != 0)) {
                        final List<Iterator<? extends IHDLObject>> iters = Lists
                                .newArrayListWithCapacity(cases.size());
                        for (final HDLSwitchCaseStatement o : cases) {
                            iters.add(Iterators.forArray(o));
                            iters.add(o.deepIterator());
                        }
                        current = Iterators.concat(iters.iterator());
                    }
                    break;
                default:
                    return false;
                }
            }
            return (current != null) && current.hasNext();
        }

        @Override
        public IHDLObject next() {
            return current.next();
        }

        @Override
        public void remove() {
            throw new IllegalArgumentException("Not supported");
        }

    };
}

From source file:org.pshdl.model.impl.AbstractHDLBlock.java

@Override
public Iterator<IHDLObject> deepIterator() {
    return new Iterator<IHDLObject>() {

        private int pos = 0;
        private Iterator<? extends IHDLObject> current;

        @Override//from ww w .  j a v  a 2  s  .  c  om
        public boolean hasNext() {
            if ((current != null) && !current.hasNext()) {
                current = null;
            }
            while (current == null) {
                switch (pos++) {
                case 0:
                    if ((statements != null) && (statements.size() != 0)) {
                        final List<Iterator<? extends IHDLObject>> iters = Lists
                                .newArrayListWithCapacity(statements.size());
                        for (final HDLStatement o : statements) {
                            iters.add(Iterators.forArray(o));
                            iters.add(o.deepIterator());
                        }
                        current = Iterators.concat(iters.iterator());
                    }
                    break;
                default:
                    return false;
                }
            }
            return (current != null) && current.hasNext();
        }

        @Override
        public IHDLObject next() {
            return current.next();
        }

        @Override
        public void remove() {
            throw new IllegalArgumentException("Not supported");
        }

    };
}

From source file:org.pshdl.model.impl.AbstractHDLFunctionCall.java

@Override
public Iterator<IHDLObject> deepIterator() {
    return new Iterator<IHDLObject>() {

        private int pos = 0;
        private Iterator<? extends IHDLObject> current;

        @Override/*from  ww w . ja  va 2  s .  c  om*/
        public boolean hasNext() {
            if ((current != null) && !current.hasNext()) {
                current = null;
            }
            while (current == null) {
                switch (pos++) {
                case 0:
                    if ((params != null) && (params.size() != 0)) {
                        final List<Iterator<? extends IHDLObject>> iters = Lists
                                .newArrayListWithCapacity(params.size());
                        for (final HDLExpression o : params) {
                            iters.add(Iterators.forArray(o));
                            iters.add(o.deepIterator());
                        }
                        current = Iterators.concat(iters.iterator());
                    }
                    break;
                default:
                    return false;
                }
            }
            return (current != null) && current.hasNext();
        }

        @Override
        public IHDLObject next() {
            return current.next();
        }

        @Override
        public void remove() {
            throw new IllegalArgumentException("Not supported");
        }

    };
}

From source file:org.pshdl.model.impl.AbstractHDLPrimitive.java

@Override
public Iterator<IHDLObject> deepIterator() {
    return new Iterator<IHDLObject>() {

        private int pos = 0;
        private Iterator<? extends IHDLObject> current;

        @Override//www .  j  a va  2s.  co m
        public boolean hasNext() {
            if ((current != null) && !current.hasNext()) {
                current = null;
            }
            while (current == null) {
                switch (pos++) {
                case 0:
                    if ((dim != null) && (dim.size() != 0)) {
                        final List<Iterator<? extends IHDLObject>> iters = Lists
                                .newArrayListWithCapacity(dim.size());
                        for (final HDLExpression o : dim) {
                            iters.add(Iterators.forArray(o));
                            iters.add(o.deepIterator());
                        }
                        current = Iterators.concat(iters.iterator());
                    }
                    break;
                case 1:
                    if (width != null) {
                        current = Iterators.concat(Iterators.forArray(width), width.deepIterator());
                    }
                    break;
                default:
                    return false;
                }
            }
            return (current != null) && current.hasNext();
        }

        @Override
        public IHDLObject next() {
            return current.next();
        }

        @Override
        public void remove() {
            throw new IllegalArgumentException("Not supported");
        }

    };
}

From source file:com.github.rinde.rinsim.scenario.gendreau06.Gendreau06Parser.java

static ImmutableList<AddParcelEvent> parseParcels(InputStream inputStream, boolean online) {
    final ImmutableList.Builder<AddParcelEvent> listBuilder = ImmutableList.builder();
    final BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, Charsets.UTF_8));
    String line;/*w  w w.  j ava 2s .c o  m*/
    try {
        while ((line = reader.readLine()) != null) {
            final Iterator<String> parts = Iterators.forArray(line.split(" "));
            final long requestArrivalTime = DoubleMath
                    .roundToLong(Double.parseDouble(parts.next()) * TIME_MULTIPLIER, RoundingMode.HALF_EVEN);
            // currently filtering out first and last lines of file. Is this ok?
            if (requestArrivalTime >= 0) {
                final long pickupServiceTime = Long.parseLong(parts.next()) * TIME_MULTIPLIER_INTEGER;
                final double pickupX = Double.parseDouble(parts.next());
                final double pickupY = Double.parseDouble(parts.next());
                final long pickupTimeWindowBegin = DoubleMath.roundToLong(
                        Double.parseDouble(parts.next()) * TIME_MULTIPLIER, RoundingMode.HALF_EVEN);
                final long pickupTimeWindowEnd = DoubleMath.roundToLong(
                        Double.parseDouble(parts.next()) * TIME_MULTIPLIER, RoundingMode.HALF_EVEN);
                final long deliveryServiceTime = Long.parseLong(parts.next()) * TIME_MULTIPLIER_INTEGER;
                final double deliveryX = Double.parseDouble(parts.next());
                final double deliveryY = Double.parseDouble(parts.next());
                final long deliveryTimeWindowBegin = DoubleMath.roundToLong(
                        Double.parseDouble(parts.next()) * TIME_MULTIPLIER, RoundingMode.HALF_EVEN);
                final long deliveryTimeWindowEnd = DoubleMath.roundToLong(
                        Double.parseDouble(parts.next()) * TIME_MULTIPLIER, RoundingMode.HALF_EVEN);

                // when an offline scenario is desired, all times are set to -1
                final long arrTime = online ? requestArrivalTime : -1;

                final ParcelDTO dto = Parcel
                        .builder(new Point(pickupX, pickupY), new Point(deliveryX, deliveryY))
                        .pickupTimeWindow(TimeWindow.create(pickupTimeWindowBegin, pickupTimeWindowEnd))
                        .deliveryTimeWindow(TimeWindow.create(deliveryTimeWindowBegin, deliveryTimeWindowEnd))
                        .neededCapacity(PARCEL_MAGNITUDE).orderAnnounceTime(arrTime)
                        .pickupDuration(pickupServiceTime).deliveryDuration(deliveryServiceTime).buildDTO();
                listBuilder.add(AddParcelEvent.create(dto));
            }
        }
        reader.close();
    } catch (final IOException e) {
        throw new IllegalArgumentException(e);
    }
    return listBuilder.build();
}