Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.ArrayList;
- import java.util.Collections;
- public class MyContainer <T extends Learner> extends ArrayList<T> implements Cloneable{
- public T min() throws EmptyContainerException{
- if(this.isEmpty()){
- throw new EmptyContainerException();
- }
- return Collections.min(this) ;
- }
- public void printContent() throws EmptyContainerException{
- if(this.isEmpty()){
- throw new EmptyContainerException();
- }
- for(T elem : this ){
- elem.printInfo();
- }
- }
- public Learner findElem(T t) throws EmptyContainerException{
- if(this.isEmpty()){
- throw new EmptyContainerException();
- }
- MyContainer<T> myContainer = (MyContainer<T>) this.clone();
- Collections.sort(myContainer);
- int index = Collections.binarySearch(myContainer, t);
- if(index>=0) {
- return myContainer.get(index);
- }
- else{
- return null;
- }
- }
- public int countSameElem(T t) throws EmptyContainerException{
- if(this.isEmpty()){
- throw new EmptyContainerException();
- }
- return Collections.frequency(this,t);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment