本文整理匯總了Java中com.google.common.collect.Collections2類的典型用法代碼示例。如果您正苦於以下問題:Java Collections2類的具體用法?Java Collections2怎麽用?Java Collections2使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Collections2類屬於com.google.common.collect包,在下文中一共展示了Collections2類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: selectProperties
import com.google.common.collect.Collections2; //導入依賴的package包/類
private Iterable<ModelPropertyExtractionContext> selectProperties(final ModelSchemaExtractionContext<?> context, CandidateMethods candidateMethods) {
Map<String, ModelPropertyExtractionContext> propertiesMap = Maps.newTreeMap();
for (Map.Entry<Wrapper<Method>, Collection<Method>> entry : candidateMethods.allMethods().entrySet()) {
Method method = entry.getKey().get();
PropertyAccessorType propertyAccessorType = PropertyAccessorType.of(method);
Collection<Method> methodsWithEqualSignature = entry.getValue();
if (propertyAccessorType != null) {
String propertyName = propertyAccessorType.propertyNameFor(method);
ModelPropertyExtractionContext propertyContext = propertiesMap.get(propertyName);
if (propertyContext == null) {
propertyContext = new ModelPropertyExtractionContext(propertyName);
propertiesMap.put(propertyName, propertyContext);
}
propertyContext.addAccessor(new PropertyAccessorExtractionContext(propertyAccessorType, methodsWithEqualSignature));
}
}
return Collections2.filter(propertiesMap.values(), new Predicate<ModelPropertyExtractionContext>() {
@Override
public boolean apply(ModelPropertyExtractionContext property) {
return property.isReadable();
}
});
}
示例2: loadUserByUsername
import com.google.common.collect.Collections2; //導入依賴的package包/類
@Override
public AttributedUserDetails loadUserByUsername(String login) throws UsernameNotFoundException {
login = login.toLowerCase(Locale.ROOT);
final SmartiUser smartiUser = getSmaritUser(login);
if (smartiUser == null) {
log.debug("User {} not found", login);
throw new UsernameNotFoundException(String.format("Unknown user: '%s'", login));
}
final MongoUserDetails userDetails = new MongoUserDetails(
smartiUser.getLogin(),
smartiUser.getPassword(),
Collections2.transform(smartiUser.getRoles(),
role -> new SimpleGrantedAuthority("ROLE_" + StringUtils.upperCase(role, Locale.ROOT))
)
);
userDetails.addAttributes(smartiUser.getProfile());
return userDetails;
}
示例3: unPackSipNode
import com.google.common.collect.Collections2; //導入依賴的package包/類
private Object unPackSipNode(Object object) {
if (object == null) {
return null;
}
if (object instanceof SIPNode) {
return handleSingleSipNode((SIPNode) object);
}
if (object instanceof Collection) {
return Collections2.transform((Collection) object, new Function<Object, Object>() {
@Override
public Object apply(Object input) {
if (!(input instanceof SIPNode)) {
return input;
}
return handleSingleSipNode((SIPNode) input);
}
});
}
return object;
}
示例4: getSeverity
import com.google.common.collect.Collections2; //導入依賴的package包/類
@Override
public String getSeverity() {
if (hasVulnerabilities()) {
Collection<Double> scores = Collections2.transform(
software.getVulnerabilities(), new Function<Vulnerability, Double>() {
@Override
public Double apply(Vulnerability vulnerability) {
return vulnerability.getCvssScore();
}
}
);
Double maxValue = Ordering.natural().max(scores);
if (maxValue > 7) {
return ScanIssueSeverity.HIGH.getName();
} else if (maxValue > 4) {
return ScanIssueSeverity.MEDIUM.getName();
}
return ScanIssueSeverity.LOW.getName();
}
return ScanIssueSeverity.INFO.getName();
}
示例5: getSeverity
import com.google.common.collect.Collections2; //導入依賴的package包/類
@Override
public String getSeverity() {
Collection<Double> scores = Collections2.transform(
vulnerabilities, new Function<Vulnerability, Double>() {
@Override
public Double apply(Vulnerability vulnerability) {
return vulnerability.getCvssScore();
}
}
);
Double maxValue = Ordering.natural().max(scores);
if (maxValue > 7) {
return ScanIssueSeverity.HIGH.getName();
} else if (maxValue > 4) {
return ScanIssueSeverity.MEDIUM.getName();
}
return ScanIssueSeverity.LOW.getName();
}
示例6: findChildren
import com.google.common.collect.Collections2; //導入依賴的package包/類
/**
* Finds all children runtime beans, same properties and values as current root
* + any number of additional properties.
*/
private Set<ObjectName> findChildren(ObjectName innerRootBean, Set<ObjectName> childRbeOns) {
final Map<String, String> wantedProperties = innerRootBean.getKeyPropertyList();
return Sets.newHashSet(Collections2.filter(childRbeOns, on -> {
Map<String, String> localProperties = on.getKeyPropertyList();
for (Entry<String, String> propertyEntry : wantedProperties.entrySet()) {
if (!localProperties.containsKey(propertyEntry.getKey())) {
return false;
}
if (!localProperties.get(propertyEntry.getKey()).equals(propertyEntry.getValue())) {
return false;
}
if (localProperties.size() <= wantedProperties.size()) {
return false;
}
}
return true;
}));
}
示例7: genYailFilesIfNecessary
import com.google.common.collect.Collections2; //導入依賴的package包/類
private void genYailFilesIfNecessary(List<String> sourceFiles)
throws IOException, YailGenerationException {
// Filter out the files that aren't really source files (i.e. that don't end in .scm or .yail)
Collection<String> formAndYailSourceFiles = Collections2.filter(
sourceFiles,
new Predicate<String>() {
@Override
public boolean apply(String input) {
return input.endsWith(FORM_PROPERTIES_EXTENSION) || input.endsWith(YAIL_EXTENSION);
}
});
for (String sourceFile : formAndYailSourceFiles) {
if (sourceFile.endsWith(FORM_PROPERTIES_EXTENSION)) {
String rootPath = sourceFile.substring(0, sourceFile.length()
- FORM_PROPERTIES_EXTENSION.length());
String yailFilePath = rootPath + YAIL_EXTENSION;
// Note: Famous last words: The following contains() makes this method O(n**2) but n should
// be pretty small.
if (!sourceFiles.contains(yailFilePath)) {
generateYail(rootPath);
}
}
}
}
示例8: QuotaConfig
import com.google.common.collect.Collections2; //導入依賴的package包/類
@Inject QuotaConfig(Configuration root) {
this.config = root.getConfigurationSection("match-quotas");
if(config == null) {
quotas = new TreeSet<>();
} else {
quotas = new TreeSet<>(Collections2.transform(
config.getKeys(false),
new Function<String, Entry>() {
@Override
public Entry apply(@Nullable String key) {
return new Entry(config.getConfigurationSection(key));
}
}
));
}
}
示例9: loadFromDataStore
import com.google.common.collect.Collections2; //導入依賴的package包/類
@VisibleForTesting
void loadFromDataStore() {
try {
Date date = new Date();
int version = commonModelFacade.getNextNamespacedListsVersion();
log.info("Start getting NamespacedList(listVersion={}) from WS - startTime={}", version, date.getTime());
NamespacedListsBatch namespacedListsBatch = new NamespacedListsBatch();
namespacedListsBatch.setDataNodeVersion(version);
for (NamespacedList item : commonModelFacade.getAllNamespacedLists()) {
namespacedListsBatch.addValues(item.getName(), Collections2.transform(item.getValueSet(),
item.getType().equals(NamespacedListType.ENCODED) ? NamespacedListValueForWS::getEncodedValue : NamespacedListValueForWS::getValue));
}
setNamespacedListsBatch(namespacedListsBatch);
Long endTime = (new Date()).getTime();
log.info("End getting NamespacedList from WS - endTime=" + endTime + ", total duration=" + (endTime - date.getTime()) + " millis");
} catch (Exception e) {
log.error("Failed to load NamespacedList from commonModelFacade: {}", e.getMessage());
throw e;
}
}
示例10: getCurrentSelectedUsers
import com.google.common.collect.Collections2; //導入依賴的package包/類
@Override
public List<SelectedUser> getCurrentSelectedUsers(SectionInfo info)
{
return Lists.newArrayList(
Collections2.transform(ParentViewItemSectionUtils.getItemInfo(info).getItem().getNotifications(),
new Function<String, SelectedUser>()
{
@Override
public SelectedUser apply(String uuidOrEmail)
{
final UserBean userBean = userService.getInformationForUser(uuidOrEmail);
final String displayName;
if( userBean == null )
{
displayName = uuidOrEmail;
}
else
{
displayName = Format.format(userBean);
}
return new SelectedUser(uuidOrEmail, displayName);
}
}));
}
示例11: getCurrentSelectedUsers
import com.google.common.collect.Collections2; //導入依賴的package包/類
@Override
public List<SelectedUser> getCurrentSelectedUsers(SectionInfo info)
{
return Lists.newArrayList(
Collections2.transform(ParentViewItemSectionUtils.getItemInfo(info).getItem().getCollaborators(),
new Function<String, SelectedUser>()
{
@Override
public SelectedUser apply(final String uuidOrEmail)
{
final UserBean userBean = userService.getInformationForUser(uuidOrEmail);
final String displayName;
if( userBean == null )
{
displayName = uuidOrEmail;
}
else
{
displayName = Format.format(userBean);
}
return new SelectedUser(uuidOrEmail, displayName);
}
}));
}
示例12: setGroupFilter
import com.google.common.collect.Collections2; //導入依賴的package包/類
/**
* Must be set before registering the dialog
*
* @param groupFilter
*/
public void setGroupFilter(Set<String> groupFilter)
{
if( !Check.isEmpty(groupFilter) )
{
this.groupFilter = groupFilter;
final Collection<GroupBean> groupBeans = userService.getInformationForGroups(groupFilter).values();
final Collection<String> gn = Collections2.transform(groupBeans, new Function<GroupBean, String>()
{
@Override
public String apply(GroupBean group)
{
return group.getName();
}
});
groupFilterNames = Lists.newArrayList(gn);
Collections.sort(groupFilterNames);
}
}
示例13: listAll
import com.google.common.collect.Collections2; //導入依賴的package包/類
public static ArrayList<Country> listAll(Context context, final String filter) {
ArrayList<Country> list = new ArrayList<>();
for (String countryCode : Locale.getISOCountries()) {
Country country = getCountry(countryCode, context);
list.add(country);
}
sortList(list);
if (filter != null && filter.length() > 0) {
return new ArrayList<>(Collections2.filter(list, new Predicate<Country>() {
@Override
public boolean apply(Country input) {
return input.getName().toLowerCase().contains(filter.toLowerCase());
}
}));
} else {
return list;
}
}
示例14: listAll
import com.google.common.collect.Collections2; //導入依賴的package包/類
public static ArrayList<Currency> listAll(Context context, final String filter) {
ArrayList<Currency> list = new ArrayList<>();
for (java.util.Currency currency : java.util.Currency.getAvailableCurrencies()) {
list.add(getCurrency(currency, context));
}
sortList(list);
if (filter != null && filter.length() > 0) {
return new ArrayList<>(Collections2.filter(list, new Predicate<Currency>() {
@Override
public boolean apply(Currency input) {
return input.getName().toLowerCase().contains(filter.toLowerCase()) ||
input.getSymbol().toLowerCase().contains(filter.toLowerCase());
}
}));
} else {
return list;
}
}
示例15: getSourceFiles
import com.google.common.collect.Collections2; //導入依賴的package包/類
@SuppressWarnings("unchecked")
private static Collection<String> getSourceFiles(String extraActionFile) {
ExtraActionInfo info = ExtraActionUtils.getExtraActionInfo(extraActionFile);
CppCompileInfo cppInfo = info.getExtension(CppCompileInfo.cppCompileInfo);
return Collections2.filter(
cppInfo.getSourcesAndHeadersList(),
Predicates.and(
Predicates.not(Predicates.containsPattern("third_party/")),
Predicates.not(Predicates.containsPattern("config/heron-config.h")),
Predicates.not(Predicates.containsPattern(".*pb.h$")),
Predicates.not(Predicates.containsPattern(".*cc_wrapper.sh$")),
Predicates.not(Predicates.containsPattern(".*pb.cc$"))
)
);
}