Untitled
unknown
plain_text
2 years ago
2.4 kB
7
Indexable
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class TableManager {
private Map<String, List<Record>> table;
public TableManager() {
table = new HashMap<>();
}
// Method to add a record to the table
public void addRecord(Record record) {
// Iterate through each field and add the record to the corresponding lists in the HashMap
addRecordToList(record.getName(), record);
addRecordToList(record.getNumber(), record);
addRecordToList(record.getBirthday(), record);
addRecordToList(record.getEmail(), record);
addRecordToList(record.getMemo(), record);
}
// Helper method to add a record to a list associated with a specific field value in the HashMap
private void addRecordToList(String fieldValue, Record record) {
List<Record> records = table.getOrDefault(fieldValue, new ArrayList<>());
records.add(record);
table.put(fieldValue, records);
}
// Method to get records by field value
public List<Record> getRecordsByField(String fieldName) {
return table.getOrDefault(fieldName, new ArrayList<>());
}
}
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class TableManager {
private Map<String, List<Record>> table;
public TableManager() {
table = new HashMap<>();
}
// Method to add a record to the table
public void addRecord(Record record) {
// Iterate through each field and add the record to the corresponding lists in the HashMap
addRecordToList(record.getName(), record);
addRecordToList(record.getNumber(), record);
addRecordToList(record.getBirthday(), record);
addRecordToList(record.getEmail(), record);
addRecordToList(record.getMemo(), record);
}
// Helper method to add a record to a list associated with a specific field value in the HashMap
private void addRecordToList(String fieldValue, Record record) {
List<Record> records = table.getOrDefault(fieldValue, new ArrayList<>());
records.add(record);
table.put(fieldValue, records);
}
// Method to get records by field value
public List<Record> getRecordsByField(String fieldName) {
return table.getOrDefault(fieldName, new ArrayList<>());
}
}
Editor is loading...