List of usage examples for java.util LinkedHashSet add
boolean add(E e);
From source file:org.apache.tajo.plan.rewrite.rules.ProjectionPushDownRule.java
public LogicalNode visitJoin(Context context, LogicalPlan plan, LogicalPlan.QueryBlock block, JoinNode node, Stack<LogicalNode> stack) throws TajoException { Context newContext = new Context(context); String joinQualReference = null; if (node.hasJoinQual()) { for (EvalNode eachQual : AlgebraicUtil.toConjunctiveNormalFormArray(node.getJoinQual())) { if (eachQual instanceof BinaryEval) { BinaryEval binaryQual = (BinaryEval) eachQual; for (int i = 0; i < 2; i++) { EvalNode term = binaryQual.getChild(i); pushDownIfComplexTermInJoinCondition(newContext, eachQual, term); }/* ww w. jav a2s. c o m*/ } } joinQualReference = newContext.addExpr(node.getJoinQual()); newContext.addNecessaryReferences(node.getJoinQual()); } String[] referenceNames = null; if (node.hasTargets()) { referenceNames = new String[node.getTargets().size()]; int i = 0; for (Iterator<Target> it = getFilteredTarget(node.getTargets(), context.requiredSet); it.hasNext();) { Target target = it.next(); referenceNames[i++] = newContext.addExpr(target); } } stack.push(node); LogicalNode left = visit(newContext, plan, block, node.getLeftChild(), stack); LogicalNode right = visit(newContext, plan, block, node.getRightChild(), stack); stack.pop(); Schema merged = SchemaUtil.merge(left.getOutSchema(), right.getOutSchema()); node.setInSchema(merged); if (node.hasJoinQual()) { Target target = context.targetListMgr.getTarget(joinQualReference); if (newContext.targetListMgr.isEvaluated(joinQualReference)) { throw new TajoInternalError( "Join condition must be evaluated in the proper Join Node: " + joinQualReference); } else { node.setJoinQual(target.getEvalTree()); newContext.targetListMgr.markAsEvaluated(target); } } LinkedHashSet<Target> projectedTargets = Sets.newLinkedHashSet(); for (Iterator<String> it = getFilteredReferences(context.targetListMgr.getNames(), context.requiredSet); it .hasNext();) { String referenceName = it.next(); Target target = context.targetListMgr.getTarget(referenceName); if (context.targetListMgr.isEvaluated(referenceName)) { Target fieldReference = new Target(new FieldEval(target.getNamedColumn())); // here, we assume that every exprs are specified at the on clause // because all filters have been moved to appropriate logical nodes during the filter push down phase if (LogicalPlanner.checkIfBeEvaluatedAtJoin(block, fieldReference.getEvalTree(), node, stack.peek().getType() != NodeType.JOIN)) { projectedTargets.add(fieldReference); } } else if (LogicalPlanner.checkIfBeEvaluatedAtJoin(block, target.getEvalTree(), node, stack.peek().getType() != NodeType.JOIN)) { projectedTargets.add(target); context.targetListMgr.markAsEvaluated(target); } } node.setTargets(new ArrayList<>(projectedTargets)); LogicalPlanner.verifyProjectedFields(block, node); return node; }
From source file:org.apache.ws.scout.registry.BusinessLifeCycleManagerImpl.java
public BulkResponse saveServices(Collection services) throws JAXRException { BulkResponseImpl bulk = new BulkResponseImpl(); BusinessService[] sarr = new BusinessService[services.size()]; LinkedHashSet<Key> coll = new LinkedHashSet<Key>(); Collection<Exception> exceptions = new ArrayList<Exception>(); Iterator iter = services.iterator(); int currLoc = 0; while (iter.hasNext()) { try {//from ww w .ja va2s .co m BusinessService bs = ScoutJaxrUddiHelper.getBusinessServiceFromJAXRService((Service) iter.next()); sarr[currLoc] = bs; currLoc++; } catch (ClassCastException ce) { throw new UnexpectedObjectException(); } } // Save Service ServiceDetail sd = null; try { sd = (ServiceDetail) executeOperation(sarr, "SAVE_SERVICE"); } catch (RegistryException e) { exceptions.add(new SaveException(e.getLocalizedMessage())); bulk.setStatus(JAXRResponse.STATUS_FAILURE); return bulk; } List<BusinessService> bizServiceList = sd.getBusinessService(); sarr = new BusinessService[bizServiceList.size()]; bizServiceList.toArray(sarr); for (int i = 0; sarr != null && i < sarr.length; i++) { BusinessService entity = (BusinessService) sarr[i]; coll.add(new KeyImpl(entity.getServiceKey())); } bulk.setCollection(coll); bulk.setExceptions(exceptions); return bulk; }
From source file:cross.io.InputDataFactory.java
/** * Create a collection of files from the given string resource paths. * * @param input the string resource paths * @return a collection of files/*from w w w . j a v a 2 s. co m*/ */ @Override public Collection<File> getInputFiles(String[] input) { LinkedHashSet<File> files = new LinkedHashSet<>(); for (String inputString : input) { log.debug("Processing input string {}", inputString); //separate wildcards from plain files String name = FilenameUtils.getName(inputString); boolean isWildcard = name.contains("?") || name.contains("*"); String fullPath = FilenameUtils.getFullPath(inputString); File path = new File(fullPath); File baseDirFile = new File(this.basedir); if (!baseDirFile.exists()) { throw new ExitVmException("Input base directory '" + baseDirFile + "' does not exist!"); } if (!baseDirFile.isDirectory()) { throw new ExitVmException("Input base directory '" + baseDirFile + "' is not a directory!"); } log.debug("Path is absolute: {}", path.isAbsolute()); //identify absolute and relative files if (!path.isAbsolute()) { log.info("Resolving relative file against basedir: {}", this.basedir); path = new File(this.basedir, fullPath); } //normalize filenames fullPath = FilenameUtils.normalize(path.getAbsolutePath()); log.debug("After normalization: {}", fullPath); IOFileFilter dirFilter = this.recurse ? TrueFileFilter.INSTANCE : null; if (isWildcard) { log.debug("Using wildcard matcher for {}", name); files.addAll(FileUtils.listFiles(new File(fullPath), new WildcardFileFilter(name, IOCase.INSENSITIVE), dirFilter)); } else { log.debug("Using name for {}", name); File f = new File(fullPath, name); if (!f.exists()) { throw new ExitVmException("Input file '" + f + "' does not exist!"); } files.add(f); } } return files; }
From source file:org.apache.ws.scout.registry.BusinessLifeCycleManagerV3Impl.java
public BulkResponse saveServices(Collection services) throws JAXRException { BulkResponseImpl bulk = new BulkResponseImpl(); BusinessService[] sarr = new BusinessService[services.size()]; LinkedHashSet<Key> coll = new LinkedHashSet<Key>(); Collection<Exception> exceptions = new ArrayList<Exception>(); Iterator iter = services.iterator(); int currLoc = 0; while (iter.hasNext()) { try {// w ww .j ava2 s .com BusinessService bs = ScoutJaxrUddiV3Helper.getBusinessServiceFromJAXRService((Service) iter.next()); sarr[currLoc] = bs; currLoc++; } catch (ClassCastException ce) { throw new UnexpectedObjectException(); } } // Save Service ServiceDetail sd = null; try { sd = (ServiceDetail) executeOperation(sarr, "SAVE_SERVICE"); } catch (RegistryV3Exception e) { exceptions.add(new SaveException(e.getLocalizedMessage())); bulk.setStatus(JAXRResponse.STATUS_FAILURE); return bulk; } List<BusinessService> bizServiceList = sd.getBusinessService(); sarr = new BusinessService[bizServiceList.size()]; bizServiceList.toArray(sarr); for (int i = 0; sarr != null && i < sarr.length; i++) { BusinessService entity = (BusinessService) sarr[i]; coll.add(new KeyImpl(entity.getServiceKey())); } bulk.setCollection(coll); bulk.setExceptions(exceptions); return bulk; }
From source file:org.apache.ws.scout.registry.BusinessLifeCycleManagerImpl.java
public BulkResponse saveServiceBindings(Collection bindings) throws JAXRException { BulkResponseImpl bulk = new BulkResponseImpl(); BindingTemplate[] sbarr = new BindingTemplate[bindings.size()]; LinkedHashSet<Key> coll = new LinkedHashSet<Key>(); Collection<Exception> exceptions = new ArrayList<Exception>(); Iterator iter = bindings.iterator(); int currLoc = 0; while (iter.hasNext()) { try {/*from w ww . ja v a2 s. com*/ BindingTemplate bs = ScoutJaxrUddiHelper.getBindingTemplateFromJAXRSB((ServiceBinding) iter.next()); sbarr[currLoc] = bs; currLoc++; } catch (ClassCastException ce) { throw new UnexpectedObjectException(); } } // Save ServiceBinding BindingDetail bd = null; try { bd = (BindingDetail) executeOperation(sbarr, "SAVE_SERVICE_BINDING"); } catch (RegistryException e) { exceptions.add(new SaveException(e.getLocalizedMessage())); bulk.setStatus(JAXRResponse.STATUS_FAILURE); return bulk; } List<BindingTemplate> bindingTemplateList = bd.getBindingTemplate(); sbarr = new BindingTemplate[bindingTemplateList.size()]; bindingTemplateList.toArray(sbarr); for (int i = 0; sbarr != null && i < sbarr.length; i++) { BindingTemplate bt = (BindingTemplate) sbarr[i]; coll.add(new KeyImpl(bt.getBindingKey())); } if (coll.size() > 0) { bulk.setCollection(coll); } bulk.setExceptions(exceptions); return bulk; }
From source file:org.apache.tajo.engine.planner.LogicalPlanner.java
public TableSubQueryNode visitTableSubQuery(PlanContext context, Stack<Expr> stack, TablePrimarySubQuery expr) throws PlanningException { QueryBlock block = context.queryBlock; QueryBlock childBlock = context.plan.getBlock(context.plan.getBlockNameByExpr(expr.getSubQuery())); PlanContext newContext = new PlanContext(context, childBlock); LogicalNode child = visit(newContext, new Stack<Expr>(), expr.getSubQuery()); TableSubQueryNode subQueryNode = context.queryBlock.getNodeFromExpr(expr); context.plan.connectBlocks(childBlock, context.queryBlock, BlockType.TableSubQuery); subQueryNode.setSubQuery(child);//from www . ja v a 2s. co m // Add additional expressions required in upper nodes. Set<String> newlyEvaluatedExprs = TUtil.newHashSet(); for (NamedExpr rawTarget : block.namedExprsMgr.getAllNamedExprs()) { try { EvalNode evalNode = exprAnnotator.createEvalNode(context, rawTarget.getExpr(), NameResolvingMode.RELS_ONLY); if (checkIfBeEvaluatedAtRelation(block, evalNode, subQueryNode)) { block.namedExprsMgr.markAsEvaluated(rawTarget.getAlias(), evalNode); newlyEvaluatedExprs.add(rawTarget.getAlias()); // newly added exr } } catch (VerifyException ve) { } } // Assume that each unique expr is evaluated once. LinkedHashSet<Target> targets = createFieldTargetsFromRelation(block, subQueryNode, newlyEvaluatedExprs); for (String newAddedExpr : newlyEvaluatedExprs) { targets.add(block.namedExprsMgr.getTarget(newAddedExpr, true)); } subQueryNode.setTargets(targets.toArray(new Target[targets.size()])); return subQueryNode; }
From source file:org.apache.ws.scout.registry.BusinessLifeCycleManagerV3Impl.java
public BulkResponse saveServiceBindings(Collection bindings) throws JAXRException { BulkResponseImpl bulk = new BulkResponseImpl(); BindingTemplate[] sbarr = new BindingTemplate[bindings.size()]; LinkedHashSet<Key> coll = new LinkedHashSet<Key>(); Collection<Exception> exceptions = new ArrayList<Exception>(); Iterator iter = bindings.iterator(); int currLoc = 0; while (iter.hasNext()) { try {// w ww . j a v a 2 s . c o m BindingTemplate bs = ScoutJaxrUddiV3Helper .getBindingTemplateFromJAXRSB((ServiceBinding) iter.next()); sbarr[currLoc] = bs; currLoc++; } catch (ClassCastException ce) { throw new UnexpectedObjectException(); } } // Save ServiceBinding BindingDetail bd = null; try { bd = (BindingDetail) executeOperation(sbarr, "SAVE_SERVICE_BINDING"); } catch (RegistryV3Exception e) { exceptions.add(new SaveException(e.getLocalizedMessage())); bulk.setStatus(JAXRResponse.STATUS_FAILURE); return bulk; } List<BindingTemplate> bindingTemplateList = bd.getBindingTemplate(); sbarr = new BindingTemplate[bindingTemplateList.size()]; bindingTemplateList.toArray(sbarr); for (int i = 0; sbarr != null && i < sbarr.length; i++) { BindingTemplate bt = (BindingTemplate) sbarr[i]; coll.add(new KeyImpl(bt.getBindingKey())); } if (coll.size() > 0) { bulk.setCollection(coll); } bulk.setExceptions(exceptions); return bulk; }
From source file:org.opencb.opencga.storage.core.variant.io.VariantVcfDataWriter.java
@Override public boolean pre() { LinkedHashSet<VCFHeaderLine> meta = new LinkedHashSet<>(); sampleNames.clear();/*from w w w . j a va 2 s.co m*/ sampleNames.addAll(getSamples()); logger.info("Use {} samples for export ... ", this.sampleNames.size()); sampleNameMapping.putAll( sampleNames.stream().collect(Collectors.toMap(s -> s, s -> sampleNameConverter.get().apply(s)))); List<String> names = sampleNames.stream().map(s -> sampleNameMapping.get(s)).collect(Collectors.toList()); logger.info("Samples mapped: {} ... ", names.size()); // Iterator<VariantSource> iterator = sourceDBAdaptor.iterator( // new Query(VariantStorageEngine.Options.STUDY_ID.key(), studyConfiguration.getStudyId()), // new QueryOptions()); // if (iterator.hasNext()) { // VariantSource source = iterator.next(); // fileHeader = source.getMetadata().get(VariantFileUtils.VARIANT_FILE_HEADER).toString(); // } else { // throw new IllegalStateException("file headers not available for study " + studyConfiguration.getStudyName() // + ". note: check files: " + studyConfiguration.getFileIds().values().toString()); // } /* FILTER */ meta.add(new VCFFilterHeaderLine("PASS", "Valid variant")); meta.add(new VCFFilterHeaderLine(".", "No FILTER info")); /* INFO */ meta.add(new VCFInfoHeaderLine("PR", 1, VCFHeaderLineType.Float, "Pass rate")); meta.add(new VCFInfoHeaderLine("CR", 1, VCFHeaderLineType.Float, "Call rate")); meta.add(new VCFInfoHeaderLine("OPR", 1, VCFHeaderLineType.Float, "Overall Pass rate")); addCohortInfo(meta); addAnnotationInfo(meta); /* FORMAT */ meta.add(new VCFFormatHeaderLine("GT", 1, VCFHeaderLineType.String, "Genotype")); meta.add(new VCFFormatHeaderLine("PF", 1, VCFHeaderLineType.Integer, "Variant was PASS (1) filter in original vcf")); final VCFHeader header = new VCFHeader(meta, names); final SAMSequenceDictionary sequenceDictionary = header.getSequenceDictionary(); // setup writer VariantContextWriterBuilder builder = new VariantContextWriterBuilder().setOutputStream(outputStream) .setReferenceDictionary(sequenceDictionary).unsetOption(Options.INDEX_ON_THE_FLY); if (sampleNames.isEmpty() || !this.exportGenotype.get()) { builder.setOption(Options.DO_NOT_WRITE_GENOTYPES); } List<String> formatFields = studyConfiguration.getAttributes() .getAsStringList(VariantStorageEngine.Options.EXTRA_GENOTYPE_FIELDS.key()); List<String> formatFieldsType = studyConfiguration.getAttributes() .getAsStringList(VariantStorageEngine.Options.EXTRA_GENOTYPE_FIELDS_TYPE.key()); for (int i = 0; i < formatFields.size(); i++) { String id = formatFields.get(i); if (header.getFormatHeaderLine(id) == null) { header.addMetaDataLine( new VCFFormatHeaderLine(id, 1, VCFHeaderLineType.valueOf(formatFieldsType.get(i)), "")); } } writer = builder.build(); writer.writeHeader(header); return true; }
From source file:org.apache.ws.scout.registry.BusinessLifeCycleManagerImpl.java
public BulkResponse saveConcepts(Collection concepts) throws JAXRException { //Now we need to convert the collection into a vector for juddi BulkResponseImpl bulk = new BulkResponseImpl(); TModel[] entityarr = new TModel[concepts.size()]; LinkedHashSet<Key> coll = new LinkedHashSet<Key>(); Collection<Exception> exceptions = new ArrayList<Exception>(); Iterator iter = concepts.iterator(); int currLoc = 0; while (iter.hasNext()) { try {/*from ww w .ja v a2s . c o m*/ TModel en = ScoutJaxrUddiHelper.getTModelFromJAXRConcept((Concept) iter.next()); entityarr[currLoc] = en; currLoc++; } catch (ClassCastException ce) { throw new UnexpectedObjectException(); } } log.debug("Method:save_concept: ENlength=" + entityarr.length); // Save business TModelDetail td = null; try { td = (TModelDetail) executeOperation(entityarr, "SAVE_TMODEL"); } catch (RegistryException e) { exceptions.add(new SaveException(e.getLocalizedMessage())); bulk.setStatus(JAXRResponse.STATUS_FAILURE); return bulk; } List<TModel> tmodelList = td.getTModel(); entityarr = new TModel[tmodelList.size()]; tmodelList.toArray(entityarr); log.debug("After Saving TModel. Obtained vector size:" + entityarr != null ? entityarr.length : 0); for (int i = 0; entityarr != null && i < entityarr.length; i++) { TModel tm = (TModel) entityarr[i]; coll.add(new KeyImpl(tm.getTModelKey())); } bulk.setCollection(coll); bulk.setExceptions(exceptions); return bulk; }
From source file:org.apache.ws.scout.registry.BusinessQueryManagerImpl.java
public BulkResponse findAssociations(Collection findQualifiers, String sourceObjectId, String targetObjectId, Collection associationTypes) throws JAXRException { //TODO: Currently we just return all the Association objects owned by the caller IRegistry registry = (IRegistry) registryService.getRegistry(); try {//from ww w . jav a 2 s . c o m ConnectionImpl con = ((RegistryServiceImpl) getRegistryService()).getConnection(); AuthToken auth = this.getAuthToken(con, registry); PublisherAssertions result = null; try { result = registry.getPublisherAssertions(auth.getAuthInfo()); } catch (RegistryException rve) { String username = getUsernameFromCredentials(con.getCredentials()); if (AuthTokenSingleton.getToken(username) != null) { AuthTokenSingleton.deleteAuthToken(username); } auth = getAuthToken(con, registry); result = registry.getPublisherAssertions(auth.getAuthInfo()); } List<PublisherAssertion> publisherAssertionList = result.getPublisherAssertion(); LinkedHashSet<Association> col = new LinkedHashSet<Association>(); for (PublisherAssertion pas : publisherAssertionList) { String sourceKey = pas.getFromKey(); String targetKey = pas.getToKey(); if ((sourceObjectId == null || sourceObjectId.equals(sourceKey)) && (targetObjectId == null || targetObjectId.equals(targetKey))) { Collection<Key> orgcol = new ArrayList<Key>(); orgcol.add(new KeyImpl(sourceKey)); orgcol.add(new KeyImpl(targetKey)); BulkResponse bl = getRegistryObjects(orgcol, LifeCycleManager.ORGANIZATION); Association asso = ScoutUddiJaxrHelper.getAssociation(bl.getCollection(), registryService.getBusinessLifeCycleManager()); KeyedReference keyr = pas.getKeyedReference(); Concept c = new ConceptImpl(getRegistryService().getBusinessLifeCycleManager()); c.setName(new InternationalStringImpl(keyr.getKeyName())); c.setKey(new KeyImpl(keyr.getTModelKey())); c.setValue(keyr.getKeyValue()); asso.setAssociationType(c); col.add(asso); } } return new BulkResponseImpl(col); } catch (RegistryException e) { throw new JAXRException(e); } }