下面列出了com.google.common.collect.Iterables#contains ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public boolean isSingleSettingInGroup(@NotNull final FeatureGroup featureGroup, final String group) {
checkNotNull(featureGroup);
/*
No group means all match
*/
if (StringUtils.isBlank(group)) {
return true;
}
if (featureGroup.getGroup() == null) {
return true;
}
final Iterable<String> split = Splitter.on(',')
.trimResults()
.omitEmptyStrings()
.split(featureGroup.getGroup().toLowerCase());
return Iterables.contains(split, group.toLowerCase());
}
/**
* Parses all annotations and builds validation rules for the relevant ones.
*
* @return validation rules (one per annotation)
* @see AnnotatedField(Class, Iterable)
*/
FieldConstraints extractValidationRules() {
Annotation[] annotations = field.getAnnotations();
FieldConstraints fieldConstraints = new FieldConstraints();
for (Annotation annotation : annotations) {
if (Iterables.contains(relevantAnnotationClasses, annotation.annotationType())) {
ConstraintAttributes constraintAttributes = new ConstraintAttributes(annotation);
BuiltInConstraint supportedValidator = BuiltInConstraint.valueOfAnnotationClassOrNull(annotation
.annotationType());
if (supportedValidator == null) {
fieldConstraints.put(annotation.annotationType().getName(), constraintAttributes);
} else {
fieldConstraints.put(supportedValidator.toString(),
supportedValidator.createDecoratorFor(constraintAttributes));
}
}
}
return fieldConstraints;
}
/**
* Add check catalog extensions if not already existing.
*
* @param catalog
* the catalog
* @param pluginModel
* the plugin model
* @param monitor
* the monitor
* @throws CoreException
* the core exception
*/
public void addExtensions(final CheckCatalog catalog, final IPluginModelBase pluginModel, final IProgressMonitor monitor) throws CoreException {
QualifiedName catalogName = nameProvider.apply(catalog);
Collection<IPluginExtension> catalogExtensions = findExtensions(pluginModel, catalogName, ExtensionType.ALL);
Iterable<ExtensionType> registeredExtensionTypes = findExtensionTypes(catalogExtensions);
for (ExtensionType type : ExtensionType.values()) {
ICheckExtensionHelper helper = getExtensionHelper(type);
if (helper == null) {
continue;
}
if (!Iterables.contains(registeredExtensionTypes, type)) {
helper.addExtensionToPluginBase(pluginModel, catalog, type, getExtensionId(nameProvider.apply(catalog), type));
}
}
}
@Override
public ComposableFuture<Map<String, String>> load(final String cacheName, final Iterable<? extends String> keys) {
if (generateLoaderErrors.get()) {
return ComposableFutures.fromError(new RuntimeException(TEMPORARY_ERROR_MESSAGE));
}
if (Iterables.contains(keys, TIMEOUT_KEY)) {
return ComposableFutures.fromError(new RuntimeException(TIMEOUT_MESSAGE));
}
final HashMap<String,String> res = new HashMap<>();
for (String key:keys) {
if (key.equals(NULL_KEY)) {
res.put(key, null);
} if (!key.equals(MISSING_KEY)) {
res.put(key, VALUE_FOR_BULK + key);
}
}
return ComposableFutures.fromValue(res);
}
@Override
public double getEdgesInsideCommunity(int vertexCommunity, int communityVertices)
{
double edges = 0;
Iterable<Vertex> vertices = titanGraph.getVertices(NODE_COMMUNITY, vertexCommunity);
Iterable<Vertex> comVertices = titanGraph.getVertices(COMMUNITY, communityVertices);
for (Vertex vertex : vertices)
{
for (Vertex v : vertex.getVertices(Direction.OUT, SIMILAR))
{
if (Iterables.contains(comVertices, v))
{
edges++;
}
}
}
return edges;
}
protected void setTableIdsAndConfigs() throws IOException {
ZooKeeperInstance instance = new ZooKeeperInstance(ClientConfiguration.loadDefault().withInstance(conf.get(INSTANCE_NAME))
.withZkHosts(conf.get(ZOOKEEPERS)));
Connector connector = null;
tableConfigs = new HashMap<>();
Iterable<String> localityGroupTables = Splitter.on(",").split(conf.get(CONFIGURE_LOCALITY_GROUPS, ""));
try {
connector = instance.getConnector(conf.get(USERNAME), new PasswordToken(Base64.decodeBase64(conf.get(PASSWORD))));
tableIds = connector.tableOperations().tableIdMap();
Set<String> compressionTableBlackList = getCompressionTableBlackList(conf);
String compressionType = getCompressionType(conf);
for (String tableName : tableIds.keySet()) {
ConfigurationCopy tableConfig = new ConfigurationCopy(connector.tableOperations().getProperties(tableName));
tableConfig.set(Property.TABLE_FILE_COMPRESSION_TYPE.getKey(), (compressionTableBlackList.contains(tableName) ? Compression.COMPRESSION_NONE
: compressionType));
if (Iterables.contains(localityGroupTables, tableName)) {
Map<String,Set<Text>> localityGroups = connector.tableOperations().getLocalityGroups(tableName);
// pull the locality groups for this table.
Map<Text,String> cftlg = Maps.newHashMap();
Map<String,Set<ByteSequence>> lgtcf = Maps.newHashMap();
for (Entry<String,Set<Text>> locs : localityGroups.entrySet()) {
lgtcf.put(locs.getKey(), new HashSet<>());
for (Text loc : locs.getValue()) {
cftlg.put(loc, locs.getKey());
lgtcf.get(locs.getKey()).add(new ArrayByteSequence(loc.getBytes()));
}
}
columnFamilyToLocalityGroup.put(tableName, cftlg);
localityGroupToColumnFamilies.put(tableName, lgtcf);
}
tableConfigs.put(tableName, tableConfig);
}
} catch (AccumuloException | AccumuloSecurityException | TableNotFoundException e) {
throw new IOException("Unable to get configuration. Please call MultiRFileOutput.setAccumuloConfiguration with the proper credentials", e);
}
}
private StrippingType getStrippingType(ExtraLinkArgs extraLinkArgs) {
if (Iterables.contains(extraLinkArgs, "-dynamiclib")) {
return StrippingType.DYNAMIC_LIB;
}
if (Iterables.contains(extraLinkArgs, "-kext")) {
return StrippingType.KERNEL_EXTENSION;
}
return StrippingType.DEFAULT;
}
@NoWarning("GC")
public static void testIterablesOK(Iterable<String> i, Collection<String> c) {
Iterables.contains(i, "x");
Iterables.removeAll(i, c);
Iterables.retainAll(i, c);
Iterables.elementsEqual(i, c);
Iterables.frequency(i, "x");
}
@Override
public void apply(EntityLocal entity) {
super.apply(entity);
boolean isCharacterGroupsPresent = characterGroups != null
&& characterGroups.size() > 0;
boolean isCharacterGroupsValid = isCharacterGroupsPresent
&& !Iterables.contains(characterGroups, Predicates.isNull())
&& !Iterables.contains(characterGroups, Predicates.equalTo(""));
boolean isAcceptableCharsPresentAndValid = acceptableChars != null
&& !acceptableChars.isEmpty();
Preconditions.checkArgument(!isCharacterGroupsPresent || isCharacterGroupsValid, "password.character.groups config key was given but does not contain any valid groups");
Preconditions.checkArgument(!(isCharacterGroupsPresent && isAcceptableCharsPresentAndValid), "password.chars and password.character.groups both provided - please provide only ONE of them");
Preconditions.checkArgument(!isCharacterGroupsValid || characterGroups.size() <= passwordLength, "password.length must be longer than the number of entries in password.character.groups");
String password;
if (isCharacterGroupsValid) {
password = Identifiers.makeRandomPassword(passwordLength, characterGroups.toArray(new String[0]));
} else if (isAcceptableCharsPresentAndValid) {
password = Identifiers.makeRandomPassword(passwordLength, acceptableChars);
} else {
password = Identifiers.makeRandomPassword(passwordLength);
}
entity.sensors().set(sensor, password);
}
/**
* Checks if an object with given name, case sensitive or not, and type is exported.
*
* @param context
* the context
* @param name
* the name
* @param type
* the type
* @param ignoreCase
* the ignore case
* @return true, if is exported
*/
public boolean isExported(final EObject context, final String name, final EClass type, final boolean ignoreCase) {
List<String> exportedNames = getExportedNames(ContainerQuery.newBuilder(domainMapper, type).execute(context));
if (ignoreCase) {
return Iterables.contains(Iterables.transform(exportedNames, new Function<String, String>() {
@Override
public String apply(final String from) {
return from.toLowerCase(); // NOPMD
}
}), name);
} else {
return exportedNames.contains(name);
}
}
@Override
public boolean contains(@Nullable Object o) {
// narrow down search when object is a segment
if (o instanceof ICalledFunction) {
ICalledFunction seg = (ICalledFunction) o;
Iterable<@NonNull ISegment> iterable = getIntersectingElements(seg.getStart());
return Iterables.contains(iterable, seg);
}
return false;
}
@Override
protected CollectPackagesUnderDirectoryValue aggregateWithSubdirectorySkyValues(
MyPackageDirectoryConsumer consumer, Map<SkyKey, SkyValue> subdirectorySkyValues) {
// Aggregate the child subdirectory package state.
ImmutableMap.Builder<RootedPath, Boolean> builder = ImmutableMap.builder();
for (SkyKey key : subdirectorySkyValues.keySet()) {
RecursivePkgKey recursivePkgKey = (RecursivePkgKey) key.argument();
CollectPackagesUnderDirectoryValue collectPackagesValue =
(CollectPackagesUnderDirectoryValue) subdirectorySkyValues.get(key);
boolean packagesOrErrorsInSubdirectory =
collectPackagesValue.isDirectoryPackage()
|| collectPackagesValue.getErrorMessage() != null
|| Iterables.contains(
collectPackagesValue
.getSubdirectoryTransitivelyContainsPackagesOrErrors()
.values(),
Boolean.TRUE);
builder.put(recursivePkgKey.getRootedPath(), packagesOrErrorsInSubdirectory);
}
ImmutableMap<RootedPath, Boolean> subdirectories = builder.build();
String errorMessage = consumer.getErrorMessage();
if (errorMessage != null) {
return CollectPackagesUnderDirectoryValue.ofError(errorMessage, subdirectories);
}
return CollectPackagesUnderDirectoryValue.ofNoError(
consumer.isDirectoryPackage(), subdirectories);
}
@Override
public boolean contains(BsonValue<?> element) {
return Iterables.contains(this, element);
}
@Override
public boolean contains(T object) {
return Iterables.contains(this, object);
}
private boolean isAzure(Location location) {
Set<String> computeIds = getJcloudsLocationIds("azurecompute");
return location.getParent() != null && Iterables.contains(computeIds, location.getParent().getId());
}
private void messageOverrideMemberTypeConflict(RedefinitionType redefinitionType, TMember overriding,
TMember overridden, Result result, MemberMatrix mm) {
String message;
String code;
String redefinitionTypeName = redefinitionType.name();
if (redefinitionType == RedefinitionType.implemented &&
Iterables.contains(mm.implemented(), overriding)) {
redefinitionTypeName = "consumed";
}
String overridingSource = "";
if (redefinitionType == RedefinitionType.implemented &&
Iterables.contains(mm.inherited(), overriding)) {
overridingSource = "inherited ";
}
String extraMessage = cfOtherImplementedMembers(mm, overriding, overridden);
if (overriding.isField() && overridden.isField() && !((TField) overridden).isConst()) {
code = CLF_REDEFINED_TYPE_NOT_SAME_TYPE;
message = getMessageForCLF_REDEFINED_TYPE_NOT_SAME_TYPE(
overridingSource + validatorMessageHelper.descriptionDifferentFrom(overriding, overridden),
redefinitionTypeName,
validatorMessageHelper.descriptionDifferentFrom(overridden, overriding),
extraMessage);
} else if (overriding.isMethod() && overridden.isMethod()) {
code = CLF_REDEFINED_METHOD_TYPE_CONFLICT;
message = getMessageForCLF_REDEFINED_METHOD_TYPE_CONFLICT(
overridingSource + validatorMessageHelper.descriptionDifferentFrom(overriding, overridden),
redefinitionTypeName,
validatorMessageHelper.descriptionDifferentFrom(overridden, overriding),
validatorMessageHelper.trimTypesystemMessage(result),
extraMessage);
} else {
code = CLF_REDEFINED_MEMBER_TYPE_INVALID;
message = getMessageForCLF_REDEFINED_MEMBER_TYPE_INVALID(
overridingSource + validatorMessageHelper.descriptionDifferentFrom(overriding, overridden),
validatorMessageHelper.descriptionDifferentFrom(overridden, overriding),
redefinitionTypeName,
validatorMessageHelper.trimTypesystemMessage(result),
extraMessage);
}
addIssueToMemberOrInterfaceReference(redefinitionType, overriding, overridden, message, code);
}
private boolean isAttributeAvailable(String attributeName, Iterable<String> attributeNames) {
return (attributeName == null || Iterables.contains(attributeNames, attributeName));
}
public static <T> void assertNotContains(T expected, Iterable<? extends T> actual, String message) {
if(Iterables.contains(actual, expected)) {
fail(formatNotContains(message, expected, actual));
}
}
/**
* Rebuild the view's entry tree to ensure that entries from a newly started
* trace are added.
*
* @param signal
* analysis started signal.
* @since 3.3
*/
@TmfSignalHandler
public void handleAnalysisStarted(TmfStartAnalysisSignal signal) {
IAnalysisModule module = signal.getAnalysisModule();
if (module instanceof ITmfAnalysisModuleWithStateSystems && !module.isAutomatic()) {
/*
* use set to wait for initialization in build entry list to avoid
* deadlocks.
*/
final ITmfTrace viewTrace = getTrace();
if (Iterables.contains(allModules(viewTrace), module)) {
/*
* Rebuild only if the started analysis module is from the
* active trace/experiment.
*/
new Thread(() -> {
/*
* DataProviderManager#getDataProvider() (see getDataProvider() below) should never be called in a signal handler.
*/
synchronized (fStartedAnalysis) {
fStartedAnalysis.add((ITmfAnalysisModuleWithStateSystems) module);
//Every children of ITmfAnalysisModuleWithStateSystems extends TmfAbstractAnalysisModule
ITmfTrace moduleTrace = module instanceof TmfAbstractAnalysisModule ? ((TmfAbstractAnalysisModule) module).getTrace() : viewTrace;
if (moduleTrace != null) {
getDataProvider(moduleTrace).startedAnalysisSignalHandler((ITmfAnalysisModuleWithStateSystems) module);
rebuild();
}
}
}).start();
} else {
/*
* Reset the View for the relevant trace, ensuring that the
* entry list will be rebuilt when the view switches back.
*/
for (ITmfTrace trace : TmfTraceManager.getInstance().getOpenedTraces()) {
if (Iterables.contains(allModules(trace), module)) {
synchronized (fStartedAnalysis) {
fStartedAnalysis.add((ITmfAnalysisModuleWithStateSystems) module);
resetView(trace);
}
break;
}
}
}
}
}
private void createJPAReport(GraphContext context, ProjectModel application)
{
JPAConfigurationFileService jpaConfigurationFileService = new JPAConfigurationFileService(context);
JPAEntityService jpaEntityService = new JPAEntityService(context);
GraphService<JPANamedQueryModel> jpaNamedQueryService = new GraphService<>(context, JPANamedQueryModel.class);
List<JPAConfigurationFileModel> jpaConfigList = new ArrayList<>();
for (JPAConfigurationFileModel jpaConfig : jpaConfigurationFileService.findAll())
{
Set<ProjectModel> applications = ProjectTraversalCache.getApplicationsForProject(context, jpaConfig.getProjectModel());
if (applications.contains(application))
jpaConfigList.add(jpaConfig);
}
List<JPAEntityModel> entityList = new ArrayList<>();
for (JPAEntityModel entityModel : jpaEntityService.findAll())
{
if (Iterables.contains(entityModel.getApplications(), application))
entityList.add(entityModel);
}
List<JPANamedQueryModel> namedQueryList = new ArrayList<>();
for (JPANamedQueryModel namedQuery : jpaNamedQueryService.findAll())
{
if (Iterables.contains(namedQuery.getJpaEntity().getApplications(), application))
namedQueryList.add(namedQuery);
}
if (jpaConfigList.isEmpty() && entityList.isEmpty() && namedQueryList.isEmpty())
return;
GraphService<WindupVertexListModel> listService = new GraphService<>(context, WindupVertexListModel.class);
Map<String, WindupVertexFrame> additionalData = new HashMap<>(3);
additionalData.put("jpaConfiguration", listService.create().addAll(jpaConfigList));
additionalData.put("jpaEntities", listService.create().addAll(entityList));
additionalData.put("jpaNamedQueries", listService.create().addAll(namedQueryList));
ApplicationReportService applicationReportService = new ApplicationReportService(context);
ApplicationReportModel applicationReportModel = applicationReportService.create();
applicationReportModel.setReportPriority(400);
applicationReportModel.setDisplayInApplicationReportIndex(true);
applicationReportModel.setReportName("JPA");
applicationReportModel.setDescription(REPORT_DESCRIPTION);
applicationReportModel.setReportIconClass("glyphicon jpa-nav-logo");
applicationReportModel.setProjectModel(application);
applicationReportModel.setTemplatePath(TEMPLATE_JPA_REPORT);
applicationReportModel.setTemplateType(TemplateType.FREEMARKER);
applicationReportModel.setRelatedResource(additionalData);
// Set the filename for the report
ReportService reportService = new ReportService(context);
reportService.setUniqueFilename(applicationReportModel, "jpa_" + application.getName(), "html");
}