1 /*
2 * ModeShape (http://www.modeshape.org)
3 * See the COPYRIGHT.txt file distributed with this work for information
4 * regarding copyright ownership. Some portions may be licensed
5 * to Red Hat, Inc. under one or more contributor license agreements.
6 * See the AUTHORS.txt file in the distribution for a full listing of
7 * individual contributors.
8 *
9 * ModeShape is free software. Unless otherwise indicated, all code in ModeShape
10 * is licensed to you under the terms of the GNU Lesser General Public License as
11 * published by the Free Software Foundation; either version 2.1 of
12 * the License, or (at your option) any later version.
13 *
14 * ModeShape is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this software; if not, write to the Free
21 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
23 */
24 package org.modeshape.graph.query.model;
25
26 import net.jcip.annotations.Immutable;
27 import org.modeshape.common.util.CheckArg;
28
29 /**
30 * A specification of the ordering for the results.
31 */
32 @Immutable
33 public class Ordering implements LanguageObject {
34 private static final long serialVersionUID = 1L;
35
36 private final DynamicOperand operand;
37 private final Order order;
38
39 /**
40 * Create a new ordering specification, given the supplied operand and order.
41 *
42 * @param operand the operand being ordered
43 * @param order the order type
44 * @throws IllegalArgumentException if the operand or order type is null
45 */
46 public Ordering( DynamicOperand operand,
47 Order order ) {
48 CheckArg.isNotNull(operand, "operand");
49 CheckArg.isNotNull(order, "order");
50 this.operand = operand;
51 this.order = order;
52 }
53
54 /**
55 * Get the operand being ordered.
56 *
57 * @return the operand; never null
58 */
59 public DynamicOperand operand() {
60 return operand;
61 }
62
63 /**
64 * The order type.
65 *
66 * @return the type; never null
67 */
68 public Order order() {
69 return order;
70 }
71
72 /**
73 * {@inheritDoc}
74 *
75 * @see java.lang.Object#toString()
76 */
77 @Override
78 public String toString() {
79 return Visitors.readable(this);
80 }
81
82 /**
83 * {@inheritDoc}
84 *
85 * @see java.lang.Object#hashCode()
86 */
87 @Override
88 public int hashCode() {
89 return operand.hashCode();
90 }
91
92 /**
93 * {@inheritDoc}
94 *
95 * @see java.lang.Object#equals(java.lang.Object)
96 */
97 @Override
98 public boolean equals( Object obj ) {
99 if (obj == this) return true;
100 if (obj instanceof Ordering) {
101 Ordering that = (Ordering)obj;
102 if (this.order != that.order) return false;
103 return this.operand.equals(that.operand);
104 }
105 return false;
106 }
107
108 /**
109 * {@inheritDoc}
110 *
111 * @see org.modeshape.graph.query.model.Visitable#accept(org.modeshape.graph.query.model.Visitor)
112 */
113 public void accept( Visitor visitor ) {
114 visitor.visit(this);
115 }
116 }