List of usage examples for com.google.common.collect Iterables any
public static <T> boolean any(Iterable<T> iterable, Predicate<? super T> predicate)
From source file:org.eclipse.sirius.diagram.business.api.query.DDiagramElementQuery.java
/** * Tests whether the dDiagramElement is indirectly folded because it is * accessible from another edge which was explicitly folded. * //from ww w . j ava 2s. co m * @return <code>true</code> if the dDiagramElement is explicitly folded. */ public boolean isIndirectlyFolded() { return Iterables.any(element.getGraphicalFilters(), Predicates.instanceOf(FoldingFilter.class)); }
From source file:com.eucalyptus.util.Internets.java
public static boolean testLocal(final InetAddress addr) { if (addr == null) return true; try {/*from w w w . java 2 s . com*/ Boolean result = addr.isAnyLocalAddress(); result |= Iterables.any(Internets.getNetworkInterfaces(), new Predicate<NetworkInterface>() { @Override public boolean apply(NetworkInterface arg0) { return Iterables.any(arg0.getInterfaceAddresses(), new Predicate<InterfaceAddress>() { @Override public boolean apply(InterfaceAddress arg0) { return arg0.getAddress().equals(addr); } }); } }); return result; } catch (Exception e) { // Exceptions.eat( e.getMessage( ), e ); return false; } }
From source file:org.eclipse.sirius.diagram.business.api.query.DDiagramElementQuery.java
/** * Tests whether the dDiagramElement is explicitly or indirectly folded. * //w ww .ja v a 2 s . co m * @return <code>true</code> if the dDiagramElement is folded (explicitly or * indirectly). */ public boolean isFolded() { return Iterables.any(element.getGraphicalFilters(), Predicates .or(Predicates.instanceOf(FoldingPointFilter.class), Predicates.instanceOf(FoldingFilter.class))); }
From source file:org.eclipse.viatra.query.patternlanguage.validation.PatternLanguageJavaValidator.java
@Check public void checkPatterns(PatternModel model) { resourceDescriptions.setContext(model); if (model.getPatterns() != null) { // TODO: more precise calculation is needed for duplicate patterns // (number and type of pattern parameters) for (Pattern pattern : model.getPatterns()) { QualifiedName fullyQualifiedName = nameProvider.getFullyQualifiedName(pattern); final Iterable<IEObjectDescription> shadowingPatternDescriptions = resourceDescriptions .getExportedObjects(PatternLanguagePackage.Literals.PATTERN, fullyQualifiedName, true); for (IEObjectDescription shadowingPatternDescription : shadowingPatternDescriptions) { EObject shadowingPattern = shadowingPatternDescription.getEObjectOrProxy(); if (shadowingPattern != pattern) { URI resourceUri = pattern.eResource().getURI(); URI otherResourceUri = shadowingPatternDescription.getEObjectURI().trimFragment(); // not using shadowingPattern because it might be proxy IResourceDescription resourceDescription = resourceDescriptions .getResourceDescription(resourceUri); IResourceDescription otherResourceDescription = resourceDescriptions .getResourceDescription(otherResourceUri); List<IContainer> visible = containerManager.getVisibleContainers(resourceDescription, resourceDescriptions); List<IContainer> visibleFromOther = containerManager .getVisibleContainers(otherResourceDescription, resourceDescriptions); if (Iterables.any(visible, contains(otherResourceDescription)) || Iterables.any(visibleFromOther, contains(resourceDescription))) { String otherResourcePath = Objects.firstNonNull(otherResourceUri.toPlatformString(true), otherResourceUri.toFileString()); error(String.format(DUPLICATE_PATTERN_DEFINITION_MESSAGE, fullyQualifiedName, otherResourcePath), pattern, PatternLanguagePackage.Literals.PATTERN__NAME, IssueCodes.DUPLICATE_PATTERN_DEFINITION); }//from www . j a v a 2 s .c om } } } } }
From source file:org.eclipse.emf.compare.ide.ui.internal.contentmergeviewer.tree.TreeContentMergeViewer.java
/** * {@inheritDoc}// w w w.j a v a 2 s . c om * * @see org.eclipse.emf.compare.ide.ui.internal.contentmergeviewer.EMFCompareContentMergeViewer#paintCenter(org.eclipse.swt.widgets.Canvas, * org.eclipse.swt.graphics.GC) */ @Override protected void paintCenter(GC g) { TreeMergeViewer leftMergeViewer = getLeftMergeViewer(); TreeMergeViewer rightMergeViewer = getRightMergeViewer(); Tree leftTree = leftMergeViewer.getStructuredViewer().getTree(); Tree rightTree = rightMergeViewer.getStructuredViewer().getTree(); Rectangle leftClientArea = leftTree.getClientArea(); Rectangle rightClientArea = rightTree.getClientArea(); final List<TreeItem> leftItems = getExpandedTreeItems(leftTree); final List<TreeItem> rightItems = getExpandedTreeItems(rightTree); final ImmutableSet<TreeItem> selection = ImmutableSet.copyOf(leftTree.getSelection()); for (TreeItem leftItem : leftItems) { final boolean selected = Iterables.any(selection, equalTo(leftItem)); IMergeViewerItem leftData = (IMergeViewerItem) leftItem.getData(); final Diff leftDiff = leftData.getDiff(); if (leftDiff != null) { if (MergeViewerUtil.isVisibleInMergeViewer(leftDiff, getDifferenceGroupProvider(), getDifferenceFilterPredicate()) && !MergeViewerUtil.isMarkAsMerged(leftDiff, leftData, getCompareConfiguration())) { TreeItem rightItem = findRightTreeItemFromLeftDiff(rightItems, leftDiff, leftData); if (rightItem != null) { final Color strokeColor = getCompareColor().getStrokeColor(leftDiff, isThreeWay(), false, selected); g.setForeground(strokeColor); drawCenterLine(g, leftClientArea, rightClientArea, leftItem, rightItem); } } } } }
From source file:com.eucalyptus.images.ImageManager.java
public RegisterImageResponseType register(final RegisterImageType request) throws EucalyptusCloudException, AuthException, IllegalContextAccessException, NoSuchElementException, PersistenceException { final Context ctx = Contexts.lookup(); ImageInfo imageInfo = null;/*ww w . ja v a 2s . c om*/ final String rootDevName = (request.getRootDeviceName() != null) ? request.getRootDeviceName() : Images.DEFAULT_ROOT_DEVICE; final String eki = ImageMetadata.Platform.windows.name().equals(request.getKernelId()) ? request.getKernelId() : normalizeOptionalImageIdentifier(request.getKernelId()); final String eri = normalizeOptionalImageIdentifier(request.getRamdiskId()); verifyImageNameAndDescription(request.getName(), request.getDescription()); ImageMetadata.VirtualizationType virtType = ImageMetadata.VirtualizationType.paravirtualized; if (request.getVirtualizationType() != null) { if (StringUtils.equalsIgnoreCase("paravirtual", request.getVirtualizationType())) virtType = ImageMetadata.VirtualizationType.paravirtualized; else if (StringUtils.equalsIgnoreCase("hvm", request.getVirtualizationType())) virtType = ImageMetadata.VirtualizationType.hvm; else throw new EucalyptusCloudException("Unknown virtualization-type"); } if (request.getImageLocation() != null) { // Verify all the device mappings first. bdmInstanceStoreImageVerifier().apply(request); //When there is more than one verifier, something like this can be handy: Predicates.and(bdmVerifier(Boolean.FALSE)...).apply(request); final ImageManifest manifest = ImageManifests.lookup(request.getImageLocation(), ctx.getUser()); LOG.debug("Obtained manifest information for requested image registration: " + manifest); final ImageMetadata.Platform imagePlatform = request.getPlatform() != null ? ImageMetadata.Platform.valueOf(request.getPlatform()) : manifest.getPlatform(); if (ImageMetadata.Platform.windows.equals(imagePlatform)) virtType = ImageMetadata.VirtualizationType.hvm; final ImageMetadata.VirtualizationType virtualizationType = virtType; if (ImageMetadata.Type.machine.equals(manifest.getImageType()) && ImageMetadata.VirtualizationType.paravirtualized.equals(virtualizationType)) { // make sure kernel and ramdisk are present with the request or manifest if (request.getKernelId() == null && manifest.getKernelId() == null) throw new ClientComputeException("MissingParameter", "Kernel ID must be specified"); if (request.getRamdiskId() == null && manifest.getRamdiskId() == null) throw new ClientComputeException("MissingParameter", "Ramdisk ID must be specified"); } //Check that the manifest-specified size of the image is within bounds. //If null image max size then always allow Integer maxSize = ImageConfiguration.getInstance().getMaxImageSizeGb(); if (maxSize != null && maxSize > 0 && manifest.getSize() > (maxSize * GB)) { throw new EucalyptusCloudException("Cannot register image of size " + manifest.getSize() + " bytes because it exceeds the configured maximum instance-store image size of " + maxSize + " GB. Please contact your administrator "); } List<DeviceMapping> vbr = Lists.transform(request.getBlockDeviceMappings(), Images.deviceMappingGenerator(imageInfo, null)); final ImageMetadata.Architecture arch = (request.getArchitecture() == null ? null : ImageMetadata.Architecture.valueOf(request.getArchitecture())); Supplier<ImageInfo> allocator = new Supplier<ImageInfo>() { @Override public ImageInfo get() { try { /// TODO: we use virt-type as the heuristics for determining image-format /// In the future, we should manifest's block device mapping which is an ec2-way for expressing the image format if (ImageMetadata.Type.machine.equals(manifest.getImageType()) && ImageMetadata.VirtualizationType.paravirtualized.equals(virtualizationType)) return Images.createPendingAvailableFromManifest(ctx.getUserFullName(), request.getName(), request.getDescription(), arch, virtualizationType, ImageMetadata.Platform.linux, ImageMetadata.ImageFormat.partitioned, eki, eri, manifest); else return Images.registerFromManifest(ctx.getUserFullName(), request.getName(), request.getDescription(), arch, virtualizationType, imagePlatform, ImageMetadata.ImageFormat.fulldisk, eki, eri, manifest); } catch (Exception ex) { LOG.error(ex); Logs.extreme().error(ex, ex); throw Exceptions.toUndeclared(ex); } } }; imageInfo = RestrictedTypes.allocateUnitlessResource(allocator); imageInfo.getDeviceMappings().addAll(vbr); } else if (rootDevName != null && Iterables.any(request.getBlockDeviceMappings(), Images.findEbsRoot(rootDevName))) { Supplier<ImageInfo> allocator = null; // Verify all the device mappings first. Dont fuss if both snapshot id and volume size are left blank bdmBfebsImageVerifier().apply(request); ImageMetadata.Platform platform = ImageMetadata.Platform.linux; if (request.getPlatform() != null) platform = ImageMetadata.Platform.valueOf(request.getPlatform()); else if (ImageMetadata.Platform.windows.name().equals(eki)) platform = ImageMetadata.Platform.windows; final ImageMetadata.Platform imagePlatform = platform; allocator = new Supplier<ImageInfo>() { @Override public ImageInfo get() { try { return Images.createFromDeviceMapping(ctx.getUserFullName(), request.getName(), request.getDescription(), imagePlatform, eki, eri, rootDevName, request.getBlockDeviceMappings()); } catch (EucalyptusCloudException ex) { throw new RuntimeException(ex); } } }; imageInfo = RestrictedTypes.allocateUnitlessResource(allocator); } else { throw new EucalyptusCloudException( "Invalid request: the request must specify either ImageLocation for an " + "instance-store image or a snapshot for the root device for an EBS image. " + "Provided values were: ImageLocation=" + request.getImageLocation() + " BlockDeviceMappings=" + request.getBlockDeviceMappings()); } RegisterImageResponseType reply = (RegisterImageResponseType) request.getReply(); reply.setImageId(imageInfo.getDisplayName()); return reply; }
From source file:com.facebook.swift.codec.metadata.ThriftStructMetadataBuilder.java
private void addMethod(Class<?> clazz, Method method, boolean allowReaders, boolean allowWriters) { checkArgument(method.isAnnotationPresent(ThriftField.class)); ThriftField annotation = method.getAnnotation(ThriftField.class); // verify parameters if (isValidateGetter(method)) { if (allowReaders) { MethodExtractor methodExtractor = new MethodExtractor(method, annotation); fields.add(methodExtractor); extractors.add(methodExtractor); } else {/*from w w w . java2 s . c o m*/ metadataErrors.addError("Reader method %s.%s is not allowed on a builder class", clazz.getName(), method.getName()); } } else if (isValidateSetter(method)) { if (allowWriters) { List<ParameterInjection> parameters; if (method.getParameterTypes().length > 1 || Iterables.any( asList(method.getParameterAnnotations()[0]), Predicates.instanceOf(ThriftField.class))) { parameters = getParameterInjections(method.getParameterAnnotations(), method.getGenericParameterTypes(), extractParameterNames(method)); if (annotation.value() != Short.MIN_VALUE) { metadataErrors.addError( "A method with annotated parameters can not have a field id specified: %s.%s ", clazz.getName(), method.getName()); } if (!annotation.name().isEmpty()) { metadataErrors.addError( "A method with annotated parameters can not have a field name specified: %s.%s ", clazz.getName(), method.getName()); } if (annotation.required()) { metadataErrors.addError( "A method with annotated parameters can not be marked as required: %s.%s ", clazz.getName(), method.getName()); } } else { parameters = ImmutableList.of(new ParameterInjection(0, annotation, extractFieldName(method), method.getGenericParameterTypes()[0])); } fields.addAll(parameters); methodInjections.add(new MethodInjection(method, parameters)); } else { metadataErrors.addError( "Inject method %s.%s is not allowed on struct class, since struct has a builder", clazz.getName(), method.getName()); } } else { metadataErrors.addError("Method %s.%s is not a supported getter or setter", clazz.getName(), method.getName()); } }
From source file:org.killbill.billing.subscription.alignment.PlanAligner.java
private boolean isPlanContainPhaseType(final Plan plan, @Nullable final PhaseType phaseType) { return Iterables.any(ImmutableList.copyOf(plan.getAllPhases()), new Predicate<PlanPhase>() { @Override// w w w .j av a 2s. c o m public boolean apply(final PlanPhase input) { return input.getPhaseType() == phaseType; } }); }
From source file:nextmethod.web.razor.parser.TokenizerBackedParser.java
@SafeVarargs protected final void acceptWhile(@Nonnull final TSymbolType... types) { acceptWhile(tSymbol -> tSymbol != null && Iterables.any(Arrays.asList(types), tSymbolType -> tSymbolType != null && tSymbolType == tSymbol.getType())); }
From source file:com.eucalyptus.network.NetworkGroupManager.java
public AuthorizeSecurityGroupIngressResponseType authorize(final AuthorizeSecurityGroupIngressType request) throws Exception { final Context ctx = Contexts.lookup(); final AuthorizeSecurityGroupIngressResponseType reply = request.getReply(); final EntityTransaction db = Entities.get(NetworkGroup.class); try {/* w w w. j av a 2s.c o m*/ final NetworkGroup ruleGroup = lookupGroup(request.getGroupId(), request.getGroupName()); if (!RestrictedTypes.filterPrivileged().apply(ruleGroup)) { throw new EucalyptusCloudException("Not authorized to authorize network group " + ruleGroup.getDisplayName() + " for " + ctx.getUser()); } final List<NetworkRule> ruleList = Lists.newArrayList(); List<IpPermissionType> ipPermissions = handleOldAndNewIpPermissions(request.getCidrIp(), request.getIpProtocol(), request.getFromPort(), request.getToPort(), request.getSourceSecurityGroupName(), request.getSourceSecurityGroupOwnerId(), request.getIpPermissions()); NetworkGroups.resolvePermissions(ipPermissions, ctx.getUser().getAccountNumber(), false); for (final IpPermissionType ipPerm : ipPermissions) { if (ipPerm.getCidrIpRanges().isEmpty() && ipPerm.getGroups().isEmpty()) { continue; // see EUCA-5934 } try { final List<NetworkRule> rules = NetworkGroups.IpPermissionTypeAsNetworkRule.INSTANCE .apply(ipPerm); ruleList.addAll(rules); } catch (final IllegalArgumentException ex) { throw new ClientComputeException("InvalidPermission.Malformed", ex.getMessage()); } } if (Iterables.any(ruleGroup.getNetworkRules(), new Predicate<NetworkRule>() { @Override public boolean apply(final NetworkRule rule) { return Iterables.any(ruleList, Predicates.equalTo(rule)); } })) { reply.set_return(false); return reply; } else { ruleGroup.getNetworkRules().addAll(ruleList); reply.set_return(true); } db.commit(); NetworkGroups.flushRules(); return reply; } catch (Exception ex) { Logs.exhaust().error(ex, ex); throw ex; } finally { if (db.isActive()) db.rollback(); } }