Guest User

Untitled

a guest
Jun 22nd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. package myarchive;
  2.  
  3. import wsiarchive.*;
  4.  
  5.  
  6. // Archiv, bei dem erst ein Archiv vollgeschrieben wird, dann das nächste etc.
  7. public class OverflowArchive implements IArchive {
  8.  
  9. private String name;
  10. private IArchiveList archives;
  11.  
  12. // Die Archive werden der Reihe nach gefüllt
  13. public OverflowArchive(String name, IArchiveList archives) {
  14. this.name = name;
  15. this.archives = archives;
  16. }
  17.  
  18. // Name des Archivs liefern
  19. public String getName(){
  20. return this.name;
  21. }
  22.  
  23. // Liste der Archive ausgeben
  24. public IArchiveList getArchives(){
  25. return this.archives;
  26. }
  27.  
  28. // Item ins Archiv schreiben
  29. public IPutResult put(Item item){
  30. IPutResult result = this.archives.put(item);
  31. if (archives instanceof EmptyArchiveList){ // wenn die Archivliste leer ist
  32. throw new AssertionError("there is no archive to write - wrong archive strucure");
  33. } else if (result instanceof FullPutResult){
  34. return result;
  35. } else {
  36. // dann erzeuge ein neues OK-Result mit diesem Archiv und entsprechender Id
  37. return new OKPutResult(new OwnItemId(this, ((OKPutResult) result).getId()));
  38. }
  39. }
  40.  
  41. // Mehrere Items ins Archiv schreiben
  42. public wsiarchive.IPutResultList putMultiple(wsiarchive.IItemList items) {
  43. return items.putAll(this);
  44. }
  45.  
  46. // Item aus Archiv auslesen
  47. public IGetResult get(IItemId id) {
  48. if (id instanceof OwnItemId){
  49. OwnItemId tempId = ((OwnItemId)id);
  50. if (this == tempId.getArchive()){
  51. return tempId.get();
  52. } else {
  53. return new NoItemResult();
  54. }
  55. } else {
  56. return new NoItemResult();
  57. }
  58. }
  59.  
  60. }
Add Comment
Please, Sign In to add comment