Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package vaje12;
- import java.util.Collection;
- import java.util.Iterator;
- /**
- *
- * @author sk0019
- */
- public class Vaje12 {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- // TODO code application logic here
- }
- }
- class DinamicnaTabela implements Collection<Object> {
- Object[] tab;
- int size;
- public DinamicnaTabela() {
- this.tab = new Object[10];
- this.size=10;
- }
- public DinamicnaTabela(int len) {
- this.tab = new Object[len];
- this.size = len;
- }
- @Override
- public int size() {
- for(int i = 0; i < size; i++){
- if(tab[i]==(null))
- return i;
- }
- return size;
- }
- @Override
- public boolean isEmpty() {
- for(int i = 0; i < size; i++){
- if(tab[i]!=(null))
- return false;
- }
- return true;
- }
- @Override
- public boolean contains(Object o) {
- for(int i = 0; i < size; i++){
- if(tab[i]==o)
- return true;
- }
- return false;
- }
- @Override
- public Iterator<Object> iterator() {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
- @Override
- public Object[] toArray() {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
- @Override
- public <T> T[] toArray(T[] a) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
- @Override
- public boolean add(Object e) {
- if(size()==size){
- Object[] nov = new Object[size + 1];
- for(int z = 0; z < size; z++){
- nov[z] = tab[z];
- }
- nov[size + 1] = e;
- this.tab = nov;
- }
- else
- tab[size()]=e;
- return true;
- }
- @Override
- public boolean remove(Object o) {
- for(int y =0; y < size(); y++){
- if(tab[y]==o){
- tab[y]=null;
- }
- }
- return true;
- }
- @Override
- public boolean containsAll(Collection<?> c) throws IzjemaNepodprteOperacije {
- throw new IzjemaNepodprteOperacije();
- }
- @Override
- public boolean addAll(Collection<? extends Object> c) {
- for(Object o:c){
- add(o);
- }
- return true;
- }
- @Override
- public boolean removeAll(Collection<?> c) {
- for(Object o:c){
- if(!remove(o)){return false;}
- }
- return true;
- }
- @Override
- public boolean retainAll(Collection<?> c)throws IzjemaNepodprteOperacije {
- throw new IzjemaNepodprteOperacije();
- }
- @Override
- public void clear() throws IzjemaNepodprteOperacije{
- throw new IzjemaNepodprteOperacije();
- }
- }
- class IzjemaNepodprteOperacije extends RuntimeException {
- @Override
- public String getMessage(){
- return "Nepodprta Operacija";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement