001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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            @Override
040            public String getField() {
041                    return _field;
042            }
043    
044            @Override
045            public String getLowerTerm() {
046                    return _lowerTerm;
047            }
048    
049            @Override
050            public String getUpperTerm() {
051                    return _upperTerm;
052            }
053    
054            @Override
055            public Object getWrappedQuery() {
056                    return this;
057            }
058    
059            @Override
060            public boolean includesLower() {
061                    return _includesLower;
062            }
063    
064            @Override
065            public boolean includesUpper() {
066                    return _includesUpper;
067            }
068    
069            @Override
070            public String toString() {
071                    StringBundler sb = new StringBundler(7);
072    
073                    sb.append(_field);
074                    sb.append(CharPool.COLON);
075    
076                    if (_includesLower) {
077                            sb.append(CharPool.OPEN_BRACKET);
078                    }
079                    else {
080                            sb.append(CharPool.OPEN_CURLY_BRACE);
081                    }
082    
083                    if (_lowerTerm != null) {
084                            sb.append(_lowerTerm);
085                    }
086                    else {
087                            sb.append(CharPool.STAR);
088                    }
089    
090                    sb.append(" TO ");
091    
092                    if (_upperTerm != null) {
093                            sb.append(_upperTerm);
094                    }
095                    else {
096                            sb.append(CharPool.STAR);
097                    }
098    
099                    if (_includesUpper) {
100                            sb.append(CharPool.CLOSE_BRACKET);
101                    }
102                    else {
103                            sb.append(CharPool.CLOSE_CURLY_BRACE);
104                    }
105    
106                    return sb.toString();
107            }
108    
109            private String _field;
110            private boolean _includesLower;
111            private boolean _includesUpper;
112            private String _lowerTerm;
113            private String _upperTerm;
114    
115    }