List of usage examples for java.lang Iterable forEach
default void forEach(Consumer<? super T> action)
From source file:com.netflix.metacat.main.configs.ElasticSearchConfig.java
/** * The ElasticSearch client.//from w ww .ja v a 2s . c o m * * @param config System config * @return Configured client or error */ @Bean @ConditionalOnMissingBean(Client.class) public Client elasticSearchClient(final Config config) { final String clusterName = config.getElasticSearchClusterName(); if (StringUtils.isBlank(clusterName)) { throw new IllegalStateException("No cluster name set. Unable to continue"); } final Settings settings = Settings.builder().put("cluster.name", clusterName) .put("client.transport.sniff", true) //to dynamically add new hosts and remove old ones .put("transport.tcp.connect_timeout", "60s").build(); final TransportClient client = new PreBuiltTransportClient(settings); // Add the transport address if exists final String clusterNodesStr = config.getElasticSearchClusterNodes(); if (StringUtils.isNotBlank(clusterNodesStr)) { final int port = config.getElasticSearchClusterPort(); final Iterable<String> clusterNodes = Splitter.on(',').split(clusterNodesStr); clusterNodes.forEach(clusterNode -> { try { client.addTransportAddress( new InetSocketTransportAddress(InetAddress.getByName(clusterNode), port)); } catch (UnknownHostException exception) { log.error("Skipping unknown host {}", clusterNode); } }); } if (client.transportAddresses().isEmpty()) { throw new IllegalStateException("No Elasticsearch cluster nodes added. Unable to create client."); } return client; }
From source file:com._4dconcept.springframework.data.marklogic.repository.support.SimpleMarklogicRepository.java
@Override @Transactional//from www. ja va 2 s. c om public void deleteAll(Iterable<? extends T> entities) { entities.forEach(this::delete); }
From source file:ch.ifocusit.plantuml.classdiagram.ClassDiagramBuilder.java
public ClassDiagramBuilder addClasse(Iterable<Class> classes) { classes.forEach(this.classesRepository::add); return this; }
From source file:it.polimi.diceH2020.SPACE4CloudWS.solvers.solversImpl.MINLPSolver.MINLPDataFileBuilder.java
MINLPDataFileBuilder addIndexedSet(String name, int index, Iterable<Integer> elements) { String currentLine = String.format("set %s[%d] :=", name, index); lines.add(currentLine);/*from ww w. j a v a 2 s.co m*/ elements.forEach(element -> lines.add(element.toString())); lines.add(";"); return this; }
From source file:org.jumlabs.jcr.oak.rpc.api.impl.JTreeServiceImpl.java
@Override public List<TTree> getChildren(TTree ttree) throws TException { List<TTree> tchildren = new ArrayList<>(); try {/*ww w . j a va 2 s.c o m*/ Tree tree = RepositoryUtils.getTree(repository, ttree); Iterable<Tree> children = tree.getChildren(); children.forEach(childTree -> { TTree childTTree = RepositoryUtils.toTTree(childTree); tchildren.add(childTTree); }); } catch (LoginException | NoSuchWorkspaceException ex) { logger.error(ex.getMessage(), ex); } return tchildren; }
From source file:org.obiba.mica.core.service.SchemaFormContentFileService.java
private Iterable<Object> saveAndDeleteFiles(JSONArray oldFiles, JSONArray newFiles, String entityPath) { cleanFileJsonArrays(oldFiles, newFiles); Iterable<Object> toDelete = Sets.difference(Sets.newHashSet(oldFiles), Sets.newHashSet(newFiles)); Iterable<Object> toSave = Sets.difference(Sets.newHashSet(newFiles), Sets.newHashSet(oldFiles)); toDelete.forEach(file -> fileStoreService.delete(((LinkedHashMap) file).get("id").toString())); saveFiles(toSave, entityPath);//from w ww .j av a 2s .com return toDelete; }
From source file:co.com.carpco.altablero.hibernate.bll.GradeBll.java
private void initializeCache() { CachingProvider cachingProvider = Caching.getCachingProvider(); CacheManager cacheManager = cachingProvider.getCacheManager(); MutableConfiguration<Integer, Set> config = new MutableConfiguration<Integer, Set>() .setTypes(Integer.class, Set.class).setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(ONE_DAY)) .setWriteThrough(true).setReadThrough(true) .setCacheLoaderFactory(new Factory<CacheLoader<Integer, Set>>() { @Override/*from ww w.ja v a2 s .co m*/ public CacheLoader<Integer, Set> create() { return new CacheLoader<Integer, Set>() { @Override public Set load(Integer key) throws CacheLoaderException { final Set<GradeBO> gradeBOSet = new HashSet<>(); Set<BzGrade> bzGradeSet = gradeDao.getGradeSet(); if (bzGradeSet != null && bzGradeSet.size() > 0) { bzGradeSet.forEach((BzGrade bzGrade) -> gradeBOSet.add(new GradeBO(bzGrade))); } return gradeBOSet; } @Override public Map<Integer, Set> loadAll(Iterable<? extends Integer> itrbl) throws CacheLoaderException { Map<Integer, Set> answer = new HashMap<>(); itrbl.forEach((Integer k) -> answer.put(k, load(k))); return answer; } }; } }).setCacheWriterFactory(new Factory<CacheWriter<Integer, Set>>() { @Override public CacheWriter<Integer, Set> create() { CacheWriter<Integer, Set> writer = new CacheWriter<Integer, Set>() { @Override public void write(Cache.Entry<? extends Integer, ? extends Set> entry) throws CacheWriterException { } @Override public void writeAll(Collection<Cache.Entry<? extends Integer, ? extends Set>> clctn) throws CacheWriterException { } @Override public void delete(Object o) throws CacheWriterException { } @Override public void deleteAll(Collection<?> clctn) throws CacheWriterException { } }; return writer; } }).setStatisticsEnabled(true); cache = cacheManager.createCache("gradeCache", config); config.isReadThrough(); }
From source file:co.com.carpco.altablero.hibernate.bll.YearBll.java
private void initializeCache() { CachingProvider cachingProvider = Caching.getCachingProvider(); CacheManager cacheManager = cachingProvider.getCacheManager(); MutableConfiguration<Integer, Set> config = new MutableConfiguration<Integer, Set>() .setTypes(Integer.class, Set.class).setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(ONE_DAY)) .setWriteThrough(true).setReadThrough(true) .setCacheLoaderFactory(new Factory<CacheLoader<Integer, Set>>() { @Override/*from w w w . j a v a2 s . co m*/ public CacheLoader<Integer, Set> create() { return new CacheLoader<Integer, Set>() { @Override public Set load(Integer key) throws CacheLoaderException { final Set<YearBO> yearBOSet = new HashSet<>(); Set<BzYear> bzYearSet = yearDao.getYearSet(); if (bzYearSet != null && bzYearSet.size() > 0) { bzYearSet.forEach((BzYear bzYear) -> yearBOSet.add(new YearBO(bzYear))); } return yearBOSet; } @Override public Map<Integer, Set> loadAll(Iterable<? extends Integer> itrbl) throws CacheLoaderException { Map<Integer, Set> answer = new HashMap<>(); itrbl.forEach((Integer k) -> answer.put(k, load(k))); return answer; } }; } }).setCacheWriterFactory(new Factory<CacheWriter<Integer, Set>>() { @Override public CacheWriter<Integer, Set> create() { CacheWriter<Integer, Set> writer = new CacheWriter<Integer, Set>() { @Override public void write(Cache.Entry<? extends Integer, ? extends Set> entry) throws CacheWriterException { } @Override public void writeAll(Collection<Cache.Entry<? extends Integer, ? extends Set>> clctn) throws CacheWriterException { } @Override public void delete(Object o) throws CacheWriterException { } @Override public void deleteAll(Collection<?> clctn) throws CacheWriterException { } }; return writer; } }).setStatisticsEnabled(true); cache = cacheManager.createCache("yearCache", config); config.isReadThrough(); }
From source file:co.kademi.kdom.template.KDomTemplater.java
private void mergeNode(KDomNode sourceNode, KDocument newDoc, JexlContext vars, List<KDomNode> nodesToAddTo, KDomElement parentElement, List<TemplateCall> contextStack) { if (sourceNode instanceof KDomElement) { KDomElement te = (KDomElement) sourceNode; te = merge(te, newDoc, vars, contextStack); nodesToAddTo.add(te);//from w ww . j a v a2s.com } else if (sourceNode instanceof KDocument.KDomExpressionNode) { KDomExpressionNode en = (KDomExpressionNode) sourceNode; System.out.println("Evaluate expre: " + en.getText() + " with context parent: " + vars.get("parent")); Expression expr = en.getExpr(); Object exprResult = expr.evaluate(vars); addNodesFromExpression(exprResult, newDoc, vars, nodesToAddTo, parentElement, contextStack); } else if (sourceNode instanceof KDocument.KDomExpressionSection) { KDomExpressionSection section = (KDomExpressionSection) sourceNode; Expression expr = section.getExpr(); if (section.getHelperName() != null) { Object exprResult; switch (section.getHelperName()) { case "template": // Evaluate the expression to get the template path (probably a const) // Needs to push the current context onto the template context stack System.out.println("execute template: " + section.getText()); exprResult = expr.evaluate(vars); String templatePath = exprResult + ""; KDocument templateDoc = templateLocator.locate(templatePath); MultiJexlContext c = MultiJexlContext.build(vars, new ObjectContext(jexl, section)); contextStack.add(0, new TemplateCall(c, section)); // push. include section as root object for use with #merge find('..') Map<String, Object> newVars = new HashMap<>(); newVars.put("doc", templateDoc); JexlContext docContext = new MapContext(newVars); vars = new NestableJexlContext(vars, docContext); vars = MultiJexlContext.build(vars, new ObjectContext(jexl, section)); KDomElement templateRootEl = templateDoc.getRoot(); System.out.println("using template: " + templateRootEl); mergeElementContent(parentElement, templateRootEl, newDoc, vars, nodesToAddTo, contextStack); break; case "merge": // this is a template calling back to the page that called it. Needs to pop the execution context, and evaluate TemplateCall templateCall = contextStack.remove(0); // pop System.out.println("merge:" + section.getText()); JexlContext templateCallContext = templateCall.getContext(); System.out.println("-----"); Object o = jexl.createExpression("this.find('body')").evaluate(templateCallContext); System.out.println("------"); exprResult = expr.evaluate(templateCallContext); addNodesFromExpression(exprResult, newDoc, vars, nodesToAddTo, parentElement, contextStack); break; } } else { Object exprResult = expr.evaluate(vars); JexlContext context = vars; if (exprResult instanceof Iterable) { // The expression returned a list, so we evaluate the child nodes for each item in the list Iterable it = (Iterable) exprResult; it.forEach((Object listItem) -> { JexlContext c = new ObjectContext(jexl, listItem); NestableJexlContext jc = new NestableJexlContext(context, c); mergeElementContent(parentElement, section, newDoc, jc, nodesToAddTo, contextStack); }); } else { // not iterable, so use as an if condition, check if value is truthy boolean b = toTruthy(exprResult); if (b) { JexlContext c = new ObjectContext(jexl, exprResult); NestableJexlContext jc = new NestableJexlContext(vars, c); mergeElementContent(parentElement, section, newDoc, jc, nodesToAddTo, contextStack); } } } } else if (sourceNode instanceof KDocument.KDomTextNode) { KDomTextNode tt = (KDomTextNode) sourceNode; KDocument.KDomTextNode n = newDoc.createTextNode(tt.getText()); nodesToAddTo.add(n); System.out.println("added node: " + n); } }
From source file:co.com.carpco.altablero.hibernate.bll.UserBll.java
private void initializeTeacherCache() { CachingProvider cachingProvider = Caching.getCachingProvider(); CacheManager cacheManager = cachingProvider.getCacheManager(); MutableConfiguration<Integer, Set> config = new MutableConfiguration<Integer, Set>() .setTypes(Integer.class, Set.class).setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(ONE_DAY)) .setWriteThrough(true).setReadThrough(true) .setCacheLoaderFactory(new Factory<CacheLoader<Integer, Set>>() { @Override//w w w .ja v a 2 s. c om public CacheLoader<Integer, Set> create() { return new CacheLoader<Integer, Set>() { @Override public Set load(Integer k) throws CacheLoaderException { final Set<UserBO> userBOSet = new HashSet<>(); Set<BzUser> bzUserSet = userDao.getTeacherSet(k); if (bzUserSet != null && bzUserSet.size() > 0) { bzUserSet.forEach((BzUser bzUser) -> userBOSet.add(new UserBO(bzUser))); } return userBOSet; } @Override public Map<Integer, Set> loadAll(Iterable<? extends Integer> itrbl) throws CacheLoaderException { Map<Integer, Set> answer = new HashMap<>(); itrbl.forEach((Integer k) -> answer.put(k, load(k))); return answer; } }; } }).setStatisticsEnabled(true); teacherCache = cacheManager.createCache("teacherCache", config); config.isReadThrough(); }