List of usage examples for java.util Set clear
void clear();
From source file:no.abmu.finances.service.hibernate3.FinanceSchemaImportServiceH3Impl.java
private Post getNewPost(Session session, FinanceSchemaExcelParser excelParser) { String code = excelParser.getPostCode(); PostType postType = getPostType(session, excelParser); PostPeriod period = getPeriod(session, excelParser); PostFinderSpecification finderSpecification = new PostFinderSpecification(code); Criteria criteria = finderSpecification.createCriteria(session); List<Post> list = criteria.list(); Post retPost = null;/*from w ww. java 2 s .c om*/ if (list.size() == 0) { retPost = createNewPost(excelParser); retPost.setPostType(postType); retPost.setPeriod(period); session.save(retPost); logger.info("NEW POST: " + retPost); validatorLogging(retPost); } else if (list.size() == 1) { retPost = list.get(0); String postValueType = excelParser.getPostValueType(); if (!postValueType.equals(retPost.getClass().getName())) { logger.error(""); logger.error( " XXXXXXXXXXXXXXXXXX OLD NOT SAME AS DEFINITION IN NEW SCHEMA XXXXXXXXXXXXXXXXXXXX"); logger.error(""); } Set validators = retPost.getValidators(); logger.info("Number of validators befor clearing existing validators: '" + validators.size() + "'"); validators.clear(); addNewValidators(excelParser, retPost); retPost.setPeriod(period); session.save(retPost); logger.info("OLD POST: " + retPost); validatorLogging(retPost); } else { retPost = list.get(0); logger.warn(""); logger.warn(" ZZZZZZZ More than on post number of posts: " + list.size() + "'"); logger.warn(""); for (Post tmpPost : list) { logger.info("OLD POSTS: " + tmpPost.toString()); validatorLogging(tmpPost); } } return retPost; }
From source file:com.civis.utils.opennlp.models.address.AddressFinderMe.java
private List<AddressSpan> tryToFindAddressByZip(String[] tokens) { tokens = removeAllSpecialChars(tokens); AddressSpan addressSpan = new AddressSpan(FindType.PATTERN); Set<String> zipSet = extractZips(); String zip = findSetValueInToken(tokens, zipSet); addressSpan.setZip(zip);//from w ww . j a v a 2s .c o m addressSpan.setCountry(Constants.DEFAULT_COUNTRY); if (StringUtils.isNotBlank(zip)) { zipSet.clear(); Set<String> citySet = extractCitiesByZip(zip); String city = findSetValueInToken(tokens, citySet); addressSpan.setCity(city); if (StringUtils.isNotBlank(city)) { int zipIndex = tokenAt(tokens, zip); int streetNumberIndex = zipIndex - 1; int maxLoopSize = 3; int streetIndex = -1; // try to find street number for (int i = streetNumberIndex; i > -1; i--) { // start on zipIndex - 1 and loop back if (StreetNumberFeature.STREET_NUMBER_PATTERN.matcher(tokens[i]).matches()) { addressSpan.setStreetNumber(tokens[i]); streetIndex = i - 1; break; } maxLoopSize--; //3 loops from zip index and street number is not found, than break if (maxLoopSize <= 0) { return Collections.emptyList(); } } // try to find street maxLoopSize = 3; for (int i = streetIndex; i > -1; i--) { // start on streetIndex - 1 and loop back StringPattern stringPattern = StringPattern.recognize(tokens[streetIndex]); if (stringPattern.isInitialCapitalLetter()) { addressSpan.setStreet(tokens[streetIndex]); if (addressSpan.isValid()) { return Collections.singletonList(addressSpan); } } maxLoopSize--; //3 loops from street number index and street is not found, than break if (maxLoopSize <= 0) { return Collections.emptyList(); } } } } return Collections.emptyList(); }
From source file:it.units.malelab.ege.util.DUMapper.java
private static double[][][] getNeatData2(String baseDir, String fileNamePattern, int generations) throws IOException { List<List<Map<Integer, Pair<Double, Double>>>> data = new ArrayList<>(); int maxInnovationNumber = 0; for (int g = 0; g < generations; g++) { List<Map<Integer, Pair<Double, Double>>> currentPopulation = new ArrayList<>(); BufferedReader reader = Files.newBufferedReader( FileSystems.getDefault().getPath(baseDir, String.format(fileNamePattern, g + 1))); String line;//from w w w. ja v a2 s . c om boolean isInPopulation = false; Map<Integer, Pair<Double, Double>> currentIndividual = null; Set<Integer> currentIndividualConnectedNodes = new HashSet<>(); while ((line = reader.readLine()) != null) { if (line.equals("[NEAT-POPULATION:SPECIES]")) { isInPopulation = true; continue; } if (!isInPopulation) { continue; } if (line.startsWith("\"g\"")) { if (currentIndividual != null) { //compute data for nodes for (int usedNode : currentIndividualConnectedNodes) { currentIndividual.put(usedNode, new Pair<>(1d, 1d)); } //save current individual currentPopulation.add(currentIndividual); } currentIndividual = new HashMap<>(); currentIndividualConnectedNodes.clear(); } if (line.startsWith("\"n\"") || line.startsWith("\"l\"")) { String[] pieces = line.split(","); int innovationNumber = Integer.parseInt(pieces[pieces.length - 1]); maxInnovationNumber = Math.max(innovationNumber, maxInnovationNumber); double used = 0; double value = 0; if (line.startsWith("\"l\"")) { value = Double.parseDouble(pieces[pieces.length - 2]); used = Double.parseDouble(pieces[2]); //get connected nodes if (used == 1) { currentIndividualConnectedNodes.add(Integer.parseInt(pieces[3])); currentIndividualConnectedNodes.add(Integer.parseInt(pieces[4])); } } currentIndividual.put(innovationNumber, new Pair<>(used, value)); } } reader.close(); data.add(currentPopulation); } //populate arrays double[][] usages = new double[generations][]; double[][] diversities = new double[generations][]; for (int g = 0; g < generations; g++) { usages[g] = new double[maxInnovationNumber]; diversities[g] = new double[maxInnovationNumber]; List<Map<Integer, Pair<Double, Double>>> currentPopulation = data.get(g); //populate usages double[][] values = new double[maxInnovationNumber][]; double[] localUsages = new double[maxInnovationNumber]; for (int i = 0; i < maxInnovationNumber; i++) { values[i] = new double[currentPopulation.size()]; } for (int p = 0; p < currentPopulation.size(); p++) { for (int i = 0; i < maxInnovationNumber; i++) { double value = 0; double used = 0; if (currentPopulation.get(p).containsKey(i)) { Pair<Double, Double> pair = currentPopulation.get(p).get(i); value = pair.getSecond(); used = pair.getFirst(); } values[i][p] = value; localUsages[i] = localUsages[i] + used; } } for (int i = 0; i < maxInnovationNumber; i++) { usages[g][i] = localUsages[i] / (double) currentPopulation.size(); diversities[g][i] = normalizedVar(values[i]); } } return new double[][][] { diversities, usages }; }
From source file:com.example.ekanban.service.ProductService.java
@Transactional public ProductDto update(Product product, List<Long> sections, List<Long> suppliers) { logger.debug("update()"); Product product2 = productRepository.findOne(product.getId()); map(product, product2);//from w w w. j av a 2s . c o m Set<Section> sectionList = product2.getSectionList(); sectionList.clear(); sections.forEach(secId -> { sectionList.add(sectionRepository.findOne(secId)); }); Set<Supplier> supplierList = product2.getSupplierList(); supplierList.clear(); suppliers.forEach(secId -> { supplierList.add(supplierRepository.findOne(secId)); }); return mapper.map(product2, ProductDto.class); }
From source file:org.apache.syncope.client.enduser.resources.UserSelfReadResource.java
private void customizeAttrTOs(final Set<AttrTO> attrs, final CustomAttributesInfo customAttributesInfo) { if (customAttributesInfo != null && customAttributesInfo.isShow() && !customAttributesInfo.getAttributes().isEmpty()) { attrs.removeAll(attrs.stream()/*from www. j a v a 2 s . c o m*/ .filter(attr -> !customAttributesInfo.getAttributes().containsKey(attr.getSchema())) .collect(Collectors.toList())); } else if (customAttributesInfo != null && !customAttributesInfo.isShow()) { attrs.clear(); } }
From source file:edu.ku.brc.af.ui.forms.SubViewBtn.java
/** * /*from w ww . ja va 2 s. c o m*/ */ @SuppressWarnings("unchecked") public void wasCancelled() { if (cachedSet != null && cachedSet.size() != ((Set<?>) dataObj).size()) { Set<Object> dataSet = (Set<Object>) dataObj; dataSet.clear(); dataSet.addAll(cachedSet); } }
From source file:edu.uci.ics.jung.io.graphml.TestGraphMLReader2.java
@Test public void testHypergraphFile() throws Exception { Transformer<GraphMetadata, Hypergraph<Number, Number>> graphFactory = new Transformer<GraphMetadata, Hypergraph<Number, Number>>() { public Hypergraph<Number, Number> transform(GraphMetadata md) { return new SetHypergraph<Number, Number>(); }//from w ww .j a va2 s .c om }; Transformer<NodeMetadata, Number> vertexFactory = new Transformer<NodeMetadata, Number>() { int n = 0; public Number transform(NodeMetadata md) { return n++; } }; Transformer<EdgeMetadata, Number> edgeFactory = new Transformer<EdgeMetadata, Number>() { int n = 100; public Number transform(EdgeMetadata md) { return n++; } }; Transformer<HyperEdgeMetadata, Number> hyperEdgeFactory = new Transformer<HyperEdgeMetadata, Number>() { int n = 0; public Number transform(HyperEdgeMetadata md) { return n++; } }; // Read the graph object. Reader fileReader = new InputStreamReader(getClass().getResourceAsStream("hyper.graphml")); GraphMLReader2<Hypergraph<Number, Number>, Number, Number> hyperreader = new GraphMLReader2<Hypergraph<Number, Number>, Number, Number>( fileReader, graphFactory, vertexFactory, edgeFactory, hyperEdgeFactory); // Read the graph. Hypergraph<Number, Number> graph = hyperreader.readGraph(); Assert.assertEquals(graph.getVertexCount(), 7); Assert.assertEquals(graph.getEdgeCount(), 4); // n0 Set<Number> incident = new HashSet<Number>(); incident.add(0); incident.add(100); Assert.assertEquals(incident, graph.getIncidentEdges(0)); // n1 incident.clear(); incident.add(0); incident.add(2); Assert.assertEquals(incident, graph.getIncidentEdges(1)); // n2 incident.clear(); incident.add(0); Assert.assertEquals(incident, graph.getIncidentEdges(2)); // n3 incident.clear(); incident.add(1); incident.add(2); Assert.assertEquals(incident, graph.getIncidentEdges(3)); // n4 incident.clear(); incident.add(1); incident.add(100); Assert.assertEquals(incident, graph.getIncidentEdges(4)); // n5 incident.clear(); incident.add(1); Assert.assertEquals(incident, graph.getIncidentEdges(5)); // n6 incident.clear(); incident.add(1); Assert.assertEquals(incident, graph.getIncidentEdges(6)); }
From source file:org.apache.sling.scripting.sightly.impl.filter.URIManipulationFilter.java
private void handleSelectors(RenderContextImpl rci, Set<String> selectors, Map<String, Object> options) { if (options.containsKey(SELECTORS)) { Object selectorsOption = options.get(SELECTORS); if (selectorsOption == null) { // we want to remove all selectors selectors.clear(); } else if (selectorsOption instanceof String) { String selectorString = (String) selectorsOption; String[] selectorsArray = selectorString.split("\\."); replaceSelectors(selectors, selectorsArray); } else if (selectorsOption instanceof Object[]) { Object[] selectorsURIArray = (Object[]) selectorsOption; String[] selectorsArray = new String[selectorsURIArray.length]; int index = 0; for (Object selector : selectorsURIArray) { selectorsArray[index++] = rci.toString(selector); }/* ww w .j ava2 s.com*/ replaceSelectors(selectors, selectorsArray); } } Object addSelectorsOption = options.get(ADD_SELECTORS); if (addSelectorsOption instanceof String) { String selectorString = (String) addSelectorsOption; String[] selectorsArray = selectorString.split("\\."); addSelectors(selectors, selectorsArray); } else if (addSelectorsOption instanceof Object[]) { Object[] selectorsURIArray = (Object[]) addSelectorsOption; String[] selectorsArray = new String[selectorsURIArray.length]; int index = 0; for (Object selector : selectorsURIArray) { selectorsArray[index++] = rci.toString(selector); } addSelectors(selectors, selectorsArray); } Object removeSelectorsOption = options.get(REMOVE_SELECTORS); if (removeSelectorsOption instanceof String) { String selectorString = (String) removeSelectorsOption; String[] selectorsArray = selectorString.split("\\."); removeSelectors(selectors, selectorsArray); } else if (removeSelectorsOption instanceof Object[]) { Object[] selectorsURIArray = (Object[]) removeSelectorsOption; String[] selectorsArray = new String[selectorsURIArray.length]; int index = 0; for (Object selector : selectorsURIArray) { selectorsArray[index++] = rci.toString(selector); } removeSelectors(selectors, selectorsArray); } }
From source file:main.java.db.twitter.TwitterDatabase.java
/** * For each User (Follower) we select how many users he is following (followees List) * then select users to fill up that list. * Selecting is based on the distribution. * NOTE: We are using two different distribution to avoid correlation: * ZipfianGenerator (describes the followed most) * ScrambledZipfianGenerator (describes the heavy tweeters) */// w ww. j ava2 s . c om private void loadFollowData() { Table tbl_followers = this.getTable(this.getDb_tbl_name_id_map().get(TwitterConstants.TBL_FOLLOWERS)); Table tbl_follows = this.getTable(this.getDb_tbl_name_id_map().get(TwitterConstants.TBL_FOLLOWS)); // Foreign Tables ArrayList<Integer> ftblList_followers = new ArrayList<Integer>(tbl_followers.getTbl_foreign_tables()); Table ftbl_followers = this.getTable(ftblList_followers.get(0)); ArrayList<Integer> ftblList_follows = new ArrayList<Integer>(tbl_follows.getTbl_foreign_tables()); Table ftbl_follows = this.getTable(ftblList_follows.get(0)); // Distributions tbl_followers.zipfDistribution = new ZipfDistribution(this.num_users, TwitterConstants.ZIPF_EXP); tbl_followers.zipfDistribution.reseedRandomGenerator(Global.repeatedRuns); tbl_follows.zipfDistribution = new ZipfDistribution(this.num_follows, TwitterConstants.ZIPF_EXP); tbl_follows.zipfDistribution.reseedRandomGenerator(Global.repeatedRuns); ZipfianGenerator zipfFollowee = new ZipfianGenerator(this.num_users, TwitterConstants.ZIPF_EXP); ZipfianGenerator zipfFollows = new ZipfianGenerator(this.num_follows, TwitterConstants.ZIPF_EXP); Set<Integer> allFollowees = new HashSet<Integer>(); Set<Integer> followees = new HashSet<Integer>(); int follower = 0, followee = 0; for (follower = 1; follower <= this.num_users; follower++) { // Adding a new 'Follower' ++Global.global_tupleSeq; Tuple follower_tpl = this.insertTuple(tbl_follows.getTbl_id(), follower); followees.clear(); int time = zipfFollows.nextInt() + 1; //time = tbl_follows.zipfDistribution.sample(); // At least this follower will follow 1 user if (time == 0) time = 1; for (int f = 0; f < time;) { followee = zipfFollowee.nextInt() + 1; //followee = tbl_followers.zipfDistribution.sample(); if (follower != followee && !followees.contains(followee)) { followees.add(followee); // Adding a new 'Followee' if not exists Tuple followee_tpl; if (!allFollowees.contains(followee)) { ++Global.global_tupleSeq; followee_tpl = this.insertTuple(tbl_followers.getTbl_id(), followee); } else { followee_tpl = tbl_followers.getTupleByPk(followee); } // Follows Table ('follower' follows 'followee' || f2 follows f1 ) // Populating foreign table relationships if (follower_tpl.getTuple_fk().containsKey(ftbl_follows.getTbl_id())) { follower_tpl.getTuple_fk().get(ftbl_follows.getTbl_id()).add(followee); } else { Set<Integer> followeeSet = new HashSet<Integer>(); followeeSet.add(followee); follower_tpl.getTuple_fk().put(ftbl_follows.getTbl_id(), followeeSet); } // Insert into index tbl_follows.insertSecondaryIdx(follower, followee); // Followers Table ('followee' is followed by 'follower' || f1 is followed by f2) // Populating foreign table relationships if (followee_tpl.getTuple_fk().containsKey(ftbl_followers.getTbl_id())) { followee_tpl.getTuple_fk().get(ftbl_followers.getTbl_id()).add(follower); } else { Set<Integer> followerSet = new HashSet<Integer>(); followerSet.add(follower); followee_tpl.getTuple_fk().put(ftbl_followers.getTbl_id(), followerSet); } // Insert into index tbl_followers.insertSecondaryIdx(followee, follower); ++f; } //end-if() } //end-for() } //end-for() tbl_followers.setTbl_last_entry(followee); tbl_follows.setTbl_last_entry(follower); Global.LOGGER.info(tbl_followers.getTbl_tuples().size() + " tuples have successfully inserted into '" + tbl_followers.getTbl_name() + "' table."); Global.LOGGER.info(tbl_follows.getTbl_tuples().size() + " tuples have successfully inserted into '" + tbl_follows.getTbl_name() + "' table."); }
From source file:org.apache.lens.cube.metadata.TestDateUtil.java
@Test public void testTimeDiff() throws LensException { ArrayList<String> minusFourDays = Lists.newArrayList("-4 days", "-4days", "-4day", "-4 day", "- 4days", "- 4 day"); ArrayList<String> plusFourDays = Lists.newArrayList("+4 days", "4 days", "+4days", "4day", "4 day", "+ 4days", "+ 4 day", "+4 day"); Set<TimeDiff> diffs = Sets.newHashSet(); for (String diffStr : minusFourDays) { diffs.add(TimeDiff.parseFrom(diffStr)); }/* w ww . ja v a 2 s. co m*/ assertEquals(diffs.size(), 1); TimeDiff minusFourDaysDiff = diffs.iterator().next(); assertEquals(minusFourDaysDiff.quantity, -4); assertEquals(minusFourDaysDiff.updatePeriod, DAILY); diffs.clear(); for (String diffStr : plusFourDays) { diffs.add(TimeDiff.parseFrom(diffStr)); } assertEquals(diffs.size(), 1); TimeDiff plusFourDaysDiff = diffs.iterator().next(); assertEquals(plusFourDaysDiff.quantity, 4); assertEquals(plusFourDaysDiff.updatePeriod, DAILY); Date now = new Date(); assertEquals(minusFourDaysDiff.offsetFrom(plusFourDaysDiff.offsetFrom(now)), now); assertEquals(plusFourDaysDiff.offsetFrom(minusFourDaysDiff.offsetFrom(now)), now); assertEquals(minusFourDaysDiff.negativeOffsetFrom(now), plusFourDaysDiff.offsetFrom(now)); assertEquals(minusFourDaysDiff.offsetFrom(now), plusFourDaysDiff.negativeOffsetFrom(now)); }