24 package org.lightjason.agentspeak.action.builtin.generic;
34 import javax.annotation.Nonnull;
35 import javax.annotation.Nullable;
36 import java.io.ObjectInputStream;
37 import java.io.PrintStream;
38 import java.io.Serializable;
39 import java.text.MessageFormat;
40 import java.util.Arrays;
41 import java.util.Collection;
42 import java.util.Collections;
43 import java.util.HashSet;
44 import java.util.List;
45 import java.util.Objects;
47 import java.util.stream.Collectors;
115 m_streamsupplier = p_streamsupplier;
116 m_stream = m_streamsupplier.
get();
117 m_seperator = p_seperator;
118 m_formatter = p_formatter != null ?
new HashSet<>( Arrays.asList( p_formatter ) ) : Collections.emptySet();
128 private void readObject(
final ObjectInputStream p_stream )
throws Exception
130 p_stream.defaultReadObject();
131 m_stream = m_streamsupplier.
get();
147 @Nonnull
final List<ITerm> p_argument, @Nonnull
final List<ITerm> p_return
150 m_stream.println( MessageFormat.format(
"{0}",
this.format( p_argument ) ) );
161 private String
format( @Nonnull
final Collection<ITerm> p_argument )
163 return p_argument.stream()
167 if ( Objects.isNull( i ) )
170 final IFormatter<?> l_formatter = m_formatter.parallelStream()
171 .filter( j -> j.isAssignableTo( i.getClass() ) )
176 return Objects.isNull( l_formatter ) ? i.
toString() : l_formatter.
toString( i );
178 .collect( Collectors.joining( m_seperator ) );
194 T
get()
throws Exception;
203 public abstract static class IFormatter<T>
implements Serializable
208 private static final long serialVersionUID = -4997526550642055213L;
218 return this.getType().isAssignableFrom( p_class );
224 return this.getType().hashCode();
228 public final boolean equals(
final Object p_object )
239 @SuppressWarnings(
"unchecked" )
240 public final String
toString( final Object p_data )
242 return this.
format( (T) p_data );
250 protected abstract Class<?> getType();
258 protected abstract String
format(
final T p_data );
base class of build-in actions for setting name by package/classname (without prefix character) ...
final IFuzzyValue< Boolean > execute(final boolean p_parallel, @Nonnull final IContext p_context, @Nonnull final List< ITerm > p_argument, @Nonnull final List< ITerm > p_return)
defines a plan-body operation
void readObject(final ObjectInputStream p_stream)
deserializable call
transient PrintStream m_stream
output stream
static< N > IFuzzyValue< N > from( @Nonnull final N p_value)
factory
final Set< IFormatter<?> > m_formatter
list mit individual format calls
execution context with local data
final Set< IFormatter<?> > formatter()
returns the formatter list
action for sum of elements.
final ISupplier< PrintStream > m_streamsupplier
supplier of print stream field
T get()
supplier exception
result for an immutable fuzzy value
final String m_seperator
argument seperator
< T > T raw()
cast to any raw value type
String format( @Nonnull final Collection< ITerm > p_argument)
format definition
CPrint( @Nonnull final ISupplier< PrintStream > p_streamsupplier)
ctor
static final long serialVersionUID
serial id
CPrint( @Nonnull final ISupplier< PrintStream > p_streamsupplier, @Nonnull final String p_seperator, @Nullable final IFormatter<?>... p_formatter)
ctor