Example usage for com.google.common.collect Iterables getLast

List of usage examples for com.google.common.collect Iterables getLast

Introduction

In this page you can find the example usage for com.google.common.collect Iterables getLast.

Prototype

public static <T> T getLast(Iterable<T> iterable) 

Source Link

Document

Returns the last element of iterable .

Usage

From source file:org.opendaylight.controller.cluster.datastore.utils.InMemorySnapshotStore.java

@Override
public Future<Option<SelectedSnapshot>> doLoadAsync(String s,
        SnapshotSelectionCriteria snapshotSelectionCriteria) {
    List<StoredSnapshot> snapshotList = snapshots.get(s);
    if (snapshotList == null) {
        return Futures.successful(Option.<SelectedSnapshot>none());
    }//  w ww. j a va 2  s .  c o m

    StoredSnapshot snapshot = Iterables.getLast(snapshotList);
    SelectedSnapshot selectedSnapshot = new SelectedSnapshot(snapshot.getMetadata(), snapshot.getData());
    return Futures.successful(Option.some(selectedSnapshot));
}

From source file:org.sonar.flex.checks.NonEmptyCaseWithoutBreakCheck.java

@Override
public void visitNode(AstNode astNode) {
    AstNode lastAstNode = astNode.getLastChild();
    if (lastAstNode.getFirstChild().is(FlexGrammar.STATEMENT) && lastAstNode.getFirstChild().getFirstChild()
            .isNot(FlexGrammar.BREAK_STATEMENT, FlexGrammar.RETURN_STATEMENT, FlexGrammar.THROW_STATEMENT)) {
        getContext().createLineViolation(this,
                "Last statement in this switch-clause should be an unconditional break.",
                Iterables.getLast(astNode.getChildren(FlexGrammar.CASE_LABEL)));
    }/*from w ww. ja  va2s .c  om*/
}

From source file:de.lgblaumeiser.ptm.analysis.analyzer.HourComputer.java

@Override
public Collection<Collection<Object>> analyze(final Collection<String> parameter) {
    YearMonth requestedMonth = YearMonth.now();
    if (parameter.size() > 0) {
        requestedMonth = YearMonth.parse(Iterables.get(parameter, 0));
    }//w w w  .  j  ava 2  s . co  m
    Collection<Collection<Object>> result = Lists.newArrayList();
    result.add(Arrays.asList("Work Day", "Starttime", "Endtime", "Presence", "Worktime", "Breaktime",
            "Overtime", "Comment"));
    Duration overtime = Duration.ZERO;
    LocalDate currentday = requestedMonth.atDay(1);
    while (!currentday.isAfter(requestedMonth.atEndOfMonth())) {
        Collection<Booking> currentBookings = getBookingsForDay(currentday);
        if (hasCompleteBookings(currentBookings)) {
            String day = currentday.format(DateTimeFormatter.ISO_LOCAL_DATE);
            LocalTime starttime = Iterables.getFirst(currentBookings, null).getStarttime();
            LocalTime endtime = Iterables.getLast(currentBookings).getEndtime();
            Duration presence = calculatePresence(starttime, endtime);
            Duration worktime = calculateWorktime(currentBookings);
            Duration breaktime = calculateBreaktime(presence, worktime);
            Duration currentOvertime = calculateOvertime(worktime, currentday);
            overtime = overtime.plus(currentOvertime);
            result.add(Arrays.asList(day, starttime.format(DateTimeFormatter.ofPattern("HH:mm")),
                    endtime.format(DateTimeFormatter.ofPattern("HH:mm")), formatDuration(presence),
                    formatDuration(worktime), formatDuration(breaktime), formatDuration(overtime),
                    validate(worktime, breaktime)));
        }
        currentday = currentday.plusDays(1);
    }
    return result;
}

From source file:org.b1.pack.cli.FsFolderContent.java

