Model Classes

This topic applies to Java version only 

Two simple classes Pilot and Id are pre-packed in a Pilot.jar:

Pilot.java
01/* Copyright (C) 2007 db4objects Inc. http://www.db4o.com */ 02package enhancement.model; 03 04public class Pilot { 05 String _name; 06 Id _id; 07 08 public Pilot(String name, Id id){ 09 _name = name; 10 _id = id; 11 } 12 13 public String get_name() { 14 return _name; 15 } 16 public void set_name(String _name) { 17 this._name = _name; 18 } 19 public Id get_id() { 20 return _id; 21 } 22 public void set_id(Id _id) { 23 this._id = _id; 24 } 25 26 public String toString(){ 27 return _name + ": " + _id; 28 } 29}
Id.java
01/* Copyright (C) 2007 db4objects Inc. http://www.db4o.com */ 02package enhancement.model; 03 04public class Id { 05 String _id; 06 07 public Id(String id){ 08 _id = id; 09 } 10 11 public String toString(){ 12 return _id; 13 } 14}

Linked collection of Car objects shows collection enhancement:

Car.java
01package enhancement.model; 02 03import tacustom.*; 04 05@Db4oPersistent 06public class Car { 07 08 private String _model = null; 09 Pilot _pilot; 10 11 public Car(String content, Pilot pilot) { 12 _model = content; 13 _pilot = pilot; 14 } 15 16 public String content() { 17 return _model; 18 } 19 20 public void content(String content) { 21 _model = content; 22 } 23 24 @Override 25 public String toString() { 26 return _model + "/" + _pilot; 27 } 28 29 public String getModel() { 30 return _model; 31 } 32 33 public Pilot getPilot() { 34 return _pilot; 35 } 36}
MaintenanceQueue.java
001/* Copyright (C) 2007 db4objects Inc. http://www.db4o.com */ 002 003package enhancement.model; 004 005import java.util.*; 006 007import tacustom.*; 008 009@Db4oPersistent 010 011public class MaintenanceQueue<Item> { 012 013 public MaintenanceQueue<Item> _next; 014 015 private Item _value; 016 017 public MaintenanceQueue(Item value) { 018 _value = value; 019 } 020 021 public static MaintenanceQueue<Integer> newList(int depth) { 022 if (depth == 0) { 023 return null; 024 } 025 MaintenanceQueue<Integer> head = new MaintenanceQueue<Integer>(depth); 026 head._next = newList(depth - 1); 027 return head; 028 } 029 030 /** 031 * Overrides this method to assert that <code>other</code> is only 032 * activated with depth 1. 033 */ 034 @SuppressWarnings("unchecked") 035 public boolean equals(Object other) { 036 return ((MaintenanceQueue<Item>) other)._next == null; 037 } 038 039 public boolean hasNext() { 040 return _next != null; 041 } 042 043 public MaintenanceQueue<Item> next() { 044 return _next; 045 } 046 047 public int size() { 048 if(_next == null) { 049 return 1; 050 } 051 return _next.size() + 1; 052 } 053 054 public Item get(int idx) { 055 if(idx == 0) { 056 return value(); 057 } 058 return _next.get(idx - 1); 059 } 060 061 public Item value() { 062 return _value; 063 } 064 065 public void add(Item item) { 066 if(_next != null) { 067 _next.add(item); 068 } 069 else { 070 _next = new MaintenanceQueue<Item>(item); 071 } 072 } 073 074 public Iterator<Item> iterator() { 075 return new LinkedListIterator<Item>(this); 076 } 077 078 public String toString() { 079 return "LinkedList: " + _value; 080 } 081 082 public static <Item> MaintenanceQueue<Item> add(MaintenanceQueue<Item> list, Item item) { 083 if(list == null) { 084 return new MaintenanceQueue<Item>(item); 085 } 086 list.add(item); 087 return list; 088 } 089 090 private final static class LinkedListIterator<Item> implements Iterator<Item> { 091 private MaintenanceQueue<Item> _current; 092 093 public LinkedListIterator(MaintenanceQueue<Item> list) { 094 _current = list; 095 } 096 097 public boolean hasNext() { 098 return _current != null; 099 } 100 101 public Item next() { 102 Item item = _current.value(); 103 _current = _current.next(); 104 return item; 105 } 106 107 public void remove() { 108 throw new UnsupportedOperationException(); 109 } 110 } 111 112 public static <Item> Iterator<Item> iterator(MaintenanceQueue<Item> list) { 113 return (list == null ? new LinkedListIterator<Item>(null) : list.iterator()); 114 } 115 116}