001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.search.generic;
016    
017    import com.liferay.portal.kernel.search.BaseQueryImpl;
018    import com.liferay.portal.kernel.search.TermRangeQuery;
019    import com.liferay.portal.kernel.util.CharPool;
020    import com.liferay.portal.kernel.util.StringBundler;
021    
022    /**
023     * @author Raymond Augé
024     */
025    public class TermRangeQueryImpl extends BaseQueryImpl
026            implements TermRangeQuery {
027    
028            public TermRangeQueryImpl(
029                    String field, String lowerTerm, String upperTerm, boolean includesLower,
030                    boolean includesUpper) {
031    
032                    _field = field;
033                    _lowerTerm = lowerTerm;
034                    _upperTerm = upperTerm;
035                    _includesLower = includesLower;
036                    _includesUpper = includesUpper;
037            }
038    
039            public String getField() {
040                    return _field;
041            }
042    
043            public String getLowerTerm() {
044                    return _lowerTerm;
045            }
046    
047            public String getUpperTerm() {
048                    return _upperTerm;
049            }
050    
051            @Override
052            public Object getWrappedQuery() {
053                    return this;
054            }
055    
056            public boolean includesLower() {
057                    return _includesLower;
058            }
059    
060            public boolean includesUpper() {
061                    return _includesUpper;
062            }
063    
064            @Override
065            public String toString() {
066                    StringBundler sb = new StringBundler(7);
067    
068                    sb.append(_field);
069                    sb.append(CharPool.COLON);
070    
071                    if (_includesLower) {
072                            sb.append(CharPool.OPEN_BRACKET);
073                    }
074                    else {
075                            sb.append(CharPool.OPEN_CURLY_BRACE);
076                    }
077    
078                    if (_lowerTerm != null) {
079                            sb.append(_lowerTerm);
080                    }
081                    else {
082                            sb.append(CharPool.STAR);
083                    }
084    
085                    sb.append(" TO ");
086    
087                    if (_upperTerm != null) {
088                            sb.append(_upperTerm);
089                    }
090                    else {
091                            sb.append(CharPool.STAR);
092                    }
093    
094                    if (_includesUpper) {
095                            sb.append(CharPool.CLOSE_BRACKET);
096                    }
097                    else {
098                            sb.append(CharPool.CLOSE_CURLY_BRACE);
099                    }
100    
101                    return sb.toString();
102            }
103    
104            private String _field;
105            private boolean _includesLower;
106            private boolean _includesUpper;
107            private String _lowerTerm;
108            private String _upperTerm;
109    
110    }