Mentions légales du service

Skip to content
Snippets Groups Projects
Commit e7b602a1 authored by Adrien's avatar Adrien
Browse files

hashmap good

parent a8276eb8
No related branches found
No related tags found
No related merge requests found
File deleted
File deleted
package kdiv;
import java.util.HashMap;
import java.util.Map;
/**
* The Distribution class manages a collections of Objects and their associated values.
*/
public class Distribution {
private Map<Object, Integer> objectMap;
/**
* Initialization
*/
public Distribution() {
this.objectMap = new HashMap<>();
}
/**
* Adds an object with an associated integer value.
* @param obj The object to store.
* @param value The integer value associated with the object.
*/
public void addObject(Object obj, int value) {
objectMap.put(obj, value);
}
/**
* Retrieves the value of a given object.
* @param obj The object to look up.
* @return The associated integer value, or null if not found.
*/
public Integer getValue(Object obj) {
return objectMap.getOrDefault(obj, null);
}
/**
* Checks if the object exists in the distribution.
* @param obj The object to check.
* @return True if the object exists, false otherwise.
*/
public boolean contains(Object obj) {
return objectMap.containsKey(obj);
}
/**
* Gets the entire distribution as a HashMap.
* @return The HashMap storing object-value pairs.
*/
public Map<Object, Integer> getObjectMap() {
return objectMap;
}
@Override
public String toString() {
return objectMap.toString();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment