1/*-
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 2002,2008 Oracle.  All rights reserved.
5 *
6 * $Id: ShipmentKey.java,v 12.7 2008/01/08 20:58:29 bostic Exp $
7 */
8
9package collections.ship.factory;
10
11import com.sleepycat.bind.tuple.MarshalledTupleEntry;
12import com.sleepycat.bind.tuple.TupleInput;
13import com.sleepycat.bind.tuple.TupleOutput;
14
15/**
16 * A ShipmentKey serves as the key in the key/data pair for a shipment entity.
17 *
18 * <p> In this sample, ShipmentKey is bound to the stored key tuple entry by
19 * implementing the MarshalledTupleEntry interface, which is called by {@link
20 * SampleViews.MarshalledKeyBinding}. </p>
21 *
22 * @author Mark Hayes
23 */
24public class ShipmentKey implements MarshalledTupleEntry {
25
26    private String partNumber;
27    private String supplierNumber;
28
29    public ShipmentKey(String partNumber, String supplierNumber) {
30
31        this.partNumber = partNumber;
32        this.supplierNumber = supplierNumber;
33    }
34
35    public final String getPartNumber() {
36
37        return partNumber;
38    }
39
40    public final String getSupplierNumber() {
41
42        return supplierNumber;
43    }
44
45    public String toString() {
46
47        return "[ShipmentKey: supplier=" + supplierNumber +
48                " part=" + partNumber + ']';
49    }
50
51    // --- MarshalledTupleEntry implementation ---
52
53    public ShipmentKey() {
54
55        // A no-argument constructor is necessary only to allow the binding to
56        // instantiate objects of this class.
57    }
58
59    public void marshalEntry(TupleOutput keyOutput) {
60
61        keyOutput.writeString(this.partNumber);
62        keyOutput.writeString(this.supplierNumber);
63    }
64
65    public void unmarshalEntry(TupleInput keyInput) {
66
67        this.partNumber = keyInput.readString();
68        this.supplierNumber = keyInput.readString();
69    }
70}
71