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

com.servicerocket.confluence.randombits.metadata.impl.handler.DirectTypeHandler Maven / Gradle / Ivy

There is a newer version: 2.5.12
Show newest version
package com.servicerocket.confluence.randombits.metadata.impl.handler;

import com.servicerocket.confluence.randombits.metadata.TypeHandler;

import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

/**
 * Handles a type which is stored directly without modification.
 */
public class DirectTypeHandler implements TypeHandler {

    private final Set> types;

    public DirectTypeHandler( Class... types ) {
        this( Arrays.asList( types ) );
    }

    public DirectTypeHandler( Collection> types ) {
        this.types = new HashSet>( types );
    }

    public boolean supportsOriginal( Object original ) {
        return supportsType( original );
    }

    public boolean supportsStorable( Object stored ) {
        return supportsType( stored );
    }

    private boolean supportsType( Object value ) {
        for ( Class type : types ) {
            if ( type.isInstance( value ) )
                return true;
        }
        return false;
    }

    public Object getOriginal( Object stored ) {
        // Assumes 'supportsStored' has been called.
        return stored;
    }

    public Object getStorable( Object value ) {
        // Assumes 'supportsOriginal' has been called.
        return value;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy