Advertisement
Guest User

Untitled

a guest
May 23rd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.39 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package vaje12;
  7.  
  8. import java.util.Collection;
  9. import java.util.Iterator;
  10.  
  11. /**
  12. *
  13. * @author sk0019
  14. */
  15. public class Vaje12 {
  16.  
  17. /**
  18. * @param args the command line arguments
  19. */
  20. public static void main(String[] args) {
  21. // TODO code application logic here
  22. }
  23.  
  24. }
  25. class DinamicnaTabela implements Collection<Object> {
  26.  
  27. Object[] tab;
  28. int size;
  29.  
  30. public DinamicnaTabela() {
  31. this.tab = new Object[10];
  32. this.size=10;
  33. }
  34. public DinamicnaTabela(int len) {
  35. this.tab = new Object[len];
  36. this.size = len;
  37. }
  38. @Override
  39. public int size() {
  40. for(int i = 0; i < size; i++){
  41. if(tab[i]==(null))
  42. return i;
  43. }
  44. return size;
  45. }
  46.  
  47. @Override
  48. public boolean isEmpty() {
  49. for(int i = 0; i < size; i++){
  50. if(tab[i]!=(null))
  51. return false;
  52. }
  53. return true;
  54. }
  55.  
  56. @Override
  57. public boolean contains(Object o) {
  58. for(int i = 0; i < size; i++){
  59. if(tab[i]==o)
  60. return true;
  61. }
  62. return false;
  63. }
  64.  
  65. @Override
  66. public Iterator<Object> iterator() {
  67. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  68. }
  69.  
  70. @Override
  71. public Object[] toArray() {
  72. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  73. }
  74.  
  75. @Override
  76. public <T> T[] toArray(T[] a) {
  77. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  78. }
  79.  
  80. @Override
  81. public boolean add(Object e) {
  82. if(size()==size){
  83. Object[] nov = new Object[size + 1];
  84. for(int z = 0; z < size; z++){
  85. nov[z] = tab[z];
  86. }
  87. nov[size + 1] = e;
  88. this.tab = nov;
  89. }
  90. else
  91. tab[size()]=e;
  92. return true;
  93. }
  94.  
  95. @Override
  96. public boolean remove(Object o) {
  97. for(int y =0; y < size(); y++){
  98. if(tab[y]==o){
  99. tab[y]=null;
  100. }
  101. }
  102. return true;
  103. }
  104.  
  105. @Override
  106. public boolean containsAll(Collection<?> c) throws IzjemaNepodprteOperacije {
  107. throw new IzjemaNepodprteOperacije();
  108. }
  109.  
  110. @Override
  111. public boolean addAll(Collection<? extends Object> c) {
  112. for(Object o:c){
  113. add(o);
  114. }
  115. return true;
  116. }
  117. @Override
  118. public boolean removeAll(Collection<?> c) {
  119. for(Object o:c){
  120. if(!remove(o)){return false;}
  121. }
  122. return true;
  123. }
  124.  
  125. @Override
  126. public boolean retainAll(Collection<?> c)throws IzjemaNepodprteOperacije {
  127. throw new IzjemaNepodprteOperacije();
  128. }
  129.  
  130. @Override
  131. public void clear() throws IzjemaNepodprteOperacije{
  132. throw new IzjemaNepodprteOperacije();
  133. }
  134.  
  135. }
  136. class IzjemaNepodprteOperacije extends RuntimeException {
  137. @Override
  138. public String getMessage(){
  139. return "Nepodprta Operacija";
  140. }
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement