1<?xml version="1.0" encoding="UTF-8" standalone="no"?> 2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 3<html xmlns="http://www.w3.org/1999/xhtml"> 4 <head> 5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 6 <title> 7 Using Sorted Collections 8 </title> 9 <link rel="stylesheet" href="gettingStarted.css" type="text/css" /> 10 <meta name="generator" content="DocBook XSL Stylesheets V1.62.4" /> 11 <link rel="home" href="index.html" title="Berkeley DB Collections Tutorial" /> 12 <link rel="up" href="Tuple.html" title="Chapter��5.�� 		Using Tuples 	" /> 13 <link rel="previous" href="tuple-serialentitybindings.html" title=" Creating Tuple-Serial Entity Bindings " /> 14 <link rel="next" href="SerializableEntity.html" title="Chapter��6.�� 		Using Serializable Entities 	" /> 15 </head> 16 <body> 17 <div class="navheader"> 18 <table width="100%" summary="Navigation header"> 19 <tr> 20 <th colspan="3" align="center"> 21 Using Sorted Collections 22 </th> 23 </tr> 24 <tr> 25 <td width="20%" align="left"><a accesskey="p" href="tuple-serialentitybindings.html">Prev</a>��</td> 26 <th width="60%" align="center">Chapter��5.�� 27 Using Tuples 28 </th> 29 <td width="20%" align="right">��<a accesskey="n" href="SerializableEntity.html">Next</a></td> 30 </tr> 31 </table> 32 <hr /> 33 </div> 34 <div class="sect1" lang="en" xml:lang="en"> 35 <div class="titlepage"> 36 <div> 37 <div> 38 <h2 class="title" style="clear: both"><a id="sortedcollections"></a> 39 Using Sorted Collections 40 </h2> 41 </div> 42 </div> 43 <div></div> 44 </div> 45 <p> 46 In general, no changes to the prior example are necessary to use 47 collections having tuple keys. Iteration of elements in a stored 48 collection will be ordered by the sort order of the tuples. 49</p> 50 <p> 51 In addition to using the tuple format, the 52 <a href="../../java/com/sleepycat/db/DatabaseType.html#BTREE" target="_top">DatabaseType.BTREE</a> 53 54 access method must be used when creating the database. 55 <a href="../../java/com/sleepycat/db/DatabaseType.html#BTREE" target="_top">DatabaseType.BTREE</a> 56 57 is used for the databases in all examples. The 58 <a href="../../java/com/sleepycat/db/DatabaseType.html#HASH" target="_top">DatabaseType.HASH</a> 59 60 access method does not support sorted keys. 61</p> 62 <p> 63 Although not shown in the example, all methods of the 64 <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/SortedMap.html" target="_top">SortedMap</a> 65 66 and 67 <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/SortedSet.html" target="_top">SortedSet</a> 68 69 interfaces may be used with sorted collections. For example, 70 submaps and subsets may be created. 71</p> 72 <p> 73 The output of the example program shows that records are sorted 74 by key value. 75</p> 76 <pre class="programlisting">Adding Suppliers 77Adding Parts 78Adding Shipments 79 80--- Parts --- 81Part: number=P1 name=Nut color=Red weight=[12.0 grams] city=London 82Part: number=P2 name=Bolt color=Green weight=[17.0 grams] city=Paris 83Part: number=P3 name=Screw color=Blue weight=[17.0 grams] city=Rome 84Part: number=P4 name=Screw color=Red weight=[14.0 grams] city=London 85Part: number=P5 name=Cam color=Blue weight=[12.0 grams] city=Paris 86Part: number=P6 name=Cog color=Red weight=[19.0 grams] city=London 87 88--- Suppliers --- 89Supplier: number=S1 name=Smith status=20 city=London 90Supplier: number=S2 name=Jones status=10 city=Paris 91Supplier: number=S3 name=Blake status=30 city=Paris 92Supplier: number=S4 name=Clark status=20 city=London 93Supplier: number=S5 name=Adams status=30 city=Athens 94 95--- Suppliers for City Paris --- 96Supplier: number=S2 name=Jones status=10 city=Paris 97Supplier: number=S3 name=Blake status=30 city=Paris 98 99--- Shipments --- 100Shipment: part=P1 supplier=S1 quantity=300 101Shipment: part=P1 supplier=S2 quantity=300 102Shipment: part=P2 supplier=S1 quantity=200 103Shipment: part=P2 supplier=S2 quantity=400 104Shipment: part=P2 supplier=S3 quantity=200 105Shipment: part=P2 supplier=S4 quantity=200 106Shipment: part=P3 supplier=S1 quantity=400 107Shipment: part=P4 supplier=S1 quantity=200 108Shipment: part=P4 supplier=S4 quantity=300 109Shipment: part=P5 supplier=S1 quantity=100 110Shipment: part=P5 supplier=S4 quantity=400 111Shipment: part=P6 supplier=S1 quantity=100 112 113--- Shipments for Part P1 --- 114Shipment: part=P1 supplier=S1 quantity=300 115Shipment: part=P1 supplier=S2 quantity=300 116 117--- Shipments for Supplier S1 --- 118Shipment: part=P1 supplier=S1 quantity=300 119Shipment: part=P2 supplier=S1 quantity=200 120Shipment: part=P3 supplier=S1 quantity=400 121Shipment: part=P4 supplier=S1 quantity=200 122Shipment: part=P5 supplier=S1 quantity=100 123Shipment: part=P6 supplier=S1 quantity=100 </pre> 124 </div> 125 <div class="navfooter"> 126 <hr /> 127 <table width="100%" summary="Navigation footer"> 128 <tr> 129 <td width="40%" align="left"><a accesskey="p" href="tuple-serialentitybindings.html">Prev</a>��</td> 130 <td width="20%" align="center"> 131 <a accesskey="u" href="Tuple.html">Up</a> 132 </td> 133 <td width="40%" align="right">��<a accesskey="n" href="SerializableEntity.html">Next</a></td> 134 </tr> 135 <tr> 136 <td width="40%" align="left" valign="top"> 137Creating Tuple-Serial Entity Bindings 138��</td> 139 <td width="20%" align="center"> 140 <a accesskey="h" href="index.html">Home</a> 141 </td> 142 <td width="40%" align="right" valign="top">��Chapter��6.�� 143 Using Serializable Entities 144 </td> 145 </tr> 146 </table> 147 </div> 148 </body> 149</html> 150