Advertisement
Guest User

Untitled

a guest
May 28th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. package com.bytebach.impl;
  2.  
  3. import java.util.*;
  4.  
  5. import com.bytebach.model.*;
  6.  
  7. public class MyDatabase implements Database {
  8.  
  9. Collection<? extends Table> tables;
  10.  
  11. public MyDatabase(){
  12.  
  13. }
  14.  
  15. @Override
  16. public Collection<? extends Table> tables() {
  17. return tables;
  18. }
  19.  
  20. @Override
  21. public Table table(String name) {
  22. for(Table t : tables){
  23. if(t.name().equals(name)){
  24. return t;
  25. }
  26. }
  27. // TODO Auto-generated method stub
  28. return null;
  29. }
  30.  
  31. @Override
  32. public void createTable(String name, List<Field> fields) {
  33. if(table(name)!=null){
  34. throw new InvalidOperation("Table already exists");
  35. }
  36. Table newTable = new MyTable(name,fields);
  37.  
  38. tables.add(newTable);
  39.  
  40.  
  41. }
  42.  
  43. @Override
  44. public void deleteTable(String name) {
  45. for(Table t : tables){
  46. if(t.name().equals(name)){
  47. tables.remove(t);
  48. //references thingy
  49. }
  50. }
  51. throw new InvalidOperation("Fuck");
  52.  
  53.  
  54.  
  55. }
  56. // This is where you'll probably want to start. You'll need to provide an
  57. // implementation of Table as well.
  58. //
  59. // One of the key challenges in this assignment is to provide you're
  60. // own implementations of the List interface which can intercept the various
  61. // operations (e.g. add, set, remove, etc) and check whether they violate
  62. // the constraints and/or update the database appropriately (e.g. for the
  63. // cascading delete).
  64. //
  65. // HINT: to get started, don't bother providing your own implementations of
  66. // List as discussed above! Instead, implement MyDatabase and MyTabe using
  67. // conventional Collections. When you have that working, and the web system
  68. // is doing something sensible, then consider how you're going to get those
  69. // unit test to past.
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement