KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ws > jaxme > sqls > db2 > PageSize


1 /*
2  * Copyright 2003, 2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15
16  */

17 package org.apache.ws.jaxme.sqls.db2;
18
19 /** <p>A DB2 page size is limited to certain values.</p>
20  */

21 public class PageSize {
22    /** The default page size (4096 bytes).
23     */

24    public static final PageSize PAGESIZE_4096 = new PageSize(4096);
25    /** The default page size (8192 bytes).
26     */

27    public static final PageSize PAGESIZE_8192 = new PageSize(8192);
28    /** The default page size (16384 bytes).
29     */

30    public static final PageSize PAGESIZE_16384 = new PageSize(16384);
31    /** The default page size (32768 bytes).
32     */

33    public static final PageSize PAGESIZE_32768 = new PageSize(32768);
34
35    private static final PageSize[] instances = new PageSize[]{
36       PAGESIZE_4096, PAGESIZE_8192, PAGESIZE_16384, PAGESIZE_32768
37    };
38
39    private long size;
40
41    private PageSize(long pSize) {
42       size = pSize;
43    }
44  
45    /** Returns the size of the pagesize specification.
46     */

47    public long getSize() { return size; }
48    public String JavaDoc toString() { return "PAGESIZE_" + size; }
49    public boolean equals(Object JavaDoc pOther) {
50       return pOther != null && pOther instanceof PageSize &&
51          size == ((PageSize) pOther).size;
52    }
53
54    /** Returns the possible pagesize specifications.
55     */

56    public static PageSize[] getInstances() { return instances; }
57
58    /** Converts the given string into a pagesize specification.
59     */

60    public static PageSize valueOf(String JavaDoc pSize) {
61       long l;
62       try {
63          l = Long.parseLong(pSize);
64       } catch (Exception JavaDoc e) {
65          throw new IllegalArgumentException JavaDoc("PageSize is no long value: " + pSize);
66       }
67       return valueOf(l);
68    }
69
70    /** Converts the given long value into a pagesize specification.
71     */

72    public static PageSize valueOf(long pSize) {
73       for (int i = 0; i < instances.length; i++) {
74          if (instances[i].size == pSize) {
75             return instances[i];
76          }
77       }
78       throw new IllegalArgumentException JavaDoc("Invalid page size: " + pSize);
79    }
80
81    public int hashCode() {
82       return (int) size / 4096;
83    }
84 }
85
Popular Tags