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

org.gradle.api.internal.attributes.AttributeValue Maven / Gradle / Ivy

There is a newer version: 8.6
Show newest version
/*
 * Copyright 2017 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.gradle.api.internal.attributes;

import org.gradle.api.attributes.Attribute;

import javax.annotation.Nullable;

/**
 * Represents an optional attribute value, as found in an attribute container. There are 3 possible cases:
 * 
    *
  • present is the default, and represents an attribute with an actual value
  • *
  • missing used whenever an attribute has no value.
  • *
* During attribute matching, this can be used to implement various {@link org.gradle.api.attributes.AttributeMatchingStrategy strategies}. * @param the type of the attribute * * @since 3.3 */ public interface AttributeValue { AttributeValue MISSING = new AttributeValue() { @Override public boolean isPresent() { return false; } @Nullable @Override public S coerce(Attribute type) { throw new UnsupportedOperationException("coerce() should not be called on a missing attribute value"); } @Override public Object get() { throw new UnsupportedOperationException("get() should not be called on a missing attribute value"); } }; /** * Tells if this attribute value is present. * @return true if this attribute value is present, implying not null. */ boolean isPresent(); /** * Returns the value of this attribute. * @return the value of this attribute. Throws an error if called on a missing or unknown attribute value. */ T get(); /** * Coerces this value to the type of the other attribute, so it can be compared * to a value of that other attribute. * * @throws IllegalArgumentException if this attribute is not compatible with the other one */ S coerce(Attribute otherAttribute); }