Skip to content

Instantly share code, notes, and snippets.

@mati23
Created January 30, 2023 20:54
Show Gist options
  • Save mati23/c9965a9e9a0232bea57c8127b7783398 to your computer and use it in GitHub Desktop.
Save mati23/c9965a9e9a0232bea57c8127b7783398 to your computer and use it in GitHub Desktop.
Mateus - Interview
public static Main(ArrayList<Transactions> transactions){
HashMap<String, ArrayList<Transactions>> hashMap = new HashMat<>();
for(Transaction transaction : transactions){
if(hashMap.get(transaction.hashCode()) == null){
ArrayList<Transaction> arrayList = new ArrayList();
arrayList.add(transaction);
hashMap.put(transaction.hashCode(), arrayList);
}else{
arrayList = hashMap.get(hashCode());
arrayList.add(transaction);
}
}
Iterable iterable = hashMap.iterable();
ArrayList<ArrayList<Transaction>> result = new ArrayList<>();
while(iterable.hasNext()){
result.add(iterable.next);
}
return result;
}
public class Transaction(){
private int id;
private String sourceAccount;
private String targetAccount;
private int amount;
private String category;
private String time;
public Transaction(){}
//getters and setters
public boolean equals(Transaction t){
if(this.sourceAccount == t.getSourceAccount()
&& this.targetAccount == t.getSourceAccount()
&& this.ammount == t.getAmmount()
&& this.category == t.getCategory()
&& (Math.mod(this.time) - Math.mod(t.getTime()) < 60)){
return true;
}
return false;
}
public String hashCode(){
return this.sourceAccount().toString() + this.targetAccount().toString() + this.ammount().toString() + this.category().toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment