LightJason - AgentSpeak(L++)
ITrigger.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 
32 
33 import javax.annotation.Nonnull;
34 import javax.annotation.Nullable;
35 import java.io.Serializable;
36 import java.util.Arrays;
37 import java.util.Collections;
38 import java.util.Map;
39 import java.util.Objects;
40 import java.util.stream.Collectors;
41 
42 
50 public interface ITrigger extends Serializable, IStructureHash, IShallowCopy<ITrigger>, Comparable<ITrigger>
51 {
56  {
60  private static final long serialVersionUID = -4216254162765675258L;
61 
62  @Override
63  public final int structurehash()
64  {
65  return 0;
66  }
67 
68  @Nonnull
69  @Override
70  public final ITrigger shallowcopy( @Nullable final IPath... p_prefix )
71  {
72  return this;
73  }
74 
75  @Nonnull
76  @Override
77  public final ITrigger shallowcopysuffix()
78  {
79  return this;
80  }
81 
82  @Override
83  public final int compareTo( @Nonnull final ITrigger p_trigger )
84  {
85  return Integer.compare( p_trigger.hashCode(), this.hashCode() );
86  }
87 
88  @Override
89  public final EType type()
90  {
91  return EType.EMPTY;
92  }
93 
94  @Override
95  public final ILiteral literal()
96  {
97  return ILiteral.EMPTY;
98  }
99 
100  @Override
101  public final int variablesize()
102  {
103  return 0;
104  }
105 
106  @Override
107  public final int hashCode()
108  {
109  return 0;
110  }
111 
112  @Override
113  public final boolean equals( final Object p_object )
114  {
115  return ( p_object instanceof ITrigger ) && ( this.hashCode() == p_object.hashCode() );
116  }
117  };
118 
124  EType type();
125 
131  ILiteral literal();
132 
138  int variablesize();
139 
140 
141 
145  enum EType
146  {
147  ADDBELIEF( "+" ),
148  DELETEBELIEF( "-" ),
149  ADDGOAL( "+!" ),
150  DELETEGOAL( "-!" ),
151  EMPTY( "" );
152 
156  private static final Map<String, EType> ELEMENTS = Collections.unmodifiableMap(
157  Arrays.stream( EType.values() )
158  .collect( Collectors.toMap( EType::sequence, i -> i ) )
159  );
160 
164  private final String m_name;
165 
171  EType( final String p_name )
172  {
173  m_name = p_name;
174  }
175 
176  @Override
177  public String toString()
178  {
179  return m_name;
180  }
181 
187  public final String sequence()
188  {
189  return m_name;
190  }
191 
197  public static EType from( @Nonnull final String p_sequence )
198  {
199  final EType l_type = ELEMENTS.get( p_sequence.trim() );
200  if ( Objects.isNull( l_type ) )
201  throw new CIllegalArgumentException( CCommon.languagestring( EType.class, "sequencenotfound", p_sequence ) );
202 
203  return l_type;
204  }
205  }
206 
207 }
T shallowcopysuffix()
clones the object (shallow-copy) without full-qualified path, only suffix is used ...
interface to create shallow-copy of objects
static< T > String languagestring(final T p_source, final String p_label, final Object... p_parameter)
returns the language depend string on any object
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)
static EType from( @Nonnull final String p_sequence)
returns a trigger type by the char sequence
Definition: ITrigger.java:197