@Test public void testOrderEntitiesByPrimaryKeys() { final List<Persistable> entities = new ArrayList<Persistable>(); final Persistable persistable1 = control.createMock(Persistable.class); final Persistable persistable2 = control.createMock(Persistable.class); final Persistable persistable3 = control.createMock(Persistable.class); CollectionUtils.addAll(entities, persistable1, persistable2, persistable3); final String pk1 = new String("pk1"); final String pk2 = new String("pk2"); final String pk3 = new String("pk3"); expect(persistable1.getPrimaryKey()).andReturn(pk1); expect(persistable2.getPrimaryKey()).andReturn(pk2); expect(persistable3.getPrimaryKey()).andReturn(pk3); final List<String> primaryKeys = new LinkedList<String>(); CollectionUtils.addAll(primaryKeys, pk1, pk3, pk2); control.replay(); final List<Persistable> orderedList = DaoUtils.orderEntitiesByPrimaryKeys(entities, primaryKeys); control.verify(); assertEquals(orderedList.get(0), persistable1); assertEquals(orderedList.get(1), persistable3); assertEquals(orderedList.get(2), persistable2); }
private void applySubsetRule(Map<String, List<Integer>> candidateDomVerMap) { List<String> removeKeyList = new ArrayList<String>(); Set<String> keySet = candidateDomVerMap.keySet(); for (String key1 : keySet) { byte[] keyArr1 = AlgorithmUtil.stringToBinaryArray(key1); List<Integer> keyList1 = AlgorithmUtil.binaryArrayToList(keyArr1); for (String key2 : keySet) { if (key1 != key2) { byte[] keyArr2 = AlgorithmUtil.stringToBinaryArray(key2); List<Integer> keyList2 = AlgorithmUtil.binaryArrayToList(keyArr2); if (CollectionUtils.isSubCollection(keyList1, keyList2)) { AlgorithmUtil.addElementToList(removeKeyList, key1); } else if (CollectionUtils.isSubCollection(keyList2, keyList1)) { AlgorithmUtil.addElementToList(removeKeyList, key2); } else { continue; } } } } for (String key : removeKeyList) { candidateDomVerMap.remove(key); } }
/** * Will copy into this Person, the details from the input Person. * * @param rs - The Person from which the details to be copied from. */ public void sync(final ResearchStaff rs) { super.sync(rs); setNciIdentifier(rs.getNciIdentifier()); if (getAddress() != null) { getAddress().sync(rs.getAddress()); } else { setAddress(rs.getAddress()); } // sync the site researchstaffs CollectionUtils.forAllDo( getSiteResearchStaffs(), new Closure<SiteResearchStaff>() { public void execute(SiteResearchStaff srs) { SiteResearchStaff otherSRS = rs.findSiteResearchStaff(srs); srs.sync(otherSRS); } }); // add new site researchstaff if needed for (SiteResearchStaff srs : rs.getSiteResearchStaffs()) { SiteResearchStaff availableSRS = findSiteResearchStaff(srs); if (availableSRS == null) addSiteResearchStaff(srs); } }
/** * Méthode en charge de mettre à jour les lignes de stock à partir des mouvements de stock de type * Sortie. La mise à jour concerne la quantité. * * @param essai Essai. * @param pharmacie Pharmacie. * @param produit Produit. * @param conditionnement Conditionnement. * @param mapLines Map des lignes de stock à mettre à jour. */ private void updateFromMvtTypeSortie( final MvtStockSearchCriteria critSortie, final Map<String, LigneStock> mapLines) { // Récupération des mouvements de type Sortie qui concernant l'essai, la // pharmacie, le // produit et le conditionnement critSortie.setTypesMouvement(TypeMvtStock.ALL_SORTIES); critSortie.setActiveOrder("datePeremption"); final List<MvtStock> sorties = this.mvtStockService.getAll(critSortie); // on ne traite pas ici les dispensations globales car elles ne sortent // pas du stocks. CollectionUtils.filter( sorties, new Predicate<MvtStock>() { @Override public boolean evaluate(final MvtStock object) { return !object.getType().equals(TypeMvtStock.DOTATION); } }); for (final MvtStock mvtStock : sorties) { final String key = this.getKeyMvtStock(mvtStock, false); if (mapLines.containsKey(key)) { final LigneStock ligneStock = mapLines.get(key); this.log.debug("Key: " + key + " objec: " + ligneStock); // Mise à jour de la quantité réelle en stock ligneStock.setQteGlobalStock(ligneStock.getQteGlobalStock() - mvtStock.getQuantite()); } else { this.log.error("Aucun Mvt d'entrée correspondant à la sortie - idMvt " + mvtStock.getId()); } } }
@Override public boolean evaluate(ConceptAnnotation annotation) { if (stycodeset.size() == 0) { return true; } else { Set<String> stycodes = JsonUtils.stringToMap(annotation.getStycodes()).keySet(); return (CollectionUtils.intersection(stycodeset, stycodes).size() > 0); } }
private void initLignesStockDispensationNominative(final Sortie sortie) { final MvtStock mvt = sortie.getMvtSortie(); final List<LigneStock> lignesStock = this.getAllLignesStock( mvt.getEssai(), mvt.getPharmacie(), mvt.getProduit(), mvt.getConditionnement(), false); // Filtre des stocks en quarantaine. org.apache.commons.collections15.CollectionUtils.filter( lignesStock, new NotPredicate<LigneStock>(new LigneStockEnQuarantainePredicate())); sortie.setLignesStock(lignesStock); }
/** * get a vertex from a list. * * <p>priority: 1. vertices in considerableCandidateVertices4DS; 2. vertices in vertex cover 3. * the highest degree one ; * * @param verList * @return */ private Integer getVertexFromCandiateMap(List<Integer> verList) { List<Integer> interConsider = (List<Integer>) CollectionUtils.intersection(verList, considerableCandidateVertices4DS); if (interConsider != null && !interConsider.isEmpty()) { return interConsider.get(0); } interConsider = (List<Integer>) CollectionUtils.intersection(verList, vertexCover); if (interConsider != null && !interConsider.isEmpty()) { return interConsider.get(0); } // List<VertexDegree> vdList = // AlgorithmUtil.sortVertexAccordingToDegreeInclude(this.g, verList); // return vdList.get(0).getVertex(); IPriorityOrder<Integer, String> pocb = new DegreeDesc<Integer, String>(); List<Integer> allVList = pocb.getOrderedVertexList(new PriorityBean<Integer, String>(g, null, null)); for (Integer v : allVList) { if (verList.contains(v)) { return v; } } return null; }
/** {@inheritDoc} */ @Override public List<LigneStock> getAllLignesStock( final Essai essai, final Pharmacie pharmacie, final Produit produit, final Conditionnement conditionnement, final Boolean dotations) { final MvtStockSearchCriteria criteria = new MvtStockSearchCriteria(); criteria.setEssai(essai); criteria.setPharmacie(pharmacie); criteria.setProduit(produit); criteria.setConditionnement(conditionnement); final List<LigneStock> resultWithNullStock = super.getAll(criteria); for (final LigneStock ligneStock : resultWithNullStock) { ligneStock.setDotation(dotations); } return new ArrayList<LigneStock>( CollectionUtils.select(resultWithNullStock, new LigneStockNonEpuisePredicate())); }
@Override public PartitionSet getWritePartitions(EstimationThresholds t) { return new PartitionSet(CollectionUtils.subtract(this.partitions, this.readonly)); }
private void getCandidateDomVerMap() throws ExceedLongMaxException { candidateDomVerMap = new LinkedHashMap<String, List<Integer>>(); // the vertex cover's complement set will be an independent set Collection<Integer> vertices = g.getVertices(); Collection<Integer> independentSet = CollectionUtils.subtract(vertices, vertexCover); /* * the vertex cover size will be the parameter k used in the fpt * algorithm */ int vertexCoverSize = vertexCover.size(); byte[] comparedRuler = new byte[vertexCoverSize]; Arrays.fill(comparedRuler, AlgorithmUtil.MARKED); for (Integer isv : independentSet) { Collection<Integer> neighOfIsv = g.getNeighbors(isv); byte ruler[] = new byte[vertexCoverSize]; // initilze the array with 0 Arrays.fill(ruler, AlgorithmUtil.UNMARKED); for (Integer neig : neighOfIsv) { /* * the position of the dominate vertex in the vertex cover will * set 1 */ int pos = vertexCover.indexOf(neig); if (pos != -1) { ruler[pos] = AlgorithmUtil.MARKED; } } // if (Arrays.equals(comparedRuler, ruler)) { // log.debug(isv + " dominates all vc"); // } String rulerStr = AlgorithmUtil.arrayToString(ruler); List<Integer> candidateDomVerSet = candidateDomVerMap.get(rulerStr); if (candidateDomVerSet == null) { candidateDomVerSet = new ArrayList<Integer>(); } // candidateDomVerSet.add(isv); AlgorithmUtil.addElementToList(candidateDomVerSet, isv); candidateDomVerMap.put(rulerStr, candidateDomVerSet); } /* * because the vertices in the vertex cover can also dominate other * vertices in the vertex cover,they are also considered */ for (Integer vcv : vertexCover) { Collection<Integer> neighOfVcv = g.getNeighbors(vcv); byte ruler[] = new byte[vertexCoverSize]; Arrays.fill(ruler, AlgorithmUtil.UNMARKED); // the vertex can dominated by itself int pos = vertexCover.indexOf(vcv); ruler[pos] = AlgorithmUtil.MARKED; for (Integer neig : neighOfVcv) { /* * the position of the dominate vertex in the vertex cover will * set 1 * * a neighbour of the vertex is likely not to be in the vertex * cover */ pos = vertexCover.indexOf(neig); if (pos != -1) { ruler[pos] = AlgorithmUtil.MARKED; } } // if (Arrays.equals(comparedRuler, ruler)) { // log.debug(vcv + " dominates all vc"); // } String rulerStr = AlgorithmUtil.arrayToString(ruler); List<Integer> candidateDomVerSet = candidateDomVerMap.get(rulerStr); if (candidateDomVerSet == null) { candidateDomVerSet = new ArrayList<Integer>(); } // candidateDomVerSet.add(vcv); AlgorithmUtil.addElementToList(candidateDomVerSet, vcv); candidateDomVerMap.put(rulerStr, candidateDomVerSet); } applySubsetRule(candidateDomVerMap); }
@RequestMapping(value = "/map.html") public ModelAndView map( @RequestParam(value = "q1", required = false) String q1, @RequestParam(value = "q2", required = false) String q2, @RequestParam(value = "q3", required = false) String q3, @RequestParam(value = "if", required = false, defaultValue = UimaUtils.MIMETYPE_STRING) String inputFormat, @RequestParam(value = "of", required = true, defaultValue = "html") String outputFormat, @RequestParam(value = "ofs", required = false, defaultValue = "pretty") String outputFormatStyle, @RequestParam(value = "sgf", required = false) String[] styGroupFilter, @RequestParam(value = "scf", required = false) String[] styCodeFilter) { ModelAndView mav = new ModelAndView(); mav.addObject("operation", "map"); // validate parameters (at least one of o, q, u or t must // be supplied, otherwise show the input form mav.addObject("q1", StringUtils.isEmpty(q1) ? "" : q1); mav.addObject("q2", StringUtils.isEmpty(q2) ? "" : q2); mav.addObject("q3", StringUtils.isEmpty(q3) ? "" : q3); String q = StringUtils.isNotEmpty(q1) ? q1 : StringUtils.isNotEmpty(q2) ? q2 : StringUtils.isNotEmpty(q3) ? q3 : null; if (StringUtils.isEmpty(q)) { setViewName(mav, outputFormat, outputFormatStyle); return mav; } try { if (NumberUtils.isNumber(q) && StringUtils.length(q) == 7) { return show(Integer.valueOf(q)); } else { // show list of concepts String text = q; if ((q.startsWith("http://") && UimaUtils.MIMETYPE_HTML.equals(inputFormat))) { URL u = new URL(q); BufferedReader br = new BufferedReader(new InputStreamReader(u.openStream())); StringBuilder tbuf = new StringBuilder(); String line = null; while ((line = br.readLine()) != null) { tbuf.append(line).append("\n"); } br.close(); text = tbuf.toString(); } List<ConceptAnnotation> annotations = new ArrayList<ConceptAnnotation>(); long startTs = System.currentTimeMillis(); JCas jcas = UimaUtils.runAE(conceptMappingAE, text, inputFormat, null); FSIndex fsindex = jcas.getAnnotationIndex(ConceptAnnotation.type); for (Iterator<ConceptAnnotation> it = fsindex.iterator(); it.hasNext(); ) { ConceptAnnotation annotation = it.next(); annotations.add(annotation); } CollectionUtils.filter(annotations, new StyGroupPredicate(styGroupFilter)); CollectionUtils.filter(annotations, new StyCodePredicate(styCodeFilter)); annotations = filterSubsumedConcepts(q, annotations); if (annotations.size() == 0) { mav.addObject("error", "No concepts found"); } else { mav.addObject("text", text); mav.addObject("annotations", annotations); long endTs = System.currentTimeMillis(); mav.addObject("elapsed", new Long(endTs - startTs)); } setViewName(mav, outputFormat, outputFormatStyle); } } catch (Exception e) { mav.addObject("error", e.getMessage()); setViewName(mav, outputFormat, outputFormatStyle); } return mav; }