Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions src/com/school/faang/hashmap/задача_3/Solution.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,53 @@
package com.school.faang.hashmap.задача_3;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

public class Solution {
public static void main(String[] args) {
Map<Product, Integer> basket = new HashMap<>();
int counter = 0;

Product phone = new Product("@qwerty", "Phone 16");
Product iPhone = new Product("@qwerty", "Phone 16");

basket.put(phone, ++counter);
basket.put(iPhone, ++counter);

System.out.println(basket);
}
}

class Product {
private String productId;
private String name;

private Product product;

public Product(String productId, String name) {
this.productId = productId;
this.name = name;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Product product = (Product) o;
return Objects.equals(productId, product.productId);
}

@Override
public int hashCode() {
return Objects.hash(productId);
}

@Override
public String toString() {
return "Product{" +
"productId='" + productId + '\'' +
", name='" + name + '\'' +
'}';
}
}