Package net.jcores.utils

Examples of net.jcores.utils.Mapper


     * @param options
     *
     * @return The mapped elements in a stable order  
     */
    public CoreInt map(final F1Int2Int f, Option... options) {
        final Mapper mapper = new Mapper(int.class, this.t.length) {
            @Override
            public void handle(int i) {
                int[] a = (int[]) this.array.get();
                a[i] = f.f(CoreInt.this.t[i]);
            }
        };

        map(mapper, options);

        return new CoreInt(this.commonCore, (int[]) mapper.getTargetArray());
    }
View Full Code Here


     *
     * @return The mapped elements in a stable order  
     */
    @SuppressWarnings("unchecked")
    public <R> CoreObject<R> map(final F1Int2Object<R> f, Option... options) {
        final Mapper mapper = new Mapper(this.t.length) {
            @Override
            public void handle(int i) {
                R[] a = (R[]) this.array.get();

                final R out = f.f(CoreInt.this.t[i]);
                if (out == null) return;

                if (a == null) {
                    a = (R[]) updateArray(Array.newInstance(out.getClass(), this.size));
                }

                a[i] = out;
            }
        };

        map(mapper, options);

        return new CoreObject<R>(this.commonCore, (R[]) mapper.getTargetArray());
    }
View Full Code Here

                mapType = ((OptionMapType) option).getType();
            }
        }

        // Create mapper
        final Mapper mapper = new Mapper(mapType, size() - 1) {
            @Override
            public void handle(int i) {
                // Get our target-array (if it is already there)
                R[] a = (R[]) this.array.get();

                // Get the in-value from the source-array
                final T ii = CoreObject.this.t[i];
                final T jj = CoreObject.this.t[i + 1];

                // Convert
                if (ii == null || jj == null) return;

                final R out = delta.f(ii, jj);

                if (out == null) return;

                // If we haven't had an in-array, create it now, according to the return type
                if (a == null) {
                    a = (R[]) updateArray(Array.newInstance(out.getClass(), this.size));
                }

                // Eventually set the out value
                a[i] = out;
            }
        };

        // Map ...
        map(mapper, options);

        // In case we don't have a return array (which happens when the mapper never returned something
        // sensible), we create a simple object array of our size, so that the core's size stays
        // consistent.
        R rval[] = (R[]) mapper.getTargetArray();
        if (rval == null) {
            rval = (R[]) Array.newInstance(Object.class, Math.max(0, size() - 1));
        }

        // ... and return result.
View Full Code Here

                mapType = ((OptionMapType) option).getType();
            }
        }

        // Create mapper
        final Mapper mapper = new Mapper(mapType, size()) {
            @Override
            public void handle(int i) {
                // Get our target-array (if it is already there)
                R[] a = (R[]) this.array.get();

                // Get the in-value from the source-array
                final T in = CoreObject.this.t[i];

                // Convert
                if (in == null) return;
                final R out = f.f(in);
                if (out == null) return;

                // If we haven't had an in-array, create it now, according to the return type
                if (a == null) {
                    a = (R[]) updateArray(Array.newInstance(out.getClass(), this.size));
                }

                // Eventually set the out value
                a[i] = out;
            }
        };

        // Map ...
        map(mapper, options);

        // In case we don't have a return array (which happens when the mapper never returned something
        // sensible), we create a simple object array of our size, so that the core's size stays
        // consistent.
        R rval[] = (R[]) mapper.getTargetArray();
        if (rval == null) {
            rval = (R[]) Array.newInstance(Object.class, size());
        }

        // ... and return result.
View Full Code Here

     * @deprecated
     * @return The mapped elements in a stable order  
     */
    @Deprecated
    public CoreInt map(final F1Object2Int<T> f, Option... options) {
        final Mapper mapper = new Mapper(int.class, size()) {
            @Override
            public void handle(int i) {
                int[] a = (int[]) this.array.get();
                a[i] = f.f(CoreObject.this.t[i]);
            }
        };

        map(mapper, options);

        return new CoreInt(this.commonCore, (int[]) mapper.getTargetArray());
    }
View Full Code Here

TOP

Related Classes of net.jcores.utils.Mapper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.