LightJason - AgentSpeak(L++)
CRelocateMutexVariable.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.variable;
25 
30 
31 import javax.annotation.Nonnull;
32 import javax.annotation.Nullable;
33 import java.util.Objects;
34 
35 
41 public final class CRelocateMutexVariable<T> extends CMutexVariable<T> implements IRelocateVariable
42 {
46  private static final long serialVersionUID = 6680660424006072619L;
50  private final IVariable<?> m_relocate;
51 
52 
58  public CRelocateMutexVariable( final IVariable<?> p_variable )
59  {
60  super( p_variable.functor(), p_variable.raw() );
61  m_relocate = p_variable;
62  }
63 
69  public CRelocateMutexVariable( @Nonnull final IPath p_functor, @Nonnull final IVariable<?> p_relocate )
70  {
71  super( p_functor, p_relocate.raw() );
72  m_relocate = p_relocate;
73  }
74 
82  private CRelocateMutexVariable( @Nonnull final IPath p_functor, @Nonnull final IVariable<?> p_variable, @Nullable final T p_value )
83  {
84  super( p_functor, p_value );
85  m_relocate = p_variable;
86  }
87 
88  @Nonnull
89  @Override
90  public final IVariable<?> relocate()
91  {
92  return m_relocate instanceof CConstant<?>
93  ? m_relocate
94  : m_relocate.set( this.raw() );
95  }
96 
97 
98  @Nonnull
99  @Override
100  public final IVariable<T> shallowcopy( @Nullable final IPath... p_prefix )
101  {
102  return ( Objects.isNull( p_prefix ) ) || ( p_prefix.length == 0 )
104  : new CRelocateMutexVariable<>( p_prefix[0].append( m_functor ), m_relocate, m_value );
105  }
106 
107  @Nonnull
108  @Override
109  public final ITerm deepcopysuffix()
110  {
111  return new CRelocateMutexVariable<>( CPath.from( m_functor.suffix() ), m_relocate, CCommon.deepclone( m_value ) );
112  }
113 
114  @Nonnull
115  @Override
116  public final ITerm deepcopy( final IPath... p_prefix )
117  {
118  return new CRelocateMutexVariable<>(
119  ( Objects.isNull( p_prefix ) ) || ( p_prefix.length == 0 )
120  ? m_functor
121  : m_functor.append( p_prefix[0] ),
122  m_relocate,
123  CCommon.deepclone( m_value )
124  );
125  }
126 
127  @Nonnull
128  @Override
130  {
132  }
133 
134 }
CRelocateMutexVariable( @Nonnull final IPath p_functor, @Nonnull final IVariable<?> p_relocate)
ctor
IVariable< T > set( @Nullable final T p_value)
sets the value
final synchronized< N > N raw()
cast to any raw value type
common structure for execution definition
final IVariable<?> m_relocate
reference to relocated variable
interface for relocated variables (linkage between two variables for transfering the value) ...
static IPath from( @Nonnull final String p_string)
factor method to build path
Definition: CPath.java:166
class to create a path structure
Definition: CPath.java:53
final IVariable<?> relocate()
sets the value into the relocated variable and returns the modifed variable
final IPath m_functor
variable / functor name
Definition: CVariable.java:55
CRelocateMutexVariable( @Nonnull final IPath p_functor, @Nonnull final IVariable<?> p_variable, @Nullable final T p_value)
private ctor for creating object-copy
final IVariable< T > shallowcopy( @Nullable final IPath... p_prefix)
clones the object (shallow-copy)
final IVariable< T > shallowcopysuffix()
clones the object (shallow-copy) without full-qualified path, only suffix is used ...
IPath append( @Nonnull final IPath p_path)
appends a path at the current and returns a new object
String suffix()
returns the last part of the path