RequiredPropKey.java 1.36 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.scene7.is.util.callbacks.Option
 *  javax.jcr.Property
 *  javax.jcr.RepositoryException
 */
package com.adobe.cq.dam.s7imaging.impl.jcr.props;

import com.adobe.cq.dam.s7imaging.impl.jcr.props.PropKey;
import com.scene7.is.util.callbacks.Option;
import java.util.Iterator;
import javax.jcr.Property;
import javax.jcr.RepositoryException;

class RequiredPropKey<T>
extends PropKey<T> {
    private final PropKey<Option<T>> delegate;
    private Option<T> defaultValue;

    static <T> PropKey<T> requiredPropKey(PropKey<Option<T>> delegate, Option<T> defaultValue) {
        return new RequiredPropKey<T>(delegate, defaultValue);
    }

    @Override
    T extractValue(Option<Property> value) throws RepositoryException {
        Iterator i$ = this.delegate.extractValue(value).iterator();
        if (i$.hasNext()) {
            Object v = i$.next();
            return (T)v;
        }
        i$ = this.defaultValue.iterator();
        if (i$.hasNext()) {
            Object v = i$.next();
            return (T)v;
        }
        throw new RepositoryException("Required property " + this.name);
    }

    private RequiredPropKey(PropKey<Option<T>> delegate, Option<T> defaultValue) {
        super(delegate.name);
        this.delegate = delegate;
        this.defaultValue = defaultValue;
    }
}