List of usage examples for com.google.common.collect Iterables getFirst
@Nullable public static <T> T getFirst(Iterable<? extends T> iterable, @Nullable T defaultValue)
From source file:com.google.gerrit.server.config.PluginConfig.java
PluginConfig withInheritance(ProjectState.Factory projectStateFactory) { if (projectConfig == null) { return this; }//from www . ja v a 2s . co m ProjectState state = projectStateFactory.create(projectConfig); ProjectState parent = Iterables.getFirst(state.parents(), null); if (parent != null) { PluginConfig parentPluginConfig = parent.getConfig().getPluginConfig(pluginName) .withInheritance(projectStateFactory); Set<String> allNames = cfg.getNames(PLUGIN, pluginName); cfg = copyConfig(cfg); for (String name : parentPluginConfig.cfg.getNames(PLUGIN, pluginName)) { if (!allNames.contains(name)) { cfg.setStringList(PLUGIN, pluginName, name, Arrays.asList(parentPluginConfig.cfg.getStringList(PLUGIN, pluginName, name))); } } } return this; }
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)); }//from w w w. jav a 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:jp.xet.uncommons.wicket.model.FirstElementModel.java
@Override protected T load() { Iterable<T> iterable = collectionModel.getObject(); try {/*from w w w .ja va 2s .c om*/ return Iterables.getFirst(iterable, null); } catch (NoSuchElementException e) { return null; } }
From source file:org.eclipse.recommenders.utils.rcp.ast.MethodDeclarationFinder.java
public Optional<MethodDeclaration> getMatch() { return fromNullable(Iterables.getFirst(matches, null)); }
From source file:se.curity.examples.oauth.FilterHelper.java
private static Optional<String> getSingleValue(String name, Multimap<String, String> initParams) { Collection<String> values = initParams.get(name); if (values.size() > 1) { throw new IllegalStateException(String.format("More than one value for parameter [%s]", name)); }/*from ww w. j a v a2 s . c o m*/ return Optional.ofNullable(Iterables.getFirst(values, null)); }
From source file:org.jclouds.virtualbox.functions.AttachNATAdapterToMachineIfNotAlreadyExists.java
@Override public Void apply(IMachine machine) { INetworkAdapter iNetworkAdapter = machine.getNetworkAdapter(networkInterfaceCard.getSlot()); // clean up previously set rules for (String redirectRule : iNetworkAdapter.getNATEngine().getRedirects()) { String redirectRuleName = Iterables.getFirst(Splitter.on(",").split(redirectRule), null); if (redirectRuleName != null) { iNetworkAdapter.getNATEngine().removeRedirect(redirectRuleName); }//from ww w .j a v a2s . c om } iNetworkAdapter.setAttachmentType(NAT); for (RedirectRule rule : networkInterfaceCard.getNetworkAdapter().getRedirectRules()) { try { String ruleName = String.format("%s@%s:%s->%s:%s", rule.getProtocol(), rule.getHost(), rule.getHostPort(), rule.getGuest(), rule.getGuestPort()); iNetworkAdapter.getNATEngine().addRedirect(ruleName, rule.getProtocol(), rule.getHost(), rule.getHostPort(), rule.getGuest(), rule.getGuestPort()); } catch (VBoxException e) { if (!e.getMessage().contains("already exists")) throw e; } } iNetworkAdapter.setEnabled(networkInterfaceCard.isEnabled()); machine.saveSettings(); return null; }
From source file:iterator.AppleSupport.java
/** @see com.apple.eawt.OpenFilesHandler#openFiles(com.apple.eawt.AppEvent.OpenFilesEvent) */ @Override// w w w. ja v a 2 s . co m public void openFiles(OpenFilesEvent e) { File open = Iterables.getFirst(e.getFiles(), null); IFS loaded = controller.load(open); loaded.setSize(controller.getSize()); bus.post(loaded); }
From source file:org.n52.svalbard.read.NillableReader.java
@Override protected void begin() throws XMLStreamException, DecodingException { Optional<String> attr = attr(W3CConstants.QN_XSI_NIL); if (attr.isPresent() && attr.get().equals("true")) { List<QName> attributeNames = getPossibleNilReasonAttributes(); Iterable<Optional<String>> attributes = attr(attributeNames); Iterable<String> reasons = Optional.presentInstances(attributes); this.nillable = Nillable.nil(Iterables.getFirst(reasons, null)); } else {/*from ww w. ja va 2s . c o m*/ this.nillable = Nillable.of(delegate(getDelegate())); } }
From source file:com.google.idea.blaze.base.run.rulefinder.RuleFinder.java
@Nullable public RuleIdeInfo firstRuleOfKinds(Project project, Kind... kinds) { return Iterables.getFirst(rulesOfKinds(project, kinds), null); }
From source file:uk.co.flax.luwak.termextractor.RegexpNGramTermExtractor.java
@Override public void extract(RegexpQuery query, List<QueryTerm> terms, List<Extractor<?>> extractors) { String regexp = parseOutRegexp(query.toString("")); String substr = Iterables.getFirst(byLengthOrdering.greatestOf(regexpSplitter.split(regexp), 1), ""); terms.add(new QueryTerm(query.getField(), substr + ngramSuffix, QueryTerm.Type.WILDCARD)); }