LightJason - AgentSpeak(L++)
CFuzzyValueMutable.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.fuzzy;
25 
28 
29 import javax.annotation.Nonnull;
30 import javax.annotation.Nullable;
31 import java.util.Arrays;
32 import java.util.Objects;
33 
34 
38 public final class CFuzzyValueMutable<T> implements IFuzzyValueMutable<T>
39 {
43  private T m_value;
47  private double m_fuzzy;
48 
54  public CFuzzyValueMutable( @Nonnull final T p_value )
55  {
56  this( p_value, 1 );
57  }
58 
64  public CFuzzyValueMutable( @Nonnull final IFuzzyValue<T> p_value )
65  {
66  m_value = p_value.value();
67  m_fuzzy = p_value.fuzzy();
68  }
69 
76  public CFuzzyValueMutable( @Nonnull final T p_value, final double p_fuzzy )
77  {
78  if ( !( ( p_fuzzy >= 0 ) && ( p_fuzzy <= 1 ) ) )
79  throw new CIllegalArgumentException( CCommon.languagestring( this, "fuzzyvalue", p_value ) );
80 
81  m_value = p_value;
82  m_fuzzy = p_fuzzy;
83  }
84 
85  @Nonnull
86  @Override
87  public final IFuzzyValueMutable<T> value( @Nullable final T p_value )
88  {
89  m_value = p_value;
90  return this;
91  }
92 
93  @Nonnull
94  @Override
95  public final IFuzzyValueMutable<T> fuzzy( final double p_value )
96  {
97  if ( !( ( p_value >= 0 ) && ( p_value <= 1 ) ) )
98  throw new CIllegalArgumentException( CCommon.languagestring( this, "fuzzyvalue", p_value ) );
99  m_fuzzy = p_value;
100  return this;
101  }
102 
103  @Nonnull
104  @Override
105  public final IFuzzyValue<T> immutable()
106  {
107  return CFuzzyValue.<T>from( m_value, m_fuzzy );
108  }
109 
110  @Nonnull
111  @Override
112  public final T value()
113  {
114  return m_value;
115  }
116 
117  @Override
118  public final double fuzzy()
119  {
120  return m_fuzzy;
121  }
122 
123  @Override
124  public final boolean valueassignableto( @Nonnull final Class<?>... p_class )
125  {
126  return Objects.isNull( m_value ) || Arrays.stream( p_class ).anyMatch( i -> i.isAssignableFrom( m_value.getClass() ) );
127  }
128 
129  @Nullable
130  @Override
131  public final T throwvaluenotassignableto( @Nonnull final Class<?>... p_class ) throws IllegalArgumentException
132  {
133  if ( !this.valueassignableto( p_class ) )
134  throw new CIllegalArgumentException( CCommon.languagestring( this, "notassignable", Arrays.asList( p_class ) ) );
135 
136  return m_value;
137  }
138 
147  @Nonnull
148  public static <N> IFuzzyValueMutable<N> from( @Nonnull final N p_value )
149  {
150  return new CFuzzyValueMutable<>( p_value );
151  }
152 
162  @Nonnull
163  public static <N> IFuzzyValueMutable<N> from( @Nonnull final N p_value, final double p_fuzzy )
164  {
165  return new CFuzzyValueMutable<>( p_value, p_fuzzy );
166  }
167 
168 }
CFuzzyValueMutable( @Nonnull final IFuzzyValue< T > p_value)
ctor
final IFuzzyValueMutable< T > value( @Nullable final T p_value)
final T throwvaluenotassignableto( @Nonnull final Class<?>... p_class)
throws an illegal argument exception iif the value is not assignable to the class ...
static< T > String languagestring(final T p_source, final String p_label, final Object... p_parameter)
returns the language depend string on any object
static< N > IFuzzyValueMutable< N > from( @Nonnull final N p_value, final double p_fuzzy)
factory
final IFuzzyValue< T > immutable()
returns an immutable instance of the object
final boolean valueassignableto( @Nonnull final Class<?>... p_class)
checkes assignable of the value
result for an immutable fuzzy value
final IFuzzyValueMutable< T > fuzzy(final double p_value)
sets the weight
static< N > IFuzzyValueMutable< N > from( @Nonnull final N p_value)
factory
CFuzzyValueMutable( @Nonnull final T p_value, final double p_fuzzy)
ctor