001/*
002 *  Copyright 2021 Anyware Services
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package org.ametys.plugins.repository.query.expression;
017
018/**
019 * Object that gives some context for expressions
020 */
021public class ExpressionContext
022{
023    private boolean _unversioned;
024    private boolean _internal;
025    private boolean _caseInsensitive;
026    
027    /**
028     * Creates a new instance of a {@link ExpressionContext}
029     */
030    protected ExpressionContext()
031    {
032        // Empty private constructor
033    }
034    
035    /**
036     * Creates a new instance of a {@link ExpressionContext}
037     * @return the created instance
038     */
039    public static ExpressionContext newInstance()
040    {
041        return new ExpressionContext();
042    }
043    
044    /**
045     * Determines if the data under the expression is internal
046     * @return <code>true</code> if the data is internal, <code>false</code> otherwise
047     */
048    public boolean unversioned()
049    {
050        return _unversioned;
051    }
052    
053    /**
054     * Set to <code>true</code> to create an expression for unversioned data (default to <code>false</code>) 
055     * @param unversioned <code>true</code> to create an expression for unversioned data, <code>false</code> otherwise
056     * @return the current {@link ExpressionContext}
057     */
058    public ExpressionContext withUnversioned(boolean unversioned)
059    {
060        _unversioned = unversioned;
061        return this;
062    }
063    
064    /**
065     * Determines if the data under the expression is internal
066     * @return <code>true</code> if the data is internal, <code>false</code> otherwise
067     */
068    public boolean internal()
069    {
070        return _internal;
071    }
072    
073    /**
074     * Set to <code>true</code> to create an expression for internal data (default to <code>false</code>) 
075     * @param internal <code>true</code> to create an expression for internal data, <code>false</code> otherwise
076     * @return the current {@link ExpressionContext}
077     */
078    public ExpressionContext withInternal(boolean internal)
079    {
080        _internal = internal;
081        return this;
082    }
083    
084    /**
085     * Determines if the expression is not case sensitive
086     * @return <code>true</code> if the expression is not case sensitive, <code>false</code> otherwise
087     */
088    public boolean caseInsensitive()
089    {
090        return _caseInsensitive;
091    }
092    
093    /**
094     * Set to <code>true</code> to create a case insensitive expression (default to <code>false</code>) 
095     * @param caseInsensitive <code>true</code> to create a case insensitive expression, <code>false</code> otherwise
096     * @return the current {@link ExpressionContext}
097     */
098    public ExpressionContext withCaseInsensitive(boolean caseInsensitive)
099    {
100        _caseInsensitive = caseInsensitive;
101        return this;
102    }
103}