private void addFile(List<String> path, File file) throws IOException {
    if (path.isEmpty()) {
        addChildren(builderMap.get(Collections.<String>emptyList()), file);
    } else {/*www  .  j av  a  2 s  .c o  m*/
        PackEntry entry = new FsPackEntry(Iterables.getLast(path), file.lastModified());
        if (file.isFile()) {
            getParentBuilder(path).addFile(entry, file.length()).setContent(new FsFileContent(file));
        } else {
            addChildren(getParentBuilder(path).addFolder(entry), file);
        }
    }
}

From source file:org.richfaces.services.ServiceLoader.java

public static <S> S loadService(Class<S> serviceClass, Class<? extends S> defaultImplementation) {
    Collection<Class<? extends S>> serviceClasses = loadServiceClasses(serviceClass);
    try {/*w  w  w  .  ja va2  s . c om*/
        return createInstance(Iterables.getLast(serviceClasses));
    } catch (NoSuchElementException e) {
        return createInstance(defaultImplementation);
    }
}

From source file:de.uniulm.omi.cloudiator.sword.util.LocationHierarchy.java

/**
 * Returns the topmost location of the hierarchy.
 *
 * @return the topmost location of the hierarchy
 *///from w  w w  . j a v a 2 s  .  c o m
public Location topmostLocation() {
    return Iterables.getLast(this);
}

From source file:jflowmap.views.flowmap.LegendValuesGenerator.java

private static List<Double> genPositive(double min, double max, int numValues) {
    List<Double> legendValues = Lists.newArrayList();
    double ord = AxisMarks.ordAlpha(max);
    double w = Math.floor(max / ord) * ord;
    for (int i = 0; i < numValues / 2; i++) {
        if (w < min) {
            break;
        }//from  w  w  w. j av a 2  s.c o  m
        legendValues.add(w);
        if (i == 0) {
            double nw = AxisMarks.ordAlpha(w);
            if (w != 0 && (w - nw) / w < 0.2) {
                w /= 2;
            } else {
                w = nw;
            }
        } else {
            w /= 2;
        }
    }

    if (w > min) {
        w = AxisMarks.ordAlpha(w);
        for (int i = 0; i < numValues / 2; i++) {
            if (w < min) {
                break;
            }
            legendValues.add(w);
            w /= 10;
        }
    }

    if (legendValues.size() == 0 || Iterables.getLast(legendValues) > min) {
        legendValues.add(min);
    }
    return legendValues;
}

From source file:org.apache.metron.test.spouts.GenericInternalTestSpout.java

public GenericInternalTestSpout withFilename(String filename) {
    if (filename != null && filename.length() > 0 && filename.charAt(0) == '$') {
        filename = Iterables.getLast(Splitter.on("}").split(filename));
    }// www  . jav  a 2s . c om
    _filename = filename;
    return this;
}

From source file:org.apache.metron.common.csv.CSVConverter.java

public static Map.Entry<String, Integer> getColumnMapEntry(String column, int i) {
    if (column.contains(":")) {
        Iterable<String> tokens = Splitter.on(':').split(column);
        String col = Iterables.getFirst(tokens, null);
        Integer pos = Integer.parseInt(Iterables.getLast(tokens));
        return new AbstractMap.SimpleEntry<>(col, pos);
    } else {// w  w  w.j  ava  2s. c  om
        return new AbstractMap.SimpleEntry<>(column, i);
    }

}

From source file:com.google.security.zynamics.reil.translators.BasicBlockGenerator.java

public BasicBlockGenerator(final Collection<List<ReilInstruction>> instructionList,
        final Collection<IAddress> nativeJumpTargets) {
    for (final List<ReilInstruction> instructions : instructionList) {
        final HashSet<IAddress> jumpTargets = fillJumpTargets(instructions);
        jumpTargets.addAll(nativeJumpTargets);

        final ReilInstruction lastInstruction = Iterables.getLast(instructions);

        for (final ReilInstruction reilInstruction : instructions) {
            addInstruction(reilInstruction, jumpTargets, lastInstruction);
        }/*from w ww  .j  a v a2  s  .  c o  m*/

        if (currentBlock.size() != 0) {
            final ReilBlock reilBlock = new ReilBlock(currentBlock);

            blocks.add(reilBlock);

            currentBlock = new ArrayList<ReilInstruction>();
        }
    }
}