private TupleImpl(Object tuple,OptionalInt arity){ this.instance = tuple; if(tuple instanceof Collection) cachedValues = new ArrayList( ((List)tuple)); else if(tuple instanceof Map){ cachedValues = new ArrayList( ((Map)tuple).entrySet()); } else if(tuple instanceof Stream){ cachedValues = (List)((Stream)tuple).collect(Collectors.toList()); } else if(tuple instanceof Iterable){ cachedValues= loadFromIterable((Iterable)tuple); } else if(tuple instanceof Iterator){ cachedValues= loadFromIterator((Iterator)tuple); } else if(tuple!=null && tuple.getClass().isArray()){ cachedValues= Arrays.asList((Object[]) tuple); } else cachedValues = ((TupleWrapper) ()-> tuple).values(); this.arity = arity.orElse(cachedValues.size()); }
@SuppressWarnings("unchecked") default List<Object> values(){ try { return (List)ReflectionCache.getFields(getInstance().getClass()).stream().map(f ->{ try { return f.get(getInstance()); } catch (Exception e) { ExceptionSoftener.throwSoftenedException(e); return null; } }).collect(Collectors.toList()); } catch (Exception e) { ExceptionSoftener .throwSoftenedException(e); return null; } } }
private TupleImpl(Object tuple,OptionalInt arity){ this.instance = tuple; if(tuple instanceof Collection) cachedValues = new ArrayList( ((List)tuple)); else if(tuple instanceof Map){ cachedValues = new ArrayList( ((Map)tuple).entrySet()); } else if(tuple instanceof Stream){ cachedValues = (List)((Stream)tuple).collect(Collectors.toList()); } else if(tuple instanceof Iterable){ cachedValues= loadFromIterable((Iterable)tuple); } else if(tuple instanceof Iterator){ cachedValues= loadFromIterator((Iterator)tuple); } else if(tuple!=null && tuple.getClass().isArray()){ cachedValues= Arrays.asList((Object[]) tuple); } else cachedValues = ((TupleWrapper) ()-> tuple).values(); this.arity = arity.orElse(cachedValues.size()); }
@SuppressWarnings("unchecked") default List<Object> values(){ try { return (List)ReflectionCache.getFields(getInstance().getClass()).stream().map(f ->{ try { return f.get(getInstance()); } catch (Exception e) { ExceptionSoftener.singleton.factory.getInstance().throwSoftenedException(e); return null; } }).collect(Collectors.toList()); } catch (Exception e) { ExceptionSoftener.singleton.factory.getInstance() .throwSoftenedException(e); return null; } } }
public static <K,V> Monoid<PMap<K,V>> toPMap() { return Monoid.<PMap<K,V>>of(HashTreePMap.empty(), (PMap<K,V> a) -> b -> a.plusAll(b), (in)-> { List w = ((TupleWrapper) ()-> in).values(); return HashTreePMap.singleton((K)w.get(0), (V)w.get(1)); }); }