List of usage examples for java.util Collection clear
void clear();
From source file:com.samsung.sjs.theorysolver.TheorySolver.java
/** * Given a fixing set finder, a solver for some particular theory, and some constraints, * this procedure either finds a model or it finds a minimum set of constraints * which, if broken, make the system satisfiable (a "fixing set"). * * <p>A <em>theory</em> is a solver that solves simple conjunctions of constraints. * The performance of this algorithm highly depends on the ability of the theory to * produce small unsatisfiable cores./*from w ww . j a v a 2s. co m*/ * * @param <Constraint> the type of constraint solved by the theory * @param <Model> the type of model produced by the theory * @param theorySolver a solver for some theory * @param fixingSetFinder a strategy for finding a fixing set * @param hardConstraints the hard constraints which MUST be satisfied * @param softConstraints the labeled soft constraints from which the fixing set is drawn * @return A pair (m,l) where l is the fixing set (a minimum set of constraints which had * to be weakened to satisfy the system), and m is the resulting model after weakening. * Note that <code>l.isEmpty()</code> means the entire set of constraints is satisfiable. * @see SatSolver * @see Theory */ public static <Constraint, Model> Pair<Model, Collection<Constraint>> solve( Theory<Constraint, Model> theorySolver, FixingSetFinder<Constraint> fixingSetFinder, List<Constraint> hardConstraints, List<Constraint> softConstraints) { FixingSetListener<Constraint, Model> listener = NOISY ? loggingListener() : FixingSetListener.dummyListener(); fixingSetFinder.setup(softConstraints); // These two are complements of each other: // - fixingSet is the constraints we are going to remove // - positive is the constraints we are going to keep // (i.e. all those not in the fixing set) Collection<Constraint> fixingSet = new ArrayList<>(); Collection<Constraint> positive = new LinkedHashSet<>(); for (;;) { // Be polite---interruptions mean that someone else wants // this thread to stop what it's doing. if (Thread.currentThread().isInterrupted()) { throw new RuntimeException("thread was interrupted"); } positive.addAll(hardConstraints); positive.addAll(softConstraints); positive.removeAll(fixingSet); // Check the proposed fixing set against the theory. Either<Model, Collection<Constraint>> result = timed(() -> theorySolver.check(positive), "CHECKING THEORY"); if (result.right == null) { // The proposed fixing set works! We are done! if (NOISY) System.out.println("VALID MODEL"); listener.onFixingSet(result.left, fixingSet); return Pair.of(result.left, fixingSet); } else { // The proposed fixing set didn't work. We will use the core // to adjust what fixing set gets returned next. // Inform the listener listener.onCore(result.right); // The fixing set finder shouldn't care about hard constraints Collection<Constraint> softCore = result.right.stream().filter(c -> !hardConstraints.contains(c)) .collect(Collectors.toList()); if (softCore.isEmpty()) { throw new IllegalStateException("Hard clauses are unsat!"); } // Push the core to the fixing set finder fixingSet.clear(); fixingSetFinder.addCore(softCore); timed(() -> fixingSetFinder.currentFixingSet(fixingSet, listener), "FINDING FIXING SET"); System.out.println(" --> PROPOSAL SIZE = " + fixingSet.size()); } } }
From source file:com.smartitengineering.version.impl.jgit.JGitVersionControlDaoTest.java
public void testSearch() { final Collection<QueryParameter> collection; collection = new ArrayList<QueryParameter>(); Collection<Commit> commitResult; Collection<Revision> revisionResult; /**//from w ww.j a v a 2s. co m * Search by committer name */ collection.add(QueryParameterFactory.getStringLikePropertyParam( SearchProperties.COMMITTER_NAME.getPropertyName(), "I M Yousuf", MatchMode.EXACT)); commitResult = jGitReadImpl.searchForCommits(collection); assertEquals(1, commitResult.size()); collection.clear(); collection.add(QueryParameterFactory.getStringLikePropertyParam( SearchProperties.COMMITTER_NAME.getPropertyName(), "Imran", MatchMode.START)); commitResult = jGitReadImpl.searchForCommits(collection); assertEquals(2, commitResult.size()); collection.clear(); collection.add(QueryParameterFactory.getStringLikePropertyParam( SearchProperties.COMMITTER_NAME.getPropertyName(), "Yousuf", MatchMode.ANYWHERE)); commitResult = jGitReadImpl.searchForCommits(collection); assertEquals(3, commitResult.size()); /** * Search by commit date */ collection.add( QueryParameterFactory.getOrderByParam(SearchProperties.COMMIT_DATE.getPropertyName(), Order.DESC)); commitResult = jGitReadImpl.searchForCommits(collection); assertEquals(3, commitResult.size()); Iterator<Commit> commitIterator = commitResult.iterator(); commitIterator.next(); Commit commit = commitIterator.next(); Date when = commit.getCommitTime(); collection.clear(); collection.add(QueryParameterFactory .<Date>getEqualPropertyParam(SearchProperties.COMMIT_DATE.getPropertyName(), when)); commitResult = jGitReadImpl.searchForCommits(collection); assertEquals(1, commitResult.size()); assertEquals(commit, commitResult.iterator().next()); collection.clear(); /** * Search by commit message */ collection.clear(); collection.add(QueryParameterFactory .getStringLikePropertyParam(SearchProperties.COMMIT_MSG.getPropertyName(), "A-2", MatchMode.END)); commitResult = jGitReadImpl.searchForCommits(collection); assertEquals(1, commitResult.size()); commit = commitResult.iterator().next(); assertEquals(1, commit.getRevisions().size()); Resource a = commit.getRevisions().iterator().next().getResource(); assertEquals("a/a.xml", a.getId()); assertEquals("UPDATE-1 Content of a/a", a.getContent()); /** * Search by commit revisions */ collection.clear(); collection.add( QueryParameterFactory.getOrderByParam(SearchProperties.COMMIT_DATE.getPropertyName(), Order.DESC)); collection.add(QueryParameterFactory.getNestedParametersParam( SearchProperties.COMMIT_REVISIONS.getPropertyName(), FetchMode.JOIN, QueryParameterFactory .getEqualPropertyParam(SearchProperties.REVISION_RESOURCE.getPropertyName(), "a/a.xml"))); commitResult = jGitReadImpl.searchForCommits(collection); assertEquals(2, commitResult.size()); collection.clear(); collection.add(QueryParameterFactory .<Boolean>getEqualPropertyParam(SearchProperties.REVISION_HEAD.getPropertyName(), true)); collection.clear(); collection.add( QueryParameterFactory.getOrderByParam(SearchProperties.COMMIT_DATE.getPropertyName(), Order.DESC)); collection.add(QueryParameterFactory.getNestedParametersParam( SearchProperties.COMMIT_REVISIONS.getPropertyName(), FetchMode.JOIN, QueryParameterFactory.getEqualPropertyParam(SearchProperties.REVISION_RESOURCE.getPropertyName(), "a/a.xml"), QueryParameterFactory.getEqualPropertyParam(SearchProperties.REVISION_HEAD.getPropertyName(), true))); commitResult = jGitReadImpl.searchForCommits(collection); assertEquals(1, commitResult.size()); /** * Search by committer email */ collection.clear(); collection.add( QueryParameterFactory.getStringLikePropertyParam(SearchProperties.COMMITTER_EMAIL.getPropertyName(), "imran@smartitengineering.com", MatchMode.EXACT)); commitResult = jGitReadImpl.searchForCommits(collection); assertEquals(1, commitResult.size()); collection.clear(); collection.add(QueryParameterFactory.getStringLikePropertyParam( SearchProperties.COMMITTER_EMAIL.getPropertyName(), "@smartitengineering.com", MatchMode.END)); commitResult = jGitReadImpl.searchForCommits(collection); assertEquals(3, commitResult.size()); collection.clear(); collection.add(QueryParameterFactory.getNestedParametersParam( SearchProperties.REVISION_COMMIT.getPropertyName(), FetchMode.JOIN, QueryParameterFactory.getStringLikePropertyParam(SearchProperties.COMMITTER_EMAIL.getPropertyName(), "imran@smartitengineering.com", MatchMode.EXACT))); revisionResult = jGitReadImpl.searchForRevisions(collection); assertEquals(2, revisionResult.size()); /** * Search by resource id and others, Also filters by committer email */ collection.add(QueryParameterFactory.getStringLikePropertyParam( SearchProperties.REVISION_RESOURCE.getPropertyName(), ".xml", MatchMode.END)); revisionResult = jGitReadImpl.searchForRevisions(collection); assertEquals(2, revisionResult.size()); collection.add(QueryParameterFactory.getStringLikePropertyParam( SearchProperties.REVISION_RESOURCE.getPropertyName(), "a/a.xml", MatchMode.EXACT)); revisionResult = jGitReadImpl.searchForRevisions(collection); assertEquals(1, revisionResult.size()); /** * Apply head filter and delete filter */ collection.clear(); collection.add(QueryParameterFactory .<Boolean>getEqualPropertyParam(SearchProperties.REVISION_HEAD.getPropertyName(), true)); collection.add(QueryParameterFactory .getEqualPropertyParam(SearchProperties.REVISION_RESOURCE_DELETED.getPropertyName(), true)); revisionResult = jGitReadImpl.searchForRevisions(collection); assertEquals(1, revisionResult.size()); a = revisionResult.iterator().next().getResource(); assertEquals("b/a.xml", a.getId()); collection.clear(); collection.add(QueryParameterFactory .<Boolean>getEqualPropertyParam(SearchProperties.REVISION_HEAD.getPropertyName(), true)); collection.add(QueryParameterFactory .getEqualPropertyParam(SearchProperties.REVISION_RESOURCE_DELETED.getPropertyName(), false)); revisionResult = jGitReadImpl.searchForRevisions(collection); assertEquals(1, revisionResult.size()); a = revisionResult.iterator().next().getResource(); assertEquals("a/a.xml", a.getId()); assertEquals("UPDATE-1 Content of a/a", a.getContent()); collection.clear(); collection.add(QueryParameterFactory .<Boolean>getEqualPropertyParam(SearchProperties.REVISION_HEAD.getPropertyName(), true)); collection.add(QueryParameterFactory.getStringLikePropertyParam( SearchProperties.REVISION_RESOURCE.getPropertyName(), "a/a.xml", MatchMode.EXACT)); revisionResult = jGitReadImpl.searchForRevisions(collection); assertEquals(1, revisionResult.size()); a = revisionResult.iterator().next().getResource(); assertEquals("a/a.xml", a.getId()); assertEquals("UPDATE-1 Content of a/a", a.getContent()); collection.clear(); collection.add(QueryParameterFactory .<Boolean>getEqualPropertyParam(SearchProperties.REVISION_HEAD.getPropertyName(), false)); collection.add(QueryParameterFactory.getStringLikePropertyParam( SearchProperties.REVISION_RESOURCE.getPropertyName(), "a/a.xml", MatchMode.EXACT)); revisionResult = jGitReadImpl.searchForRevisions(collection); assertEquals(1, revisionResult.size()); a = revisionResult.iterator().next().getResource(); assertEquals("a/a.xml", a.getId()); assertEquals("Content of a/a", a.getContent()); }
From source file:net.beaconcontroller.tutorial.LearningSwitchTutorialSolution.java
/** * get a list with all switches on network. * /*from www . j a va 2 s. c om*/ * TODO - verify if: Here this list is made sending OpenFlow messages to * discover switches on the network, this can produce overhead, be careful! * If this is true, we can use the registeredSwitches class to control * this list without need to send OpenFlow Message all the time! There are this * function implemented like method and on the code in others part of the * Of-IDPS! * * * @return A collection of switches presents on network. */ private Collection<IOFSwitch> getAllSwitchesOnNetwork() { //log.debug("Get switches on the network"); if (beaconProvider.getListeningIPAddress().isAnyLocalAddress()) { /* * TODO ERRO - ERROR - sometimes appear switches that aren't really of the network (ghosts)! * * In some tests the 2 lines below eliminates ghosts switches */ Collection<IOFSwitch> col = new HashSet<IOFSwitch>(); col.clear(); col = beaconProvider.getSwitches().values(); return col; } else { log.debug("SORRY!!! switches weren't found in this network."); } return null; }
From source file:nl.tue.gale.um.UMServiceImpl.java
private String removeUserInfo(Collection<URI> uriList) { String result = null;//w w w . j a v a 2 s. co m List<URI> resultList = new LinkedList<URI>(); for (URI uri : uriList) { if (uri.getUserInfo() != null) result = uri.getUserInfo(); resultList.add(removeUserInfo(uri)); } uriList.clear(); uriList.addAll(resultList); return result; }
From source file:org.training.storefront.breadcrumb.impl.ProductBreadcrumbBuilder.java
public List<Breadcrumb> getBreadcrumbs(final ProductModel productModel) throws IllegalArgumentException { final List<Breadcrumb> breadcrumbs = new ArrayList<>(); final Collection<CategoryModel> categoryModels = new ArrayList<>(); final Breadcrumb last; final ProductModel baseProductModel = getBaseProduct(productModel); last = getProductBreadcrumb(baseProductModel); categoryModels.addAll(baseProductModel.getSupercategories()); last.setLinkClass(LAST_LINK_CLASS);//from w ww . ja v a 2 s . c o m breadcrumbs.add(last); while (!categoryModels.isEmpty()) { CategoryModel toDisplay = null; for (final CategoryModel categoryModel : categoryModels) { if (!(categoryModel instanceof ClassificationClassModel)) { if (toDisplay == null) { toDisplay = categoryModel; } if (getBrowseHistory().findEntryMatchUrlEndsWith(categoryModel.getCode()) != null) { break; } } } categoryModels.clear(); if (toDisplay != null) { breadcrumbs.add(getCategoryBreadcrumb(toDisplay)); categoryModels.addAll(toDisplay.getSupercategories()); } } Collections.reverse(breadcrumbs); return breadcrumbs; }
From source file:com.exxonmobile.ace.hybris.storefront.breadcrumb.impl.ProductBreadcrumbBuilder.java
public List<Breadcrumb> getBreadcrumbs(final ProductModel productModel) throws IllegalArgumentException { final List<Breadcrumb> breadcrumbs = new ArrayList<Breadcrumb>(); final Collection<CategoryModel> categoryModels = new ArrayList<CategoryModel>(); final Breadcrumb last; final ProductModel baseProductModel = getBaseProduct(productModel); last = getProductBreadcrumb(baseProductModel); categoryModels.addAll(baseProductModel.getSupercategories()); last.setLinkClass(LAST_LINK_CLASS);// ww w.java2 s .com breadcrumbs.add(last); while (!categoryModels.isEmpty()) { CategoryModel toDisplay = null; for (final CategoryModel categoryModel : categoryModels) { if (!(categoryModel instanceof ClassificationClassModel)) { if (toDisplay == null) { toDisplay = categoryModel; } if (getBrowseHistory().findUrlInHistory(categoryModel.getCode()) != null) { break; } } } categoryModels.clear(); if (toDisplay != null) { breadcrumbs.add(getCategoryBreadcrumb(toDisplay)); categoryModels.addAll(toDisplay.getSupercategories()); } } Collections.reverse(breadcrumbs); return breadcrumbs; }
From source file:com.epam.cme.storefront.breadcrumb.impl.ProductBreadcrumbBuilder.java
public List<Breadcrumb> getBreadcrumbs(final ProductModel productModel) throws IllegalArgumentException { final List<Breadcrumb> breadcrumbs = new ArrayList<Breadcrumb>(); final Collection<CategoryModel> categoryModels = new ArrayList<CategoryModel>(); final Breadcrumb last; final ProductModel baseProductModel = getBaseProduct(productModel); last = getProductBreadcrumb(baseProductModel); categoryModels.addAll(baseProductModel.getSupercategories()); last.setLinkClass(LAST_LINK_CLASS);//from w w w .j av a 2 s . com breadcrumbs.add(last); while (!categoryModels.isEmpty()) { CategoryModel toDisplay = null; for (final CategoryModel categoryModel : categoryModels) { if (!(categoryModel instanceof ClassificationClassModel)) { if (toDisplay == null) { toDisplay = categoryModel; } if (getBrowseHistory().findEntryMatchUrlEndsWith(categoryModel.getCode()) != null) { break; } } } categoryModels.clear(); if (toDisplay != null) { breadcrumbs.add(getCategoryBreadcrumb(getCategoryConverter().convert(toDisplay))); categoryModels.addAll(toDisplay.getSupercategories()); } } Collections.reverse(breadcrumbs); return breadcrumbs; }
From source file:org.ms123.common.data.MultiOperations.java
public static void populate(SessionContext sessionContext, Map sourceMap, Object destinationObj, Map hintsMap) { PersistenceManager pm = sessionContext.getPM(); if (hintsMap == null) { hintsMap = new HashMap(); }//from www. j a va 2 s.c o m boolean noUpdate = Utils.getBoolean(hintsMap, "noUpdate", false); BeanMap destinationMap = new BeanMap(destinationObj); String entityName = m_inflector.getEntityName(destinationObj.getClass().getSimpleName()); debug("populate.sourceMap:" + sourceMap + ",destinationObj:" + destinationObj + ",destinationMap:" + destinationMap + "/hintsMap:" + hintsMap + "/entityName:" + entityName); if (sourceMap == null) { return; } debug("populate(" + entityName + ") is a persistObject:" + javax.jdo.JDOHelper.isPersistent(destinationObj) + "/" + javax.jdo.JDOHelper.isNew(destinationObj)); if (sourceMap.get("id") != null) { debug("populate(" + entityName + ") has id:" + sourceMap.get("id")); return; } Map permittedFields = sessionContext.getPermittedFields(entityName, "write"); Iterator<String> it = sourceMap.keySet().iterator(); while (it.hasNext()) { String propertyName = it.next(); boolean permitted = sessionContext.getPermissionService().hasAdminRole() || "team".equals(entityName) || sessionContext.isFieldPermitted(propertyName, entityName, "write"); if (!propertyName.startsWith("_") && !permitted) { debug("---->populate:field(" + propertyName + ") no write permission"); continue; } else { debug("++++>populate:field(" + propertyName + ") write permitted"); } String datatype = null; String edittype = null; if (!propertyName.startsWith("_")) { Map config = (Map) permittedFields.get(propertyName); if (config != null) { datatype = (String) config.get("datatype"); edittype = (String) config.get("edittype"); } } if (propertyName.equals(STATE_FIELD) && !sessionContext.getPermissionService().hasAdminRole()) { continue; } if ("auto".equals(edittype)) continue; String mode = null; Map hm = (Map) hintsMap.get(propertyName); if (hm != null) { Object m = hm.get("mode"); if (m != null && m instanceof String) { mode = (String) m; } if (mode == null) { m = hm.get("useit"); if (m != null && m instanceof String) { mode = (String) m; } } } if (mode == null) { mode = "replace"; } Class propertyClass = destinationMap.getType(propertyName); debug("\ttype:" + propertyClass + "(" + propertyName + "=" + sourceMap.get(propertyName) + ")"); if ("_ignore_".equals(sourceMap.get(propertyName))) { continue; } if (propertyClass == null) { debug("\t--- Warning property not found:" + propertyName); } else if (propertyClass.equals(java.util.Date.class)) { String value = Utils.getString(sourceMap.get(propertyName), destinationMap.get(propertyName), mode); debug("\tDate found:" + propertyName + "=>" + value); Date date = null; if (value != null) { try { Long val = Long.valueOf(value); date = (Date) ConvertUtils.convert(val, Date.class); debug("\tdate1:" + date); } catch (Exception e) { try { DateTime dt = new DateTime(value); date = new Date(dt.getMillis()); debug("\tdate2:" + date); } catch (Exception e1) { try { int space = value.indexOf(" "); if (space != -1) { value = value.substring(0, space) + "T" + value.substring(space + 1); DateTime dt = new DateTime(value); date = new Date(dt.getMillis()); } debug("\tdate3:" + date); } catch (Exception e2) { debug("\terror setting date:" + e); } } } } debug("\tsetting date:" + date); destinationMap.put(propertyName, date); } else if (propertyClass.equals(java.util.Map.class)) { info("!!!!!!!!!!!!!!!!!!!Map not implemented"); } else if (propertyClass.equals(java.util.List.class) || propertyClass.equals(java.util.Set.class)) { boolean isList = propertyClass.equals(java.util.List.class); boolean isSimple = false; if (datatype != null && datatype.startsWith("list_")) { isSimple = true; } try { Class propertyType = TypeUtils.getTypeForField(destinationObj, propertyName); debug("propertyType:" + propertyType + " fill with: " + sourceMap.get(propertyName) + ",list:" + destinationMap.get(propertyName) + "/mode:" + mode); Collection sourceList = isList ? new ArrayList() : new HashSet(); Object fromVal = sourceMap.get(propertyName); if (fromVal instanceof String && ((String) fromVal).length() > 0) { info("FromVal is StringSchrott, ignore"); continue; } if (sourceMap.get(propertyName) instanceof Collection) { sourceList = (Collection) sourceMap.get(propertyName); } if (sourceList == null) { sourceList = isList ? new ArrayList() : new HashSet(); } Collection destinationList = (Collection) PropertyUtils.getProperty(destinationObj, propertyName); debug("destinationList:" + destinationList); debug("sourceList:" + sourceList); if (destinationList == null) { destinationList = isList ? new ArrayList() : new HashSet(); PropertyUtils.setProperty(destinationObj, propertyName, destinationList); } if ("replace".equals(mode)) { boolean isEqual = false; if (isSimple) { isEqual = Utils.isCollectionEqual(destinationList, sourceList); if (!isEqual) { destinationList.clear(); } debug("\tisEqual:" + isEqual); } else { List deleteList = new ArrayList(); String namespace = sessionContext.getStoreDesc().getNamespace(); for (Object o : destinationList) { if (propertyType.getName().endsWith(".Team")) { int status = sessionContext.getTeamService().getTeamStatus(namespace, new BeanMap(o), null, sessionContext.getUserName()); debug("populate.replace.teamStatus:" + status + "/" + new HashMap(new BeanMap(o))); if (status != -1) { pm.deletePersistent(o); deleteList.add(o); } } else { pm.deletePersistent(o); deleteList.add(o); } } for (Object o : deleteList) { destinationList.remove(o); } } debug("populate.replace.destinationList:" + destinationList + "/" + propertyType.getName()); if (isSimple) { if (!isEqual) { for (Object o : sourceList) { destinationList.add(o); } } } else { for (Object o : sourceList) { Map childSourceMap = (Map) o; Object childDestinationObj = propertyType.newInstance(); if (propertyType.getName().endsWith(".Team")) { childSourceMap.remove("id"); Object desc = childSourceMap.get("description"); Object name = childSourceMap.get("name"); Object dis = childSourceMap.get("disabled"); String teamid = (String) childSourceMap.get("teamid"); Object ti = Utils.getTeamintern(sessionContext, teamid); if (desc == null) { childSourceMap.put("description", PropertyUtils.getProperty(ti, "description")); } if (name == null) { childSourceMap.put("name", PropertyUtils.getProperty(ti, "name")); } if (dis == null) { childSourceMap.put("disabled", false); } pm.makePersistent(childDestinationObj); populate(sessionContext, childSourceMap, childDestinationObj, hintsMap); PropertyUtils.setProperty(childDestinationObj, "teamintern", ti); } else { pm.makePersistent(childDestinationObj); populate(sessionContext, childSourceMap, childDestinationObj, hintsMap); } debug("populated.add:" + new HashMap(new BeanMap(childDestinationObj))); destinationList.add(childDestinationObj); } } } else if ("remove".equals(mode)) { if (isSimple) { for (Object o : sourceList) { if (destinationList.contains(o)) { destinationList.remove(o); } } } else { for (Object ol : sourceList) { Map childSourceMap = (Map) ol; Object o = Utils.listContainsId(destinationList, childSourceMap, "teamid"); if (o != null) { destinationList.remove(o); pm.deletePersistent(o); } } } } else if ("add".equals(mode)) { if (isSimple) { for (Object o : sourceList) { destinationList.add(o); } } else { for (Object ol : sourceList) { Map childSourceMap = (Map) ol; Object childDestinationObj = Utils.listContainsId(destinationList, childSourceMap, "teamid"); if (childDestinationObj != null) { populate(sessionContext, childSourceMap, childDestinationObj, hintsMap); } else { childDestinationObj = propertyType.newInstance(); if (propertyType.getName().endsWith(".Team")) { Object desc = childSourceMap.get("description"); Object name = childSourceMap.get("name"); Object dis = childSourceMap.get("disabled"); String teamid = (String) childSourceMap.get("teamid"); Object ti = Utils.getTeamintern(sessionContext, teamid); if (desc == null) { childSourceMap.put("description", PropertyUtils.getProperty(ti, "description")); } if (name == null) { childSourceMap.put("name", PropertyUtils.getProperty(ti, "name")); } if (dis == null) { childSourceMap.put("disabled", false); } pm.makePersistent(childDestinationObj); populate(sessionContext, childSourceMap, childDestinationObj, hintsMap); PropertyUtils.setProperty(childDestinationObj, "teamintern", ti); } else { pm.makePersistent(childDestinationObj); populate(sessionContext, childSourceMap, childDestinationObj, hintsMap); } destinationList.add(childDestinationObj); } } } } else if ("assign".equals(mode)) { if (!isSimple) { for (Object ol : sourceList) { Map childSourceMap = (Map) ol; Object childDestinationObj = Utils.listContainsId(destinationList, childSourceMap); if (childDestinationObj != null) { debug("id:" + childSourceMap + " already assigned"); } else { Object id = childSourceMap.get("id"); Boolean assign = Utils.getBoolean(childSourceMap.get("assign")); Object obj = pm.getObjectById(propertyType, id); if (assign) { destinationList.add(obj); } else { destinationList.remove(obj); } } } } } } catch (Exception e) { e.printStackTrace(); debug("populate.list.failed:" + propertyName + "=>" + sourceMap.get(propertyName) + ";" + e); } } else if (propertyClass.equals(java.lang.Boolean.class)) { try { destinationMap.put(propertyName, ConvertUtils.convert(sourceMap.get(propertyName), Boolean.class)); } catch (Exception e) { debug("populate.boolean.failed:" + propertyName + "=>" + sourceMap.get(propertyName) + ";" + e); } } else if (propertyClass.equals(java.lang.Double.class)) { String value = Utils.getString(sourceMap.get(propertyName), destinationMap.get(propertyName), mode); try { destinationMap.put(propertyName, Double.valueOf(value)); } catch (Exception e) { debug("populate.double.failed:" + propertyName + "=>" + value + ";" + e); } } else if (propertyClass.equals(java.lang.Long.class)) { try { destinationMap.put(propertyName, ConvertUtils.convert(sourceMap.get(propertyName), Long.class)); } catch (Exception e) { debug("populate.long.failed:" + propertyName + "=>" + sourceMap.get(propertyName) + ";" + e); } } else if (propertyClass.equals(java.lang.Integer.class)) { debug("Integer:" + ConvertUtils.convert(sourceMap.get(propertyName), Integer.class)); try { destinationMap.put(propertyName, ConvertUtils.convert(sourceMap.get(propertyName), Integer.class)); } catch (Exception e) { debug("populate.integer.failed:" + propertyName + "=>" + sourceMap.get(propertyName) + ";" + e); } } else if ("binary".equals(datatype) || propertyClass.equals(byte[].class)) { InputStream is = null; InputStream is2 = null; try { if (sourceMap.get(propertyName) instanceof FileItem) { FileItem fi = (FileItem) sourceMap.get(propertyName); String name = fi.getName(); byte[] bytes = IOUtils.toByteArray(fi.getInputStream()); if (bytes != null) { debug("bytes:" + bytes.length); } destinationMap.put(propertyName, bytes); is = fi.getInputStream(); is2 = fi.getInputStream(); } else if (sourceMap.get(propertyName) instanceof Map) { Map map = (Map) sourceMap.get(propertyName); String storeLocation = (String) map.get("storeLocation"); is = new FileInputStream(new File(storeLocation)); is2 = new FileInputStream(new File(storeLocation)); byte[] bytes = IOUtils.toByteArray(is); if (bytes != null) { debug("bytes2:" + bytes.length); } is.close(); destinationMap.put(propertyName, bytes); is = new FileInputStream(new File(storeLocation)); } else if (sourceMap.get(propertyName) instanceof String) { String value = (String) sourceMap.get(propertyName); if (value.startsWith("data:")) { int ind = value.indexOf(";base64,"); byte b[] = Base64.decode(value.substring(ind + 8)); destinationMap.put(propertyName, b); is = new ByteArrayInputStream(b); is2 = new ByteArrayInputStream(b); } else { } } else { debug("populate.byte[].no a FileItem:" + propertyName + "=>" + sourceMap.get(propertyName)); continue; } Tika tika = new Tika(); TikaInputStream stream = TikaInputStream.get(is); TikaInputStream stream2 = TikaInputStream.get(is2); String text = tika.parseToString(is); debug("Text:" + text); try { destinationMap.put("text", text); } catch (Exception e) { destinationMap.put("text", text.getBytes()); } //@@@MS Hardcoded try { Detector detector = new DefaultDetector(); MediaType mime = detector.detect(stream2, new Metadata()); debug("Mime:" + mime.getType() + "|" + mime.getSubtype() + "|" + mime.toString()); destinationMap.put("type", mime.toString()); sourceMap.put("type", mime.toString()); } catch (Exception e) { e.printStackTrace(); } } catch (Exception e) { e.printStackTrace(); debug("populate.byte[].failed:" + propertyName + "=>" + sourceMap.get(propertyName) + ";" + e); } finally { try { is.close(); is2.close(); } catch (Exception e) { } } } else { boolean ok = false; try { Class propertyType = TypeUtils.getTypeForField(destinationObj, propertyName); debug("propertyType:" + propertyType + "/" + propertyName); if (propertyType != null) { boolean hasAnn = propertyType.isAnnotationPresent(PersistenceCapable.class); debug("hasAnnotation:" + hasAnn); if (propertyType.newInstance() instanceof javax.jdo.spi.PersistenceCapable || hasAnn) { handleRelatedTo(sessionContext, sourceMap, propertyName, destinationMap, destinationObj, propertyType); Object obj = sourceMap.get(propertyName); if (obj != null && obj instanceof Map) { Map childSourceMap = (Map) obj; Object childDestinationObj = destinationMap.get(propertyName); if (childDestinationObj == null) { childDestinationObj = propertyType.newInstance(); destinationMap.put(propertyName, childDestinationObj); } populate(sessionContext, childSourceMap, childDestinationObj, hintsMap); } else { if (obj == null) { destinationMap.put(propertyName, null); } } ok = true; } } } catch (Exception e) { e.printStackTrace(); } if (!ok) { String value = Utils.getString(sourceMap.get(propertyName), destinationMap.get(propertyName), mode); try { if (noUpdate) { if (Utils.isEmptyObj(destinationMap.get(propertyName))) { destinationMap.put(propertyName, value); } } else { destinationMap.put(propertyName, value); } } catch (Exception e) { debug("populate.failed:" + propertyName + "=>" + value + ";" + e); } } } } }
From source file:com.jaeksoft.searchlib.Client.java
private final int updateDocList(int totalCount, int docCount, Collection<IndexDocument> docList, InfoCallback infoCallBack) throws NoSuchAlgorithmException, IOException, URISyntaxException, SearchLibException, InstantiationException, IllegalAccessException, ClassNotFoundException { checkMaxStorageLimit();// www . j av a2 s.c o m checkMaxDocumentLimit(); docCount += updateDocuments(docList); StringBuilder sb = new StringBuilder(); sb.append(docCount); if (totalCount > 0) { sb.append(" / "); sb.append(totalCount); } sb.append(" document(s) updated."); if (infoCallBack != null) infoCallBack.setInfo(sb.toString()); else Logging.info(sb.toString()); docList.clear(); return docCount; }
From source file:org.enerj.apache.commons.collections.TestPredicateUtils.java
public void testAllPredicate() { assertTrue(PredicateUtils.allPredicate(new Predicate[] {}).evaluate(null)); assertEquals(true, PredicateUtils.allPredicate(new Predicate[] { PredicateUtils.truePredicate(), PredicateUtils.truePredicate(), PredicateUtils.truePredicate() }).evaluate(null)); assertEquals(false, PredicateUtils.allPredicate(new Predicate[] { PredicateUtils.truePredicate(), PredicateUtils.falsePredicate(), PredicateUtils.truePredicate() }).evaluate(null)); assertEquals(false, PredicateUtils.allPredicate(new Predicate[] { PredicateUtils.falsePredicate(), PredicateUtils.falsePredicate(), PredicateUtils.truePredicate() }).evaluate(null)); assertEquals(false, PredicateUtils.allPredicate(new Predicate[] { PredicateUtils.falsePredicate(), PredicateUtils.falsePredicate(), PredicateUtils.falsePredicate() }).evaluate(null)); Collection coll = new ArrayList(); coll.add(PredicateUtils.truePredicate()); coll.add(PredicateUtils.truePredicate()); coll.add(PredicateUtils.truePredicate()); assertEquals(true, PredicateUtils.allPredicate(coll).evaluate(null)); coll.clear(); coll.add(PredicateUtils.truePredicate()); coll.add(PredicateUtils.falsePredicate()); coll.add(PredicateUtils.truePredicate()); assertEquals(false, PredicateUtils.allPredicate(coll).evaluate(null)); coll.clear();// www . ja va2 s . co m coll.add(PredicateUtils.falsePredicate()); coll.add(PredicateUtils.falsePredicate()); coll.add(PredicateUtils.truePredicate()); assertEquals(false, PredicateUtils.allPredicate(coll).evaluate(null)); coll.clear(); coll.add(PredicateUtils.falsePredicate()); coll.add(PredicateUtils.falsePredicate()); coll.add(PredicateUtils.falsePredicate()); assertEquals(false, PredicateUtils.allPredicate(coll).evaluate(null)); coll.clear(); coll.add(PredicateUtils.falsePredicate()); assertFalse(PredicateUtils.allPredicate(coll).evaluate(null)); coll.clear(); coll.add(PredicateUtils.truePredicate()); assertTrue(PredicateUtils.allPredicate(coll).evaluate(null)); coll.clear(); assertTrue(PredicateUtils.allPredicate(coll).evaluate(null)); }