You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
895 B
33 lines
895 B
package com.example.datacollect.service;
|
|
import java.security.PublicKey;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
public class HistoryManager implements HistoryService{
|
|
private final List<String> history=new ArrayList<>();
|
|
private static final int MAX_SIZE=100;
|
|
@Override
|
|
public void add(String command){
|
|
if (command == null || command.trim().isEmpty()) {
|
|
return;
|
|
}
|
|
history.add(command.trim());
|
|
if (history.size() > MAX_SIZE) {
|
|
history.remove(0);
|
|
}
|
|
}
|
|
@Override
|
|
public List<String> getHistory() {
|
|
return new ArrayList<>(history);
|
|
}
|
|
@Override
|
|
public void clear() {
|
|
history.clear();
|
|
}
|
|
@Override
|
|
public String get(int index) {
|
|
if (index >= 0 && index < history.size()) {
|
|
return history.get(index);
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|