List of usage examples for java.util Collection clear
void clear();
From source file:org.apache.vxquery.compiler.rewriter.rules.PushFunctionsOntoEqJoinBranches.java
@Override public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue(); if (op.getOperatorTag() != LogicalOperatorTag.INNERJOIN) { return false; }/*from w w w . jav a 2s . co m*/ AbstractBinaryJoinOperator join = (AbstractBinaryJoinOperator) op; ILogicalExpression expr = join.getCondition().getValue(); if (expr.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) { return false; } AbstractFunctionCallExpression fexp = (AbstractFunctionCallExpression) expr; FunctionIdentifier fi = fexp.getFunctionIdentifier(); if (!(fi.equals(AlgebricksBuiltinFunctions.AND) || fi.equals(AlgebricksBuiltinFunctions.EQ))) { return false; } boolean modified = false; List<Mutable<ILogicalExpression>> functionList = new ArrayList<Mutable<ILogicalExpression>>(); List<Mutable<ILogicalExpression>> variableList = new ArrayList<Mutable<ILogicalExpression>>(); functionList.clear(); ExpressionToolbox.findAllFunctionExpressions(join.getCondition(), AlgebricksBuiltinFunctions.EQ, functionList); Collection<LogicalVariable> producedVariables = new ArrayList<LogicalVariable>(); for (Mutable<ILogicalExpression> searchM : functionList) { ILogicalExpression search = searchM.getValue(); if (search.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) { continue; } AbstractFunctionCallExpression searchExp = (AbstractFunctionCallExpression) search; // Go through all argument for EQ. for (Mutable<ILogicalExpression> expressionM : searchExp.getArguments()) { // Push on to branch when possible. for (Mutable<ILogicalOperator> branch : join.getInputs()) { producedVariables.clear(); getProducedVariablesInDescendantsAndSelf(branch.getValue(), producedVariables); variableList.clear(); ExpressionToolbox.findVariableExpressions(expressionM, variableList); boolean found = true; for (Mutable<ILogicalExpression> searchVariableM : variableList) { VariableReferenceExpression vre = (VariableReferenceExpression) searchVariableM.getValue(); if (!producedVariables.contains(vre.getVariableReference())) { found = false; } } if (found) { // push down LogicalVariable assignVariable = context.newVar(); AssignOperator aOp = new AssignOperator(assignVariable, new MutableObject<ILogicalExpression>(expressionM.getValue())); aOp.getInputs().add(new MutableObject<ILogicalOperator>(branch.getValue())); branch.setValue(aOp); aOp.recomputeSchema(); expressionM.setValue(new VariableReferenceExpression(assignVariable)); modified = true; } } } } return modified; }
From source file:org.apache.bval.jsr.BeanDescriptorImpl.java
private static void addGroupConvertion(final MetaProperty prop, final PropertyDescriptorImpl edesc) { boolean fieldFound = false; boolean methodFound = false; Class<?> current = prop.getParentMetaBean().getBeanClass(); while (current != null && current != Object.class && (!methodFound || !fieldFound)) { if (!fieldFound) { final Field field = Reflection.getDeclaredField(current, prop.getName()); if (field != null) { processConvertGroup(edesc, field); fieldFound = true;//ww w .jav a 2 s. c om } } if (!methodFound) { final String name = Character.toUpperCase(prop.getName().charAt(0)) + prop.getName().substring(1); Method m = Reflection.getDeclaredMethod(current, "get" + name); if (m == null) { final Method isAccessor = Reflection.getDeclaredMethod(current, "is" + name); if (isAccessor != null && boolean.class.equals(isAccessor.getReturnType())) { m = isAccessor; } } if (m != null) { processConvertGroup(edesc, m); methodFound = true; } } current = current.getSuperclass(); } final Collection<Annotation> annotations = prop.getFeature(JsrFeatures.Property.ANNOTATIONS_TO_PROCESS); if (annotations != null) { for (final Annotation a : annotations) { if (ConvertGroup.List.class.isInstance(a)) { for (final ConvertGroup convertGroup : ConvertGroup.List.class.cast(a).value()) { edesc.addGroupConversion(new GroupConversionDescriptorImpl(new Group(convertGroup.from()), new Group(convertGroup.to()))); } } if (ConvertGroup.class.isInstance(a)) { final ConvertGroup convertGroup = ConvertGroup.class.cast(a); edesc.addGroupConversion(new GroupConversionDescriptorImpl(new Group(convertGroup.from()), new Group(convertGroup.to()))); } } annotations.clear(); } if (!edesc.getGroupConversions().isEmpty() && !edesc.isCascaded()) { throw new ConstraintDeclarationException("@Valid is needed for group conversion"); } }
From source file:com.jaeksoft.searchlib.Client.java
private final int deleteUniqueKeyList(int totalCount, int docCount, Collection<String> deleteList, InfoCallback infoCallBack) throws SearchLibException { docCount += deleteDocuments(getSchema().getUniqueField(), deleteList); StringBuilder sb = new StringBuilder(); sb.append(docCount);/*from www.java 2 s .co m*/ sb.append(" / "); sb.append(totalCount); sb.append(" XML document(s) deleted."); if (infoCallBack != null) infoCallBack.setInfo(sb.toString()); else Logging.info(sb.toString()); deleteList.clear(); return docCount; }
From source file:ubic.gemma.loader.genome.goldenpath.GoldenPathBioSequenceLoader.java
/** * @param bioSequences//w w w. j av a2 s . c o m */ void load(BlockingQueue<BioSequence> queue) { log.debug("Entering 'load' "); StopWatch timer = new StopWatch(); timer.start(); int count = 0; int cpt = 0; double secspt = 0.0; Collection<BioSequence> bioSequencesToPersist = new ArrayList<BioSequence>(); try { while (!(producerDone && queue.isEmpty())) { BioSequence sequence = queue.poll(); if (sequence == null) { continue; } sequence.getSequenceDatabaseEntry().setExternalDatabase(genbank); sequence.setTaxon(taxon); bioSequencesToPersist.add(sequence); if (++count % BATCH_SIZE == 0) { bioSequenceService.create(bioSequencesToPersist); bioSequencesToPersist.clear(); } // just some timing information. if (count % 1000 == 0) { cpt++; timer.stop(); double secsperthousand = timer.getTime() / 1000.0; secspt += secsperthousand; double meanspt = secspt / cpt; String progString = "Processed and loaded " + count + " sequences, last one was " + sequence.getName() + " (" + secsperthousand + "s for last 1000, mean per 1000 =" + String.format("%.1f", meanspt) + "s)"; log.info(progString); timer.reset(); timer.start(); } } } catch (Exception e) { consumerDone = true; throw new RuntimeException(e); } // finish up. bioSequenceService.create(bioSequencesToPersist); log.info("Loaded total of " + count + " sequences"); consumerDone = true; }
From source file:de.hybris.platform.category.impl.DefaultCategoryService.java
@Override public List<CategoryModel> getCategoryPathForProduct(final ProductModel product, final Class... includeOnlyCategories) { final List<CategoryModel> result = new ArrayList<CategoryModel>(); final Collection<CategoryModel> currentLevel = new ArrayList<CategoryModel>(); currentLevel.addAll(product.getSupercategories()); while (!CollectionUtils.isEmpty(currentLevel)) { CategoryModel categoryModel = null; for (final CategoryModel category : currentLevel) { if (categoryModel == null && shouldAddPathElement(category.getClass(), includeOnlyCategories)) { categoryModel = category; }/*from ww w . ja va 2s. c om*/ } currentLevel.clear(); if (categoryModel != null) { currentLevel.addAll(categoryModel.getSupercategories()); result.add(categoryModel); } } Collections.reverse(result); return result; }
From source file:org.icescrum.core.security.MethodScrumExpressionHandler.java
@SuppressWarnings("unchecked") public Object filter(Object filterTarget, Expression filterExpression, EvaluationContext ctx) { MethodScrumExpressionRoot rootObject = (MethodScrumExpressionRoot) ctx.getRootObject().getValue(); List retainList;//from w w w .j a v a 2 s. co m if (logger.isDebugEnabled()) { logger.debug("Filtering with expression: " + filterExpression.getExpressionString()); } if (filterTarget instanceof Collection) { Collection collection = (Collection) filterTarget; retainList = new ArrayList(collection.size()); if (logger.isDebugEnabled()) { logger.debug("Filtering collection with " + collection.size() + " elements"); } for (Object filterObject : (Collection) filterTarget) { rootObject.setFilterObject(filterObject); if (ExpressionUtils.evaluateAsBoolean(filterExpression, ctx)) { retainList.add(filterObject); } } if (logger.isDebugEnabled()) { logger.debug("Retaining elements: " + retainList); } collection.clear(); collection.addAll(retainList); return filterTarget; } if (filterTarget.getClass().isArray()) { Object[] array = (Object[]) filterTarget; retainList = new ArrayList(array.length); if (logger.isDebugEnabled()) { logger.debug("Filtering collection with " + array.length + " elements"); } for (int i = 0; i < array.length; i++) { rootObject.setFilterObject(array[i]); if (ExpressionUtils.evaluateAsBoolean(filterExpression, ctx)) { retainList.add(array[i]); } } if (logger.isDebugEnabled()) { logger.debug("Retaining elements: " + retainList); } Object[] filtered = (Object[]) Array.newInstance(filterTarget.getClass().getComponentType(), retainList.size()); for (int i = 0; i < retainList.size(); i++) { filtered[i] = retainList.get(i); } return filtered; } throw new IllegalArgumentException( "Filter target must be a collection or array type, but was " + filterTarget); }
From source file:org.training.storefront.breadcrumb.impl.SearchBreadcrumbBuilder.java
public List<Breadcrumb> getBreadcrumbs(final String categoryCode, final String searchText, final boolean emptyBreadcrumbs) throws IllegalArgumentException { final List<Breadcrumb> breadcrumbs = new ArrayList<>(); if (categoryCode == null) { final Breadcrumb breadcrumb = new Breadcrumb("/search?text=" + getEncodedUrl(searchText), StringEscapeUtils.escapeHtml(searchText), (emptyBreadcrumbs ? LAST_LINK_CLASS : "")); breadcrumbs.add(breadcrumb);/*from w w w . j ava2 s . com*/ } else { // Create category hierarchy path for breadcrumb final List<Breadcrumb> categoryBreadcrumbs = new ArrayList<>(); final Collection<CategoryModel> categoryModels = new ArrayList<>(); final CategoryModel lastCategoryModel = getCommerceCategoryService().getCategoryForCode(categoryCode); categoryModels.addAll(lastCategoryModel.getSupercategories()); categoryBreadcrumbs .add(getCategoryBreadcrumb(lastCategoryModel, (!emptyBreadcrumbs ? LAST_LINK_CLASS : ""))); while (!categoryModels.isEmpty()) { final CategoryModel categoryModel = categoryModels.iterator().next(); if (!(categoryModel instanceof ClassificationClassModel)) { if (categoryModel != null) { categoryBreadcrumbs.add(getCategoryBreadcrumb(categoryModel)); categoryModels.clear(); categoryModels.addAll(categoryModel.getSupercategories()); } } else { categoryModels.remove(categoryModel); } } Collections.reverse(categoryBreadcrumbs); breadcrumbs.addAll(categoryBreadcrumbs); } return breadcrumbs; }
From source file:org.apache.james.user.jdbc.AbstractJdbcUsersRepository.java
/** * Produces the complete list of User names, with correct case. * /*www. j ava 2 s . c o m*/ * @return a <code>List</code> of <code>String</code>s representing user * names. */ protected List<String> listUserNames() throws UsersRepositoryException { Collection<User> users = getAllUsers(); List<String> userNames = new ArrayList<String>(users.size()); for (User user : users) { userNames.add(user.getUserName()); } users.clear(); return userNames; }
From source file:com.epam.cme.storefront.breadcrumb.impl.SearchBreadcrumbBuilder.java
public List<Breadcrumb> getBreadcrumbs(final String categoryCode, final ProductSearchPageData<SearchStateData, ProductData> searchPageData) throws IllegalArgumentException { final List<Breadcrumb> breadcrumbs = new ArrayList<Breadcrumb>(); final boolean emptyBreadcrumbs = CollectionUtils.isEmpty(searchPageData.getBreadcrumbs()); Breadcrumb breadcrumb;/*from www .java 2 s . co m*/ if (categoryCode == null) { breadcrumb = new Breadcrumb("/search?text=" + getEncodedUrl(searchPageData.getFreeTextSearch()), StringEscapeUtils.escapeHtml(searchPageData.getFreeTextSearch()), (emptyBreadcrumbs ? LAST_LINK_CLASS : "")); breadcrumbs.add(breadcrumb); } else { // Create category hierarchy path for breadcrumb final List<Breadcrumb> categoryBreadcrumbs = new ArrayList<Breadcrumb>(); final Collection<CategoryModel> categoryModels = new ArrayList<CategoryModel>(); final CategoryModel lastCategoryModel = getCommerceCategoryService().getCategoryForCode(categoryCode); categoryModels.addAll(lastCategoryModel.getSupercategories()); categoryBreadcrumbs .add(getCategoryBreadcrumb(lastCategoryModel, (!emptyBreadcrumbs ? LAST_LINK_CLASS : ""))); while (!categoryModels.isEmpty()) { final CategoryModel categoryModel = categoryModels.iterator().next(); if (!(categoryModel instanceof ClassificationClassModel)) { if (categoryModel != null) { categoryBreadcrumbs.add(getCategoryBreadcrumb(categoryModel)); categoryModels.clear(); categoryModels.addAll(categoryModel.getSupercategories()); } } } Collections.reverse(categoryBreadcrumbs); breadcrumbs.addAll(categoryBreadcrumbs); } return breadcrumbs; }
From source file:com.exxonmobile.ace.hybris.storefront.breadcrumb.impl.SearchBreadcrumbBuilder.java
public List<Breadcrumb> getBreadcrumbs(final String categoryCode, final String searchText, final boolean emptyBreadcrumbs) throws IllegalArgumentException { final List<Breadcrumb> breadcrumbs = new ArrayList<Breadcrumb>(); if (categoryCode == null) { final Breadcrumb breadcrumb = new Breadcrumb("/search?text=" + getEncodedUrl(searchText), StringEscapeUtils.escapeHtml(searchText), (emptyBreadcrumbs ? LAST_LINK_CLASS : "")); breadcrumbs.add(breadcrumb);/*from w w w .j av a 2 s . c om*/ } else { // Create category hierarchy path for breadcrumb final List<Breadcrumb> categoryBreadcrumbs = new ArrayList<Breadcrumb>(); final Collection<CategoryModel> categoryModels = new ArrayList<CategoryModel>(); final CategoryModel lastCategoryModel = getCommerceCategoryService().getCategoryForCode(categoryCode); categoryModels.addAll(lastCategoryModel.getSupercategories()); categoryBreadcrumbs .add(getCategoryBreadcrumb(lastCategoryModel, (!emptyBreadcrumbs ? LAST_LINK_CLASS : ""))); while (!categoryModels.isEmpty()) { final CategoryModel categoryModel = categoryModels.iterator().next(); if (!(categoryModel instanceof ClassificationClassModel)) { if (categoryModel != null) { categoryBreadcrumbs.add(getCategoryBreadcrumb(categoryModel)); categoryModels.clear(); categoryModels.addAll(categoryModel.getSupercategories()); } } else { categoryModels.remove(categoryModel); } } Collections.reverse(categoryBreadcrumbs); breadcrumbs.addAll(categoryBreadcrumbs); } return breadcrumbs; }