All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.fasterxml.jackson.databind.util.ViewMatcher Maven / Gradle / Ivy

There is a newer version: 2.22.2
Show newest version
package com.fasterxml.jackson.databind.util;

/**
 * Helper class used for checking whether a property is visible
 * in the active view
 */
public abstract class ViewMatcher
{
    public abstract boolean isVisibleForView(Class activeView);

    public static ViewMatcher construct(Class[] views)
    {
        if (views == null) {
            return Empty.instance;
        }
        switch (views.length) {
        case 0:
            return Empty.instance;
        case 1:
            return new Single(views[0]);
        }
        return new Multi(views);
    } 
    
    /*
    /**********************************************************
    /* Concrete sub-classes
    /**********************************************************
     */

    private final static class Empty extends ViewMatcher
        implements java.io.Serializable
    {
        private static final long serialVersionUID = 1L;

        final static Empty instance = new Empty();
        @Override
        public boolean isVisibleForView(Class activeView) {
            return false;
        }
    }

    private final static class Single extends ViewMatcher
        implements java.io.Serializable
    {
        private static final long serialVersionUID = 1L;

        private final Class _view;
        public Single(Class v) { _view = v; }
        @Override
        public boolean isVisibleForView(Class activeView) {
            return (activeView == _view) || _view.isAssignableFrom(activeView);
        }
    }

    private final static class Multi extends ViewMatcher
        implements java.io.Serializable
    {
        private static final long serialVersionUID = 1L;

        private final Class[] _views;

        public Multi(Class[] v) { _views = v; }

        @Override
        public boolean isVisibleForView(Class activeView)
        {
            for (int i = 0, len = _views.length; i < len; ++i) {
                Class view = _views[i];
                if ((activeView == view) || view.isAssignableFrom(activeView)) {
                    return true;
                }
            }
            return false;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy