LightJason - AgentSpeak(L++)
IBaseUnary.java
Go to the documentation of this file.
1 /*
2  * @cond LICENSE
3  * ######################################################################################
4  * # LGPL License #
5  * # #
6  * # This file is part of the LightJason AgentSpeak(L++) #
7  * # Copyright (c) 2015-19, LightJason (info@lightjason.org) #
8  * # This program is free software: you can redistribute it and/or modify #
9  * # it under the terms of the GNU Lesser General Public License as #
10  * # published by the Free Software Foundation, either version 3 of the #
11  * # License, or (at your option) any later version. #
12  * # #
13  * # This program is distributed in the hope that it will be useful, #
14  * # but WITHOUT ANY WARRANTY; without even the implied warranty of #
15  * # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
16  * # GNU Lesser General Public License for more details. #
17  * # #
18  * # You should have received a copy of the GNU Lesser General Public License #
19  * # along with this program. If not, see http://www.gnu.org/licenses/ #
20  * ######################################################################################
21  * @endcond
22  */
23 
24 package org.lightjason.agentspeak.language.execution.expression;
25 
29 
30 import javax.annotation.Nonnull;
31 import java.text.MessageFormat;
32 import java.util.stream.Stream;
33 
34 
38 public abstract class IBaseUnary implements IUnaryExpression
39 {
43  private static final long serialVersionUID = -8992581726613099958L;
47  protected final EOperator m_operator;
51  protected final IExpression m_expression;
52 
53 
60  protected IBaseUnary( @Nonnull final EOperator p_operator, @Nonnull final IExpression p_expression )
61  {
62  if ( !p_operator.isUnary() )
63  throw new CIllegalArgumentException( CCommon.languagestring( IBaseUnary.class, "operator", p_operator ) );
64 
65  m_operator = p_operator;
66  m_expression = p_expression;
67  }
68 
69  @Nonnull
70  @Override
71  public final IExpression expression()
72  {
73  return m_expression;
74  }
75 
76  @Nonnull
77  @Override
78  public final EOperator operator()
79  {
80  return m_operator;
81  }
82 
83  @Override
84  public final int hashCode()
85  {
86  return m_expression.hashCode() ^ m_operator.hashCode();
87  }
88 
89  @Override
90  public final boolean equals( final Object p_object )
91  {
92  return ( p_object instanceof IExpression ) && ( this.hashCode() == p_object.hashCode() );
93  }
94 
95  @Override
96  public final String toString()
97  {
98  return MessageFormat.format( "{0}({1})", m_operator, m_expression );
99  }
100 
101  @Nonnull
102  @Override
103  public final Stream<IVariable<?>> variables()
104  {
105  return m_expression.variables();
106  }
107 
108 }
final IExpression m_expression
left-hand-side argument
Definition: IBaseUnary.java:51
Stream< IVariable<?> > variables()
returns a stream with all used variables
static< T > String languagestring(final T p_source, final String p_label, final Object... p_parameter)
returns the language depend string on any object
final IExpression expression()
returns the expression
Definition: IBaseUnary.java:71
IBaseUnary( @Nonnull final EOperator p_operator, @Nonnull final IExpression p_expression)
ctor
Definition: IBaseUnary.java:60
final EOperator operator()
return expression operator
Definition: IBaseUnary.java:78
final Stream< IVariable<?> > variables()
returns a stream with all used variables