List of usage examples for org.apache.commons.collections CollectionUtils union
public static Collection union(final Collection a, final Collection b)
From source file:org.amanzi.neo.loader.core.synonyms.SynonymsManager.java
@SuppressWarnings("unchecked") public void updateSynonyms(final String synonymsType, final INodeType nodeType, final String propertyName, final String[] updatedSynonyms) { List<Synonyms> previousList = getSynonyms(synonymsType, nodeType); for (Synonyms singleSynonym : previousList) { if (singleSynonym.getPropertyName().equals(propertyName)) { Collection<String> previousSynonyms = Arrays.asList(singleSynonym.getPossibleHeaders()); Collection<String> newSynonyms = Arrays.asList(updatedSynonyms); Collection<String> resultedSynonyms = CollectionUtils.union(previousSynonyms, newSynonyms); singleSynonym.setPossibleHeaders(resultedSynonyms.toArray(new String[resultedSynonyms.size()])); }/* ww w. j a v a2s.c o m*/ } }
From source file:org.apache.hadoop.hbase.regionserver.indexed.IndexFilterEvaluator.java
@SuppressWarnings("unchecked") private List<KeyValue> evaluate(Map<Pair, List<StoreFile>> indexMap, FilterList filterList) throws IOException { List<KeyValue> result = null; if (filterList.getOperator() == FilterList.Operator.MUST_PASS_ALL) { for (Filter filter : filterList.getFilters()) { List<KeyValue> childResult = evaluate(indexMap, filter); if (result == null) { result = childResult;/*from w w w . ja v a2 s. c o m*/ } else if (childResult != null) { result = (ArrayList<KeyValue>) CollectionUtils.intersection(result, childResult); } } } else if (filterList.getOperator() == FilterList.Operator.MUST_PASS_ONE) { for (Filter filter : filterList.getFilters()) { List<KeyValue> childResult = evaluate(indexMap, filter); if (result == null) { result = childResult; } else if (childResult != null) { result = (ArrayList<KeyValue>) CollectionUtils.union(result, childResult); } } } return result; }
From source file:org.apache.nutch.api.impl.NutchServerPoolExecutor.java
@SuppressWarnings("unchecked") public Collection<JobInfo> getAllJobs() { return CollectionUtils.union(getJobRunning(), getJobHistory()); }
From source file:org.apache.nutch.service.impl.NutchServerPoolExecutor.java
/** * Gives all jobs(currently running and completed) * @return/*from www . j av a 2 s . c o m*/ */ @SuppressWarnings("unchecked") public Collection<JobInfo> getAllJobs() { return CollectionUtils.union(getJobRunning(), getJobHistory()); }
From source file:org.apache.sysml.runtime.controlprogram.parfor.RemoteParForSparkWorker.java
private void configureWorker(long taskID) throws DMLRuntimeException, IOException { _workerID = taskID;//from www. j av a 2 s. c o m //initialize codegen class cache (before program parsing) for (Entry<String, byte[]> e : _clsMap.entrySet()) CodegenUtils.getClassSync(e.getKey(), e.getValue()); //parse and setup parfor body program ParForBody body = ProgramConverter.parseParForBody(_prog, (int) _workerID); _childBlocks = body.getChildBlocks(); _ec = body.getEc(); _resultVars = body.getResultVarNames(); _numTasks = 0; _numIters = 0; //reuse shared inputs (to read shared inputs once per process instead of once per core; //we reuse everything except result variables and partitioned input matrices) _ec.pinVariables(_ec.getVarList()); //avoid cleanup of shared inputs Collection<String> blacklist = CollectionUtils.union(_resultVars, _ec.getVarListPartitioned()); reuseVars.reuseVariables(_jobid, _ec.getVariables(), blacklist); //init and register-cleanup of buffer pool (in parfor spark, multiple tasks might //share the process-local, i.e., per executor, buffer pool; hence we synchronize //the initialization and immediately register the created directory for cleanup //on process exit, i.e., executor exit, including any files created in the future. synchronized (CacheableData.class) { if (!CacheableData.isCachingActive() && !InfrastructureAnalyzer.isLocalMode()) { //create id, executor working dir, and cache dir String uuid = IDHandler.createDistributedUniqueID(); LocalFileUtils.createWorkingDirectoryWithUUID(uuid); CacheableData.initCaching(uuid); //incl activation and cache dir creation CacheableData.cacheEvictionLocalFilePrefix = CacheableData.cacheEvictionLocalFilePrefix + "_" + _workerID; //register entire working dir for delete on shutdown RemoteParForUtils.cleanupWorkingDirectoriesOnShutdown(); } } //ensure that resultvar files are not removed super.pinResultVariables(); //enable/disable caching (if required and not in CP process) if (!_caching && !InfrastructureAnalyzer.isLocalMode()) CacheableData.disableCaching(); //mark as initialized _initialized = true; }
From source file:org.apache.sysml.runtime.transform.decode.DecoderFactory.java
@SuppressWarnings("unchecked") public static Decoder createDecoder(String spec, String[] colnames, ValueType[] schema, FrameBlock meta) throws DMLRuntimeException { Decoder decoder = null;//from w ww. j av a 2 s . c o m try { //parse transform specification JSONObject jSpec = new JSONObject(spec); List<Decoder> ldecoders = new ArrayList<Decoder>(); //create decoders 'recode', 'dummy' and 'pass-through' List<Integer> rcIDs = Arrays.asList( ArrayUtils.toObject(TfMetaUtils.parseJsonIDList(jSpec, colnames, TfUtils.TXMETHOD_RECODE))); List<Integer> dcIDs = Arrays.asList( ArrayUtils.toObject(TfMetaUtils.parseJsonIDList(jSpec, colnames, TfUtils.TXMETHOD_DUMMYCODE))); rcIDs = new ArrayList<Integer>(CollectionUtils.union(rcIDs, dcIDs)); List<Integer> ptIDs = new ArrayList<Integer>( CollectionUtils.subtract(UtilFunctions.getSequenceList(1, meta.getNumColumns(), 1), rcIDs)); //create default schema if unspecified (with double columns for pass-through) if (schema == null) { schema = UtilFunctions.nCopies(meta.getNumColumns(), ValueType.STRING); for (Integer col : ptIDs) schema[col - 1] = ValueType.DOUBLE; } if (!dcIDs.isEmpty()) { ldecoders.add(new DecoderDummycode(schema, ArrayUtils.toPrimitive(dcIDs.toArray(new Integer[0])))); } if (!rcIDs.isEmpty()) { ldecoders.add(new DecoderRecode(schema, !dcIDs.isEmpty(), ArrayUtils.toPrimitive(rcIDs.toArray(new Integer[0])))); } if (!ptIDs.isEmpty()) { ldecoders.add(new DecoderPassThrough(schema, ArrayUtils.toPrimitive(ptIDs.toArray(new Integer[0])), ArrayUtils.toPrimitive(dcIDs.toArray(new Integer[0])))); } //create composite decoder of all created decoders //and initialize with given meta data (recode, dummy, bin) decoder = new DecoderComposite(schema, ldecoders); if (meta != null) decoder.initMetaData(meta); } catch (Exception ex) { throw new DMLRuntimeException(ex); } return decoder; }
From source file:org.apache.sysml.runtime.transform.encode.EncoderFactory.java
@SuppressWarnings("unchecked") public static Encoder createEncoder(String spec, String[] colnames, ValueType[] schema, FrameBlock meta) throws DMLRuntimeException { Encoder encoder = null;/*w w w . j av a 2 s . c om*/ int clen = schema.length; try { //parse transform specification JSONObject jSpec = new JSONObject(spec); List<Encoder> lencoders = new ArrayList<Encoder>(); //prepare basic id lists (recode, dummycode, pass-through) //note: any dummycode column requires recode as preparation List<Integer> rcIDs = Arrays.asList( ArrayUtils.toObject(TfMetaUtils.parseJsonIDList(jSpec, colnames, TfUtils.TXMETHOD_RECODE))); List<Integer> dcIDs = Arrays.asList( ArrayUtils.toObject(TfMetaUtils.parseJsonIDList(jSpec, colnames, TfUtils.TXMETHOD_DUMMYCODE))); rcIDs = new ArrayList<Integer>(CollectionUtils.union(rcIDs, dcIDs)); List<Integer> binIDs = TfMetaUtils.parseBinningColIDs(jSpec, colnames); List<Integer> ptIDs = new ArrayList<Integer>(CollectionUtils .subtract(CollectionUtils.subtract(UtilFunctions.getSequenceList(1, clen, 1), rcIDs), binIDs)); List<Integer> oIDs = Arrays.asList( ArrayUtils.toObject(TfMetaUtils.parseJsonIDList(jSpec, colnames, TfUtils.TXMETHOD_OMIT))); List<Integer> mvIDs = Arrays.asList(ArrayUtils .toObject(TfMetaUtils.parseJsonObjectIDList(jSpec, colnames, TfUtils.TXMETHOD_IMPUTE))); //create individual encoders if (!rcIDs.isEmpty()) { RecodeAgent ra = new RecodeAgent(jSpec, colnames, clen); ra.setColList(ArrayUtils.toPrimitive(rcIDs.toArray(new Integer[0]))); lencoders.add(ra); } if (!ptIDs.isEmpty()) lencoders.add(new EncoderPassThrough(ArrayUtils.toPrimitive(ptIDs.toArray(new Integer[0])), clen)); if (!dcIDs.isEmpty()) lencoders.add(new DummycodeAgent(jSpec, colnames, schema.length)); if (!binIDs.isEmpty()) lencoders.add(new BinAgent(jSpec, colnames, schema.length, true)); if (!oIDs.isEmpty()) lencoders.add(new OmitAgent(jSpec, colnames, schema.length)); if (!mvIDs.isEmpty()) { MVImputeAgent ma = new MVImputeAgent(jSpec, colnames, schema.length); ma.initRecodeIDList(rcIDs); lencoders.add(ma); } //create composite decoder of all created encoders //and initialize meta data (recode, dummy, bin, mv) encoder = new EncoderComposite(lencoders); if (meta != null) encoder.initMetaData(meta); } catch (Exception ex) { throw new DMLRuntimeException(ex); } return encoder; }
From source file:org.apache.sysml.runtime.transform.meta.TfMetaUtils.java
/** * Parses the given json specification and extracts a list of column ids * that are subject to recoding.//from w w w. j av a 2 s .c om * * @param spec transform specification as json string * @param colnames column names * @return list of column ids * @throws IOException if IOException occurs */ @SuppressWarnings("unchecked") private static List<Integer> parseRecodeColIDs(String spec, String[] colnames) throws IOException { if (spec == null) throw new IOException("Missing transform specification."); List<Integer> specRecodeIDs = null; try { //parse json transform specification for recode col ids JSONObject jSpec = new JSONObject(spec); List<Integer> rcIDs = Arrays.asList( ArrayUtils.toObject(TfMetaUtils.parseJsonIDList(jSpec, colnames, TfUtils.TXMETHOD_RECODE))); List<Integer> dcIDs = Arrays.asList( ArrayUtils.toObject(TfMetaUtils.parseJsonIDList(jSpec, colnames, TfUtils.TXMETHOD_DUMMYCODE))); specRecodeIDs = new ArrayList<Integer>(CollectionUtils.union(rcIDs, dcIDs)); } catch (Exception ex) { throw new IOException(ex); } return specRecodeIDs; }
From source file:org.beanfuse.lang.SeqStringUtil.java
/** * delimiter?????"??"?./*ww w . j a v a 2 s . c o m*/ * delimiterdelimiter<br> * ???delimiter.<br> * <p> * <blockquote> * * <pre> * mergeSeq(",1,2,", "") = ",1,2,"; * mergeSeq(",1,2,", null) = ",1,2,"; * mergeSeq("1,2", "3") = "1,2,3"; * mergeSeq("1,2", "3,") = "1,2,3,"; * mergeSeq(",1,2", "3,") = ",1,2,3,"; * mergeSeq(",1,2,", ",3,") = ",1,2,3,"; * </pre> * * </blockquote> * <p> * * @param first * @param second * @return */ public static String mergeSeq(final String first, final String second, final String delimiter) { if (StringUtils.isNotEmpty(second) && StringUtils.isNotEmpty(first)) { List firstSeq = Arrays.asList(StringUtils.split(first, delimiter)); List secondSeq = Arrays.asList(StringUtils.split(second, delimiter)); Collection rs = CollectionUtils.union(firstSeq, secondSeq); StringBuilder buf = new StringBuilder(); for (Iterator iter = rs.iterator(); iter.hasNext();) { String ele = (String) iter.next(); buf.append(delimiter).append(ele); } if (buf.length() > 0) { buf.append(delimiter); } return buf.toString(); } else { return ((first == null) ? "" : first) + ((second == null) ? "" : second); } }
From source file:org.beangle.commons.lang.StrUtils.java
/** * delimiter?????"??"?./* w w w . j a v a 2s . c o m*/ * delimiterdelimiter<br> * ???delimiter.<br> * <p> * <blockquote> * * <pre> * mergeSeq(",1,2,", "") = ",1,2,"; * mergeSeq(",1,2,", null) = ",1,2,"; * mergeSeq("1,2", "3") = "1,2,3"; * mergeSeq("1,2", "3,") = "1,2,3,"; * mergeSeq(",1,2", "3,") = ",1,2,3,"; * mergeSeq(",1,2,", ",3,") = ",1,2,3,"; * </pre> * * </blockquote> * <p> * * @param first * @param second * @return */ public static String mergeSeq(final String first, final String second, final String delimiter) { if (StringUtils.isNotEmpty(second) && StringUtils.isNotEmpty(first)) { List<String> firstSeq = Arrays.asList(StringUtils.split(first, delimiter)); List<String> secondSeq = Arrays.asList(StringUtils.split(second, delimiter)); @SuppressWarnings("unchecked") Collection<String> rs = CollectionUtils.union(firstSeq, secondSeq); StringBuilder buf = new StringBuilder(); for (final String ele : rs) { buf.append(delimiter).append(ele); } if (buf.length() > 0) { buf.append(delimiter); } return buf.toString(); } else { return ((first == null) ? "" : first) + ((second == null) ? "" : second); } }