Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Opensec UTIL - https://nakamura5akihito.github.io/ Copyright (C) 2015 Akihito Nakamura Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package io.opensec.util.search;



An aggregation of sets of objects.

Author(s):
Akihito Nakamura, AIST
See also:
Function
 
 public class Aggregation
     implements Projection
 {
     private static final long  serialVersionUID = 3941437174859447411L;



    
An expression that denotes all the objects: "*".
 
     public static final String  WHOLE_OBJECT_EXPRESSION = "*";



    
Creates a 'COUNT(*)' aggregation. This is a shortcut to:
new Aggregation( "*", AggregateFunction.COUNT )

Returns:
a 'COUNT(*)' aggregation.
 
     public static Aggregation countAll()
     {
         return (new Aggregation. ));
     }




    
Creates a 'COUNT' aggregation. This is a shortcut to:
new Aggregation( expr, AggregateFunction.COUNT )

Parameters:
expr the expression.
Returns:
a 'COUNT' aggregation.
 
     public static Aggregation count(
                     final String expr
                     )
     {
         return (new Aggregationexpr. ));
     }



    
Creates a 'MAX' aggregation.

Parameters:
expr the expression.
Returns:
a 'MAX' aggregation.
 
     public static Aggregation max(
                     final String expr
                     )
     {
         return (new Aggregationexpr. ));
     }



    
Creates a 'MIN' aggregation.

Parameters:
expr the expression.
Returns:
a 'MIN' aggregation.
    public static Aggregation min(
                    final String expr
                    )
    {
        return (new Aggregationexpr. ));
    }



    
Creates a 'SUM' aggregation.

Parameters:
expr the expression.
Returns:
a 'SUM' aggregation.
    public static Aggregation sum(
                    final String expr
                    )
    {
        return (new Aggregationexpr. ));
    }



    
Creates a 'AVG' aggregation.

Parameters:
expr the expression.
Returns:
a 'AVG' aggregation.
    public static Aggregation avg(
                    final String expr
                    )
    {
        return (new Aggregationexpr. ));
    }





    
The expression.
    private String  _expression;



    
The aggregate function.
    private Function  _function;
    public static final Function  DEFAULT_FUNCTION = .;




    
Default constructor.
    public Aggregation()
    {
        this );
    }



    
Constructs an AggregateFunction with the specified expression and function.

Parameters:
expr the expression.
function the function.
    public Aggregation(
                    final String expr,
                    final Function function
                    )
    {
        setExpressionexpr );
        setFunctionfunction );
    }




    
Sets the expression.

Parameters:
expr the expression.
    public void setExpression(
                    final String expr
                    )
    {
         = expr;
    }



    
Returns the expression.

Returns:
the expression.
    public String getExpression()
    {
        return ;
    }



    
Sets the aggregate function.

Parameters:
function the function.
    public void setFunction(
                    final Function function
                    )
    {
         = function;
    }



    
Returns the aggregate function.

Returns:
the function.
    public Function getFunction()
    {
        return ( == null ?  : );
    }
    //**************************************************************
    //  java.lang.Object
    //**************************************************************

    
Determines whether another object is equal to this Aggregation. The result is true if and only if the argument is not null and is an Aggregation object that has the same expression and function.

Parameters:
obj the object to test for equality with this Aggregation.
Returns:
true if the given object equals this one; false otherwise.
    @Override
    public boolean equals(
                    final Object obj
                    )
    {
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof Aggregation)) {
            return false;
        }
        Aggregation  other = (Aggregation)obj;
        String  other_expr = other.getExpression();
        String   this_expr =  this.getExpression();
        if (other_expr == this_expr
                ||  (other_expr != null  &&  other_expr.equalsthis_expr ))) {
            if (other.getFunction() == this.getFunction()) {
                return true;
            }
        }
        return false;
    }



    
Computes the hash code for this Aggregation.

Returns:
a hash code value for this object.
    @Override
    public int hashCode()
    {
        final int  prime = 37;
        int  result = 17;
        String  expr = getExpression();
        result = prime * result + (expr == null ? 0 : expr.hashCode());
        Function  func = getFunction();
        result = prime * result + (func == null ? 0 : func.hashCode());
        return result;
    }



    
Returns a string representation of this Aggregation. This method is intended to be used only for debugging purposes. The content and format of the returned string might not conform to any query language syntax.

Returns:
a string representation of this Aggregation.
    @Override
    public String toString()
    {
        return "Aggregation[expression=" + getExpression()
                    + ", function=" + getFunction()
                    + "]";
    }
// Aggregation
New to GrepCode? Check out our FAQ X