I want to get a unique elements from the page. I'am calculating total number of records. Each record belong to a user, hence there are multiple records with the belongs to the same user. I want to get the total with the unique number of users.
List<WebElement> efirstpagecount = driver.findElements(By.xpath("//*[#id='usersList']/tbody/tr/td[3]"));
Set<WebElement> uniquecount = new HashSet<WebElement>(efirstpagecount);
System.out.println("Unique count: " + uniquecount.size());
for (WebElement u : uniquecount ) {
System.out.println(u.getText());
}
Output:
Unique count: 20
robin
Rocky
prom
jack
stone
Veronica
Veronica
Shawn
Rocky
carl
Rocky
James
Rocky
sam
bon
sam
bone
don
Shawn
don
Above code is giving me the the count including the duplicate values. Please advise how to get the unique values. Thanks in advance!
Assuming the td just has the username, you can try something like this in java 8.
Set<String> uniqueUsers = efirstpagecount.stream()
.map(WebElement::getText).map(String::trim)
.distinct().collect(Collectors.toSet());
Related
I have set and a sub-set for each id. i need to accumulate the total
ex: employeeIdSet is the outer set which has all the employeeIds
Now each employee - may be combined or not combined and they will be added credits
empa - credit 10
empb linked with empc, empd - credit would be 15, overall for the 3 employees.
similalrly
empe linked with empz, emps - credit would be 7, over all for the 3 employees and linked with empq where the credit is 9
similarly
empr linked with empo - credit would be 6, overall for the 2 employees
Now i want to have a list of employee id with respective credits
ex:
empa-10
emp-15,
empc-15,
empd-15,
empe - 7+9,
empz - 7+9,
emps- 7+9,
empr - 6,
empo - 6
the problem we get employee id in the outer loop and inner loop we can get the subsequent employees. however all addition leads to problem
code
final Set<Long> combinedEmployeeIdSet = new HashSet<>();
final Set<CombinedEmployee> combinedEmployees = employee.getCombinedEmployees();
for(final CombinedEmployee combinedEmployee: combinedEmployees) {
combinedEmployeeIdSet.add(combinedEmployee.getId());
}
for(final OtherEmployee otherEmployee: otherEmployees) {
if(!combinedEmployeeIdSet.contains(otherEmployee.getId())) {
employeeCredit += otherEmployee.getCredit();
}
}
expectation is get the total credits of the given employeeId where when there under same group, it should be added as one single unit, else the credit should be added
empe - 7+9, displays 15
empz - 7+9, displays 15
emps- 7+9, displays 15
thanks
Very confused by your description.
Do you mean you have some "emp"s, say: emp-a,emp-b ... emp-x, and each emp have a credit, say: emp-a:10, emp-b:5, emp-c:7... emp-x:6. Some emps have links with other emps, say: emp-a (emp-b, empc). Now you want to get the credit for each emp, if the emp has links, its credit should be a sumarize of itself and all its links.
So you may get
emp-a 10+5+7
emp-b 5
emp-c 7
...
emp-x 6
Hey i think i have some logic problem, but yet i cant really see where it is.
I know that the Problem is somewhere between HashSet, but thats it.
I am using a HashMap and the key is numberOfEpisode and the values are HashSet.
So if these animes in my List of Array has the same amount of Episode, like 12 then add them to a new HashSet and then into the HashMap.
Code
HashSet<Strings> animeNames;
for(Anime anime : animius.getListOfAnime){
animeNames = new HashSet<>();
for(Anime anime2 : animius.getListOfAnime){
for(Episode episode : anime.getListOEpisode){
for(Episode episode2 : anime2.getListOfEpisode{
if(episode.getNumber == episode2.getNumber){
animeNames.add(anime.getName);
animius.getEpisodeAndAnimeIndex.put(episode.getNumber, animeNames)
}
}
}
}
}
Output
After Formatting it. And Lets say only anime1 has similarities towards anime 2, but anime 2 has 2 Keys one with 12 Episode and the other one with 24 Episode.
12 ---- anime1, anime2 <--- this is correct
24 ---- anime1, anime2 <--- this is wrong
Expected Output
12 ---- anime1, anime2
24 ---- anime2
Attempted Solutions
I have created 2 HashSet with one which contains the values of anime.getName and the other one which contains anime2.getName.
I also played around with putting the new instantiation of animeNames and animeNames2 differently in the for each loops
If I haven't misunderstood you, you don't need to have 4 nested for loops. You just want to check for each anime in your collection what number of episodes they have and store that. Essentially group animes together by number of episodes. The code below does that.
HashMap<Integer, Set<Anime>> animeMap = new HashMap<>();
for(Anime anime : animius.getListOfAnime){
int numberOfEpisodes = anime.getListOEpisodes().size();
if (animeMap.contains(numberOfEpisodes) {
animeMap.get(numberOfEpisodes).add(anime);
} else {
HashSet<Anime> animeNames = new HashSet<>();
animeNames.add(anime);
animeMap.put(numberOfEpisodes, animeNames);
}
}
I am trying to figure out a way to delete a specific row from a table when it has the same row id as another couple rows in Accumulo. This is how I have my table set up:
m0 : property : name -> erp
m0 : property : age -> 23
m0 : purchase : food -> 5.00
m0 : purchase : gas -> 24.00
m0 : purchase : beer -> 15.00
Say I want to delete gas from the table. I know I could use connection.tableOperations().deleteRows(table, start, stop) but if I pass in the row id of m0 - 1 and m0 to the function it is going to delete all of these entries. Can I do a delete where colFam = something and colQual = something? I didn't see anything in the API to support this but frankenstein code is cool also :)
Yes it is possible. I was thinking of rows and columns still in a sql mindest. In order to delete a column (which is what I was thinking of) rather than a row. You just write another mutation. For example:
Text rowId = new Text("m0");
Text colFam = new Text("purchase");
Text colQual = new Text("gas");
Mutation mut = new Mutation(rowId);
mut.putDelete(colFam, colQual);
writer = connection.createBatchWriter(tableName, new BatchWriter());
try{
writer.addMutation(mut);
}catch{
...
}
Works perfect :)
This is my first post for help. Please correct me if you see anything wrong with my post.
I am trying to validate the sorting functionality in a web page with Selenium script (using java). here are the details...
First I go to a User search results page with multiple pages.
It has users with the details: user name, number of miles.
There is a sort filter drop down with values: Values A-Z, Values Z-A, Miles Most, Miles Least, Newest Members, Oldest members . by default the sorting is newest members.
Initially I just want to validate: Values A-Z, Values Z-A, Miles Most and Miles Least Since I could see those values in the search page.
For someone who is looking to solve the same problem. Below code worked for me in validating the sorting of all the string values in a page
//Declare Variables
int eleCount;
List<String> customerNameA = new ArrayList();
List<String> customerNameB = new ArrayList();
// Check for our Customer elements and count them.... replace xxx with your xpath
assertTrue(isElementPresent(By.xpath("xxx")));
elements = driver.findElements(By.xpath("xxx']"));
eleCount = elements.size();
System.out.println("Element count: " + eleCount);
for(int i = 2; i < eleCount; i++){
//Capture the customer name values
//replace xxx with your xpath & replace the value increments for each element in xpath with + i +
customerNameA.add(driver.findElement(By.xpath("xxx")).getText());
System.out.println(driver.findElement(By.xpath("xxx")).getText());
customerNameB.add(driver.findElement(By.xpath("xxx")).getText());
}
Collections.sort(customerNameA);
for (int i=0;i<customerNameA.size();i++) {
System.out.println("Customer Name from input: " + customerNameB.get(i) + "--Customer Name from sorted input: " + customerNameA.get(i));
if (!(customerNameA.get(i).equals(customerNameB.get(i)))) {
System.out.println("Customer Names not sorted: " + i);
break;
}
}
}
Fact table :
Id Year Month countryId Sales
1 1999 1 1 3000
2 1999 2 1 2300
3 2000 3 2 3999
4 2000 4 3 2939
Dimension table:
Id country province
1 US LA
2 US CA
3 US GA
4 EN LN
and I use Guava table like this :
Table<Integer, String, Object> table = Tables.newCustomTable(
Maps.<Integer, Map<String, Object>> newLinkedHashMap(),
new Supplier<Map<String, Object>>() {
public Map<String, Object> get() {
return Maps.newLinkedHashMap();
}
});
table.put(1, "Year", 1999);
table.put(1, "Month", 1);
table.put(1, "countyId", 1);
table.put(1, "Sales", 3000);
// ...... etc
table1.put(1, "county", "US");
table1.put(1, "provice", 1999);
// ......
I want to implement a LEFT JOIN like:
1 1999 1 1 3000 US LA
2 1999 2 1 2300 US LA
3 2000 3 2 3999 US CA
4 2000 4 3 2939 EN LN
What should I do?
Guava's Table isn't supposed to be used like any SQL's table, as it is a collection. SQL's tables are designed to be indexable, sortable, filterable, etc. Guava's Table has only a fraction of those and only indirectly, and joints aren't part of them (unless you play with transformations).
What you need to do is to have your two tables and loop through the elements of table and find the corresponding mapping in table1.
In your case, I believe you're better off with a List replacing table and a Guava Table for table1. Loop through the list and make your final objects as you get your elements.