• Views
  • Iteration Report
  • My Iteration Report
  •  
OMERO.server
  • Login
  • Help/Guide
  • About Trac
  • Preferences
  • Wiki
  • Timeline
  • Roadmap
  • Browse Source
  • View Tickets
  • Search

Context Navigation

  • Last Change
  • Annotate
  • Revision Log

root/trunk/components/common/src/ome/parameters/QueryParameter.java

Revision 1167, 3.5 kB (checked in by jmoore, 2 years ago)

[svn:keywords] Id,Date,Revision,URL for *.java and Id for *.xml

  • Property svn:keywords set to
    Date
    Revision
    Id
    URL
Line 
1/*
2 * ome.parameters.QueryParameter
3 *
4 *   Copyright 2006 University of Dundee. All rights reserved.
5 *   Use is subject to license terms supplied in LICENSE.txt
6 */
7
8package ome.parameters;
9
10// Java imports
11import java.io.IOException;
12import java.io.InvalidObjectException;
13import java.io.ObjectInputStream;
14import java.io.Serializable;
15
16// Third-party libraries
17
18// Application-internal dependencies
19import ome.conditions.ApiUsageException;
20
21/**
22 * arbitrary query parameter used by {@link ome.api.IQuery}.
23 *
24 * @author <br>
25 *         Josh Moore&nbsp;&nbsp;&nbsp;&nbsp; <a
26 *         href="mailto:josh.moore@gmx.de"> josh.moore@gmx.de</a>
27 * @version 3.0 <small> (<b>Internal version:</b> $Revision$ $Date$)
28 *          </small>
29 * @since 3.0-M2
30 */
31public class QueryParameter implements Serializable {
32
33    final public Class type;
34
35    final public String name;
36
37    final public Object value;
38
39    public QueryParameter(String name, Class type, Object value) {
40
41        if (name == null) {
42            throw new ApiUsageException("Expecting a value for name.");
43        }
44
45        if (type == null) {
46            throw new ApiUsageException("Expecting a value for type.");
47        }
48
49        if (value == null || type.isAssignableFrom(value.getClass())) {
50            this.name = name;
51            this.type = type;
52            this.value = value;
53        } else {
54            StringBuffer sb = new StringBuffer();
55            sb.append("Value object should be of type: ");
56            sb.append(type.getName());
57            sb.append(" and not: ");
58            sb.append(value.getClass().getName());
59            throw new ApiUsageException(sb.toString());
60        }
61    }
62
63    @Override
64    public String toString() {
65        StringBuffer sb = new StringBuffer(64);
66        sb.append("QP{");
67        sb.append("name=");
68        sb.append(name);
69        sb.append(",type=");
70        sb.append(type.getName());
71        sb.append(",value=");
72        sb.append(value);
73        sb.append("}");
74        return sb.toString();
75    }
76
77    @Override
78    public boolean equals(Object obj) {
79        if (!(obj instanceof QueryParameter)) {
80            return false;
81        }
82
83        QueryParameter qp = (QueryParameter) obj;
84
85        if (this == qp) {
86            return true;
87        }
88
89        if (!this.name.equals(qp.name)) {
90            return false;
91        }
92        if (!this.type.equals(qp.type)) {
93            return false;
94        }
95
96        return this.value == null ? qp.value == null : this.value
97                .equals(qp.value);
98
99    }
100
101    @Override
102    public int hashCode() {
103        int result = 11;
104        result = 17 * result + name.hashCode();
105        result = 19 * result + type.hashCode();
106        result = 23 * result + (value == null ? 0 : value.hashCode());
107        return result;
108    }
109
110    // ~ Serialization
111    // =========================================================================
112    private static final long serialVersionUID = 112229651549133492L;
113
114    private void readObject(ObjectInputStream s) throws IOException,
115            ClassNotFoundException {
116        s.defaultReadObject();
117
118        if (type == null) {
119            throw new InvalidObjectException(
120                    "QueryParameter type cannot be null.");
121        }
122
123        if (value == null) {
124            throw new InvalidObjectException(
125                    "QueryParameter value cannot be null.");
126        }
127
128        if (!type.isAssignableFrom(value.getClass())) {
129            throw new InvalidObjectException(
130                    "QueryParameter value must be of type type.");
131        }
132    }
133
134}
Note: See TracBrowser for help on using the browser.

Download in other formats:

  • Plain Text
  • Original Format

Trac Powered

Powered by Trac 0.11
By Edgewall Software.

Visit the Trac open source project at
http://trac.edgewall.org/