001    /**
002     * Copyright (c) 2000-present 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.kernel.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.search.query.QueryVisitor;
020    import com.liferay.portal.kernel.util.CharPool;
021    import com.liferay.portal.kernel.util.StringBundler;
022    
023    /**
024     * @author Raymond Aug??
025     */
026    public class TermRangeQueryImpl
027            extends BaseQueryImpl implements TermRangeQuery {
028    
029            public TermRangeQueryImpl(
030                    String field, String lowerTerm, String upperTerm, boolean includesLower,
031                    boolean includesUpper) {
032    
033                    _field = field;
034                    _lowerTerm = lowerTerm;
035                    _upperTerm = upperTerm;
036                    _includesLower = includesLower;
037                    _includesUpper = includesUpper;
038            }
039    
040            @Override
041            public <T> T accept(QueryVisitor<T> queryVisitor) {
042                    return queryVisitor.visitQuery(this);
043            }
044    
045            @Override
046            public String getField() {
047                    return _field;
048            }
049    
050            @Override
051            public String getLowerTerm() {
052                    return _lowerTerm;
053            }
054    
055            @Override
056            public String getUpperTerm() {
057                    return _upperTerm;
058            }
059    
060            @Override
061            public boolean includesLower() {
062                    return _includesLower;
063            }
064    
065            @Override
066            public boolean includesUpper() {
067                    return _includesUpper;
068            }
069    
070            @Override
071            public String toString() {
072                    StringBundler sb = new StringBundler(7);
073    
074                    sb.append(_field);
075                    sb.append(CharPool.COLON);
076    
077                    if (_includesLower) {
078                            sb.append(CharPool.OPEN_BRACKET);
079                    }
080                    else {
081                            sb.append(CharPool.OPEN_CURLY_BRACE);
082                    }
083    
084                    if (_lowerTerm != null) {
085                            sb.append(_lowerTerm);
086                    }
087                    else {
088                            sb.append(CharPool.STAR);
089                    }
090    
091                    sb.append(" TO ");
092    
093                    if (_upperTerm != null) {
094                            sb.append(_upperTerm);
095                    }
096                    else {
097                            sb.append(CharPool.STAR);
098                    }
099    
100                    if (_includesUpper) {
101                            sb.append(CharPool.CLOSE_BRACKET);
102                    }
103                    else {
104                            sb.append(CharPool.CLOSE_CURLY_BRACE);
105                    }
106    
107                    return sb.toString();
108            }
109    
110            private final String _field;
111            private final boolean _includesLower;
112            private final boolean _includesUpper;
113            private final String _lowerTerm;
114            private final String _upperTerm;
115    
116    }