LightJason - AgentSpeak(L++)
CTrigger.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.instantiable.plan.trigger;
25 
29 
30 import javax.annotation.Nonnull;
31 import java.text.MessageFormat;
32 
33 
37 public final class CTrigger implements ITrigger
38 {
42  private static final long serialVersionUID = -4216265954626567558L;
46  private final int m_variables;
50  private final ILiteral m_literal;
54  private final EType m_event;
58  private final int m_hashcode;
62  private final int m_structurehash;
63 
70  @SuppressWarnings( "unchecked" )
71  public CTrigger( @Nonnull final EType p_event, @Nonnull final ILiteral p_literal )
72  {
73  m_event = p_event;
74  m_literal = p_literal;
75  m_variables = CCommon.variablefrequency( p_literal ).size();
76  m_hashcode = m_event.hashCode() ^ m_literal.hashCode();
77  m_structurehash = m_event.hashCode() ^ m_literal.structurehash();
78  }
79 
87  public static ITrigger from( @Nonnull final EType p_event, @Nonnull final ILiteral p_literal )
88  {
89  return new CTrigger( p_event, p_literal );
90  }
91 
92  @Override
93  public final int hashCode()
94  {
95  return m_hashcode;
96  }
97 
98  @Override
99  public final boolean equals( final Object p_object )
100  {
101  return ( p_object instanceof ITrigger ) && ( this.hashCode() == p_object.hashCode() );
102  }
103 
104  @Override
105  public final String toString()
106  {
107  return MessageFormat.format( "{0}{1}", m_event, m_literal );
108  }
109 
110  @Override
111  public final EType type()
112  {
113  return m_event;
114  }
115 
116  @Override
117  public final ILiteral literal()
118  {
119  return m_literal;
120  }
121 
122  @Override
123  public final int variablesize()
124  {
125  return m_variables;
126  }
127 
128  @Override
129  public final int structurehash()
130  {
131  return m_structurehash;
132  }
133 
134  @Nonnull
135  @Override
136  public final ITrigger shallowcopy( final IPath... p_prefix )
137  {
138  return new CTrigger( m_event, m_literal.shallowcopy( p_prefix ) );
139  }
140 
141  @Nonnull
142  @Override
144  {
145  return new CTrigger( m_event, m_literal.shallowcopysuffix() );
146  }
147 
148  @Override
149  public final int compareTo( @Nonnull final ITrigger p_other )
150  {
151  return p_other.toString().compareTo( this.toString() );
152  }
153 }
T shallowcopysuffix()
clones the object (shallow-copy) without full-qualified path, only suffix is used ...
CTrigger( @Nonnull final EType p_event, @Nonnull final ILiteral p_literal)
ctor
Definition: CTrigger.java:71
final int structurehash()
returns a hash value which defines a hash ove rthe structure
Definition: CTrigger.java:129
common structure for execution definition
static ITrigger from( @Nonnull final EType p_event, @Nonnull final ILiteral p_literal)
creates a trigger event^
Definition: CTrigger.java:87
final int compareTo( @Nonnull final ITrigger p_other)
Definition: CTrigger.java:149
final ILiteral literal()
returns the literal of the event
Definition: CTrigger.java:117
int structurehash()
returns a hash value which defines a hash ove rthe structure
T shallowcopy( @Nullable final IPath... p_prefix)
clones the object (shallow-copy)
final ITrigger shallowcopysuffix()
clones the object (shallow-copy) without full-qualified path, only suffix is used ...
Definition: CTrigger.java:143
final ILiteral m_literal
literal with unified variables
Definition: CTrigger.java:50