List of usage examples for com.google.common.collect Iterables getLast
@Nullable public static <T> T getLast(Iterable<? extends T> iterable, @Nullable T defaultValue)
From source file:io.helixservice.core.feature.AbstractFeature.java
/** * {@inheritDoc}/*w w w. j av a 2s. c o m*/ */ @Override public <T extends Component> T findComponentByType(String componentType, T defaultValue) { //noinspection unchecked return Iterables.getLast((Collection<T>) componentsMap.get(componentType), defaultValue); }
From source file:it.anyplace.sync.core.beans.FileInfo.java
@Override public String toString() { return "FileRecord{" + "folder=" + folder + ", path=" + path + ", size=" + size + ", lastModified=" + lastModified + ", type=" + type + ", last version = " + Iterables.getLast(versionList, null) + '}'; }
From source file:com.cloudbees.demo.beesshop.service.AmazonS3FileStorageService.java
@Nullable public String findContentType(String fileName) { String fileExtension = Iterables.getLast(Splitter.on('.').split(fileName), null); fileExtension = Strings.nullToEmpty(fileExtension).toLowerCase(); return contentTypeByFileExtension.get(fileExtension); }
From source file:org.eclipse.xtext.xbase.scoping.batch.ConstructorScopes.java
/** * Custom languages that allow to infer anonymous classes may want to use this helper * to access the constructors of those classes. * @param session subtypes may override and use the given session. *///from w ww.j av a2s . c o m protected IScope createAnonymousClassConstructorScope(final JvmGenericType anonymousType, EObject context, final IFeatureScopeSession session) { // we don't care about the type scope since the type is well known here IVisibilityHelper protectedIsVisible = new IVisibilityHelper() { @Override public boolean isVisible(/* @NonNull */ JvmMember member) { return member.getVisibility() != JvmVisibility.PRIVATE; } }; return new ConstructorTypeScopeWrapper(context, protectedIsVisible, IScope.NULLSCOPE) { @Override public Iterable<IEObjectDescription> getElements(EObject object) { throw new UnsupportedOperationException("TODO implement as necessary"); } @Override public Iterable<IEObjectDescription> getElements(QualifiedName name) { JvmTypeReference superType = Iterables.getLast(anonymousType.getSuperTypes(), null); if (superType == null) return Collections.emptyList(); JvmType type = superType.getType(); if (type == null) return Collections.emptyList(); QualifiedName typeName = qualifiedNameConverter.toQualifiedName(type.getQualifiedName('.')); if (typeName.getSegmentCount() > name.getSegmentCount()) { typeName = typeName.skipFirst(typeName.getSegmentCount() - name.getSegmentCount()); } if (!typeName.equals(name)) { if (name.getSegmentCount() == 1 && name.getFirstSegment().indexOf('$') > 0) { QualifiedName splitted = QualifiedName.create(Strings.split(name.getFirstSegment(), '$')); typeName = qualifiedNameConverter.toQualifiedName(type.getQualifiedName('.')); if (typeName.getSegmentCount() > splitted.getSegmentCount()) { typeName = typeName.skipFirst(typeName.getSegmentCount() - splitted.getSegmentCount()); } if (!typeName.equals(splitted)) { return Collections.emptyList(); } } else { return Collections.emptyList(); } } IEObjectDescription typeDescription = EObjectDescription.create(name, anonymousType); return createFeatureDescriptions(Collections.singletonList(typeDescription)); } @Override protected ConstructorDescription createConstructorDescription(IEObjectDescription typeDescription, JvmConstructor constructor, boolean visible) { return createAnonmousClassConstructorDescription(typeDescription.getName(), constructor, visible); } }; }
From source file:com.infinities.keystone4j.token.model.KeystoneToken.java
public String getAutitChainId() { if (V3.equals(version)) { return Iterables.getLast(((TokenData) tokenData).getAuditIds(), null); } else {/* w w w. j a v a2 s .c o m*/ return Iterables.getLast(((Access) tokenData).getToken().getAuditIds(), null); } }
From source file:org.estatio.dom.lease.LeaseItems.java
private BigInteger nextSequenceFor(final Lease lease, final LeaseItemType type) { LeaseItem last = Iterables.getLast(findLeaseItemsByType(lease, type), null); if (last == null) { return BigInteger.ONE; }// w ww . ja v a2 s .c om return last.getSequence() == null ? BigInteger.ONE : last.getSequence().add(BigInteger.ONE); }
From source file:com.flaptor.indextank.storage.IndexLog.java
public Segment getLargestOptimizedSegment() { return Iterables.getLast(Segment.iterateSegments(root, getOptimizedPath(), true), null); }
From source file:uk.ac.cam.cl.dtg.picky.parser.deviceanalyser.DeviceAnalyserEntryParser.java
@Override public Attributes getFileAttributes() { Attributes attributes = new Attributes(); List<String> daysSorted = days.stream().filter(s -> s.matches("\\d{4}-\\d{2}-\\d{2}")).sorted() .collect(Collectors.toList()); attributes.put(ATTRIBUTE_DAYS, daysSorted.size()); if (!daysSorted.isEmpty()) { attributes.put(ATTRIBUTE_FIRST_DAY, Iterables.getFirst(daysSorted, null)); attributes.put(ATTRIBUTE_LAST_DAY, Iterables.getLast(daysSorted, null)); }/*from w ww . j a v a 2 s. c o m*/ DeviceInfo deviceInfo = deviceInfoParser.getDeviceInfo(); if (deviceInfo.apiversion != null) attributes.put(ATTRIBUTE_APIVERSION, deviceInfo.apiversion); if (deviceInfo.device != null) attributes.put(ATTRIBUTE_DEVICE, deviceInfo.device); if (deviceInfo.devicemodel != null) attributes.put(ATTRIBUTE_DEVICEMODEL, deviceInfo.devicemodel); if (deviceInfo.dpi != null) attributes.put(ATTRIBUTE_DPI, deviceInfo.dpi); if (deviceInfo.locale != null) attributes.put(ATTRIBUTE_LOCALE, deviceInfo.locale); if (deviceInfo.getCountry() != null) attributes.put(ATTRIBUTE_LOCALE_COUNTRY, deviceInfo.getCountry()); if (deviceInfo.manufacturer != null) attributes.put(ATTRIBUTE_MANUFACTURER, deviceInfo.manufacturer); if (deviceInfo.osbuildtype != null) attributes.put(ATTRIBUTE_OSBUILDTYPE, deviceInfo.osbuildtype); if (deviceInfo.osstring != null) attributes.put(ATTRIBUTE_OSSTRING, deviceInfo.osstring); if (deviceInfo.resolution != null) attributes.put(ATTRIBUTE_RESOLUTION, deviceInfo.resolution); attributes.put(ATTRIBUTE_ROOTED, deviceInfo.getRooted()); return attributes; }
From source file:org.apache.metron.elasticsearch.writer.ElasticsearchWriter.java
List<HostnamePort> getIps(Map<String, Object> globalConfiguration) { Object ipObj = globalConfiguration.get("es.ip"); Object portObj = globalConfiguration.get("es.port"); if (ipObj == null) { return Collections.emptyList(); }//from w w w . j a va 2 s. c o m if (ipObj instanceof String && ipObj.toString().contains(",") && ipObj.toString().contains(":")) { List<String> ips = Arrays.asList(((String) ipObj).split(",")); List<HostnamePort> ret = new ArrayList<>(); for (String ip : ips) { Iterable<String> tokens = Splitter.on(":").split(ip); String host = Iterables.getFirst(tokens, null); String portStr = Iterables.getLast(tokens, null); ret.add(new HostnamePort(host, Integer.parseInt(portStr))); } return ret; } else if (ipObj instanceof String && ipObj.toString().contains(",")) { List<String> ips = Arrays.asList(((String) ipObj).split(",")); List<HostnamePort> ret = new ArrayList<>(); for (String ip : ips) { ret.add(new HostnamePort(ip, Integer.parseInt(portObj + ""))); } return ret; } else if (ipObj instanceof String && !ipObj.toString().contains(":")) { return ImmutableList.of(new HostnamePort(ipObj.toString(), Integer.parseInt(portObj + ""))); } else if (ipObj instanceof String && ipObj.toString().contains(":")) { Iterable<String> tokens = Splitter.on(":").split(ipObj.toString()); String host = Iterables.getFirst(tokens, null); String portStr = Iterables.getLast(tokens, null); return ImmutableList.of(new HostnamePort(host, Integer.parseInt(portStr))); } else if (ipObj instanceof List) { List<String> ips = (List) ipObj; List<HostnamePort> ret = new ArrayList<>(); for (String ip : ips) { Iterable<String> tokens = Splitter.on(":").split(ip); String host = Iterables.getFirst(tokens, null); String portStr = Iterables.getLast(tokens, null); ret.add(new HostnamePort(host, Integer.parseInt(portStr))); } return ret; } throw new IllegalStateException( "Unable to read the elasticsearch ips, expected es.ip to be either a list of strings, a string hostname or a host:port string"); }
From source file:io.bazel.rules.closure.BazelWorker.java
private Iterable<String> loadArguments(Iterable<String> args, boolean isWorker) { String lastArg = Iterables.getLast(args, ""); if (lastArg.startsWith("@")) { Path flagFile = Paths.get(CharMatcher.is('@').trimLeadingFrom(lastArg)); if ((isWorker && lastArg.startsWith("@@")) || Files.exists(flagFile)) { if (!isWorker && !mnemonic.isEmpty()) { output.printf("HINT: %s will compile faster if you run: " + "echo \"build --strategy=%s=worker\" >>~/.bazelrc\n", mnemonic, mnemonic); }/*ww w . ja va2 s. co m*/ try { return Files.readAllLines(flagFile, UTF_8); } catch (IOException e) { throw new RuntimeException(e); } } } return args; }