本文整理匯總了Java中org.apache.commons.collections.CollectionUtils類的典型用法代碼示例。如果您正苦於以下問題:Java CollectionUtils類的具體用法?Java CollectionUtils怎麽用?Java CollectionUtils使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
CollectionUtils類屬於org.apache.commons.collections包,在下文中一共展示了CollectionUtils類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getLoginUserMenuList
import org.apache.commons.collections.CollectionUtils; //導入依賴的package包/類
/**
* 獲取當前登錄者所能看見的菜單集合
* @param request
* @param response
* @return
*/
@ResponseBody
@RequestMapping(value="/login/user/menus", method=GET, produces=APPLICATION_JSON)
public Object getLoginUserMenuList(HttpServletRequest request, HttpServletResponse response) {
List<Map<String,Object>> dataList = new ArrayList<Map<String,Object>>();
try {
List<AdminResource> userMenuResources = new ArrayList<AdminResource>();
AdminUserRealm realm = ShiroUtils.getRealm(AdminUserRealm.class);
AuthorizationInfo authInfo = realm.getAuthorizationInfo(SecurityUtils.getSubject().getPrincipals());
if(authInfo instanceof CustomAuthorizationInfo){
CustomAuthorizationInfo<AdminResource> authorizationInfo = (CustomAuthorizationInfo<AdminResource>) authInfo;
Set<AdminResource> userResources = authorizationInfo.getResources();
if(!CollectionUtils.isEmpty(userResources)){
for(AdminResource resource : userResources){
if(AdminResourceActionTypeEnum.ADMIN_RESOURCE_ACTION_TYPE_MENU.getTypeCode().equals(resource.getActionType())){
userMenuResources.add(resource);
}
}
dataList = resourceTreeBuilder.buildObjectTree(GlobalConstants.DEFAULT_ADMIN_ROOT_RESOURCE_ID, userMenuResources, resourceNavMenuNodeConverter);
}
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
return dataList;
}
示例2: delete
import org.apache.commons.collections.CollectionUtils; //導入依賴的package包/類
@RequestMapping("/delete")
@ResponseBody
public ReturnT<String> delete(int id) {
// 存在Test記錄,拒絕刪除
List<XxlApiTestHistory> historyList = xxlApiTestHistoryDao.loadByDocumentId(id);
if (CollectionUtils.isNotEmpty(historyList)) {
return new ReturnT<String>(ReturnT.FAIL_CODE, "拒絕刪除,該接口下存在Test記錄,不允許刪除");
}
// 存在Mock記錄,拒絕刪除
List<XxlApiMock> mockList = xxlApiMockDao.loadAll(id);
if (CollectionUtils.isNotEmpty(mockList)) {
return new ReturnT<String>(ReturnT.FAIL_CODE, "拒絕刪除,該接口下存在Mock記錄,不允許刪除");
}
int ret = xxlApiDocumentDao.delete(id);
return (ret>0)?ReturnT.SUCCESS:ReturnT.FAIL;
}
示例3: invokeConfigItemPostProcessors
import org.apache.commons.collections.CollectionUtils; //導入依賴的package包/類
/**
* 調用所有的{@link ConfigItemPostProcessor}進行配置項預處理
*
* @param versionPropertySource
*/
private void invokeConfigItemPostProcessors(VersionPropertySource<ConfigItemList> versionPropertySource) {
if (versionPropertySource == null) {
return;
}
List<ConfigItemPostProcessor> configItemPostProcessors = this.configItemPostProcessors;
if (CollectionUtils.isEmpty(configItemPostProcessors)) {
return;
}
long version = versionPropertySource.getVersion();
EnumerablePropertySource<?> propertySource = versionPropertySource.getSource();
if (propertySource == null) {
return;
}
if (!(propertySource instanceof ConfigPropertySource)) {
return;
}
ConfigPropertySource configPropertySource = (ConfigPropertySource) propertySource;
for (ConfigItemPostProcessor postProcessor : configItemPostProcessors) {
postProcessor.postProcessConfigItems(version, configPropertySource);
}
}
示例4: testGetTopLevelKeys
import org.apache.commons.collections.CollectionUtils; //導入依賴的package包/類
@Test
public void testGetTopLevelKeys() {
List<String> expected = Lists.newArrayList("value1", "value2");
IData idata = IDataFactory.create();
IDataCursor cursor = idata.getCursor();
IDataUtil.put(cursor, "value1", "something");
IDataUtil.put(cursor, "value2", "another one");
cursor.destroy();
Document document = docFactory.wrap(idata);
CollectionUtils.isEqualCollection(expected, document.getKeys());
}
示例5: testSelects
import org.apache.commons.collections.CollectionUtils; //導入依賴的package包/類
@Test
@SuppressWarnings("unchecked")
public void testSelects() {
Record r = new Record();
r.setUserIdentityARN("arn:sample");
List<Record> records = Arrays.asList(r, new Record());
Collection<Record> sample = CollectionUtils.select(records, new Predicate() {
@Override
public boolean evaluate(Object o) {
return o instanceof Record && ((Record) o).getUserIdentityARN() != null && ((Record) o).getUserIdentityARN().contains("sample");
}
});
Assertions.assertThat(sample).hasSize(1);
}
示例6: isDefined
import org.apache.commons.collections.CollectionUtils; //導入依賴的package包/類
/**
* 判斷對象是不是定義了 <br>
* List的話,不為NULL和空<br>
* 字符串的的話,不為NULL或空<br>
* Integer的話,不為NULL或0<br>
*
* @param obj
* 要判斷的對象
* @return 是否定義了
*/
public static boolean isDefined(Object obj) {
if (obj instanceof Collection) {
return CollectionUtils.isNotEmpty((Collection<?>) obj);
}
if (obj instanceof Map) {
return MapUtils.isNotEmpty((Map<?, ?>) obj);
}
if (obj instanceof String) {
return StringUtils.isNotEmpty((String) obj);
}
if (obj instanceof Integer) {
return obj != null && (Integer) obj != 0;
}
return obj != null;
}
示例7: batchRemove
import org.apache.commons.collections.CollectionUtils; //導入依賴的package包/類
/**
* 批量刪除補償事務信息
*
* @param ids ids 事務id集合
* @param applicationName 應用名稱
* @return true 成功
*/
@Override
public Boolean batchRemove(List<String> ids, String applicationName) {
if (CollectionUtils.isEmpty(ids) || StringUtils.isBlank(applicationName)) {
return Boolean.FALSE;
}
final String rootPath = RepositoryPathUtils.buildZookeeperPath(applicationName);
ids.stream().map(id -> {
try {
final String path = buildRootPath(rootPath, id);
byte[] content = zooKeeper.getData(path,
false, new Stat());
final TransactionRecoverAdapter adapter = objectSerializer.deSerialize(content, TransactionRecoverAdapter.class);
zooKeeper.delete(path, adapter.getVersion());
return 1;
} catch (Exception e) {
e.printStackTrace();
return -1;
}
}).count();
return Boolean.TRUE;
}
開發者ID:yu199195,項目名稱:happylifeplat-transaction,代碼行數:32,代碼來源:ZookeeperRecoverTransactionServiceImpl.java
示例8: getProxy
import org.apache.commons.collections.CollectionUtils; //導入依賴的package包/類
@Override
public HttpProxy getProxy(List<HttpProxy> httpProxies) {
if (CollectionUtils.isNotEmpty(httpProxies)) {
return httpProxies.get(new Random().nextInt(httpProxies.size()-1));
}
return null;
}
示例9: getFullPieceMd5s
import org.apache.commons.collections.CollectionUtils; //導入依賴的package包/類
private List<String> getFullPieceMd5s(Task task, FileMetaData metaData) {
List<String> pieceMd5s = taskService.getFullPieceMd5sByTask(task);
if (CollectionUtils.isEmpty(pieceMd5s)) {
pieceMd5s = fileMetaDataService.readPieceMd5(task.getTaskId(), metaData.getRealMd5());
}
return pieceMd5s;
}
示例10: determineLifecycleStatus
import org.apache.commons.collections.CollectionUtils; //導入依賴的package包/類
public ProcessingLifecycleStatus determineLifecycleStatus(RawLines rawLines) {
ProcessingLifecycleStatus status = ProcessingLifecycleStatus.UNKNOWN;
List<List<RawWord>> lines = rawLines.getRawLines();
if(CollectionUtils.isEmpty(lines)) {
return status;
}
for(List<RawWord> line : lines) {
if(status != ProcessingLifecycleStatus.UNKNOWN) {
break;
}
for(RawWord word : line) {
if(word.getWord().contains("Forgot") || word.getWord().contains("Password")) {
status = ProcessingLifecycleStatus.LOGIN_READY;
break;
} else if(word.getWord().contains("Welcome")) {
status = ProcessingLifecycleStatus.APPLICATION_READY;
break;
} else if(word.getWord().contains("Trade")) {
status = ProcessingLifecycleStatus.TRADE_PARTNER;
} else if(word.getWord().contains("SOFTWARE")) {
status = ProcessingLifecycleStatus.ACCEPT_TOS_EULA_READY;
}
}
}
return status;
}
示例11: getExecutable
import org.apache.commons.collections.CollectionUtils; //導入依賴的package包/類
private String getExecutable() {
File supposedExecutable = new File(executableDir + executableName);
if(supposedExecutable.exists()) {
return supposedExecutable.getAbsolutePath();
} else {
Collection<File> theExecutable = FileUtils.listFiles(new File(executableDir), new WildcardFileFilter(executableName), TrueFileFilter.INSTANCE);
if(theExecutable != null || theExecutable.size() > 1 || theExecutable.isEmpty()) {
File newestExecutable = theExecutable.stream().reduce(new File(""),
(aFile, newestFile) -> {
if(aFile.lastModified() > newestFile.lastModified()) {
return aFile;
}
return newestFile;
});
return newestExecutable.getAbsolutePath();
} else if(theExecutable.size() == 1) {
return ((File)CollectionUtils.get(theExecutable, 0)).getAbsolutePath();
} else {
throw new RuntimeException("Could not determine executable path");
}
}
}
示例12: getRollbackCandidates
import org.apache.commons.collections.CollectionUtils; //導入依賴的package包/類
public List<MigrationTask> getRollbackCandidates(List<MigrationTask> allMigrationTasks, int[] rollbackLevels, PatchInfoStore currentPatchInfoStore) throws MigrationException
{
validateRollbackLevel(rollbackLevels);
int rollbackLevel = rollbackLevels[0];
int currentPatchLevel = currentPatchInfoStore.getPatchLevel();
if (currentPatchLevel < rollbackLevel)
{
throw new MigrationException(
"The rollback patch level cannot be greater than the current patch level");
}
PatchRollbackPredicate rollbackPredicate = new PatchRollbackPredicate(currentPatchLevel,
rollbackLevel);
List<MigrationTask> migrationCandidates = new ArrayList<MigrationTask>();
migrationCandidates.addAll(allMigrationTasks);
CollectionUtils.filter(migrationCandidates, rollbackPredicate);
Collections.sort(migrationCandidates);
// need to reverse the list do we apply the rollbacks in descending
// order
Collections.reverse(migrationCandidates);
return migrationCandidates;
}
示例13: setCaches
import org.apache.commons.collections.CollectionUtils; //導入依賴的package包/類
public void setCaches(Collection<Cache> caches) {
if (CollectionUtils.isNotEmpty(caches)) {
for (Cache cache : caches) {
this.caches.put(cache.getName(), cache);
}
}
}
示例14: assertExistTenants
import org.apache.commons.collections.CollectionUtils; //導入依賴的package包/類
private void assertExistTenants(Set<TenantState> tenantKeys) {
if (CollectionUtils.isEmpty(tenantKeys)) {
final String error = "Tenant list for " + applicationName + " empty. Check tenants-list.json.";
log.error(error);
throw new IllegalStateException(error);
}
}
示例15: gc
import org.apache.commons.collections.CollectionUtils; //導入依賴的package包/類
@Override
public boolean gc(GcMeta gcMeta) {
boolean result = false;
if (gcMeta != null) {
List<String> cids = gcMeta.getCids();
String taskId = gcMeta.getTaskId();
if (CollectionUtils.isNotEmpty(cids) && taskId != null) {
for (String cid : cids) {
peerTaskRepo.remove(taskId, cid);
}
}
result = true;
}
return result;
}