Apache Ant Source Code Files

Apache Ant Source Code Files are inside the Apache Ant source package file like apache-ant-1.10.10-src.zip. Unzip the source package file and go to the "src/main" sub-directory, you will see source code files.

Here is the list of Java source code files of the Apache Ant 1.10.10 in \Users\fyicenter\apache-ant-1.10.10\src\main:

✍: FYIcenter.com

org/apache/tools/ant/types/Quantifier.java

/*
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  See the NOTICE file distributed with
 *  this work for additional information regarding copyright ownership.
 *  The ASF licenses this file to You 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
 *
 *      https://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.apache.tools.ant.types;

import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.stream.Stream;

import org.apache.tools.ant.BuildException;

/**
 * EnumeratedAttribute for quantifier comparisons. Evaluates a
 * <code>boolean[]</code> or raw <code>true</code> and <code>false</code>
 * counts. Accepts the following values:<dl>
 * <dt>"all"</dt><dd>none <code>false</code></dd>
 * <dt>"each"</dt><dd>none <code>false</code></dd>
 * <dt>"every"</dt><dd>none <code>false</code></dd>
 * <dt>"any"</dt><dd>at least one <code>true</code></dd>
 * <dt>"some"</dt><dd>at least one <code>true</code></dd>
 * <dt>"one"</dt><dd>exactly one <code>true</code></dd>
 * <dt>"majority"</dt><dd>more <code>true</code> than <code>false</code></dd>
 * <dt>"most"</dt><dd>more <code>true</code> than <code>false</code></dd>
 * <dt>"none"</dt><dd>none <code>true</code></dd>
 * </dl>
 * @since Ant 1.7
 */
public class Quantifier extends EnumeratedAttribute {
    private static final String[] VALUES =
            Stream.of(Predicate.values()).map(Predicate::getNames)
                .flatMap(Collection::stream).toArray(String[]::new);

    /** ALL instance */
    public static final Quantifier ALL = new Quantifier(Predicate.ALL);

    /** ANY instance */
    public static final Quantifier ANY = new Quantifier(Predicate.ANY);

    /** ONE instance */
    public static final Quantifier ONE = new Quantifier(Predicate.ONE);

    /** MAJORITY instance */
    public static final Quantifier MAJORITY =
        new Quantifier(Predicate.MAJORITY);

    /** NONE instance */
    public static final Quantifier NONE = new Quantifier(Predicate.NONE);

    private enum Predicate {
        ALL("all", "each", "every") {
            @Override
            boolean eval(int t, int f) {
                return f == 0;
            }
        },

        ANY("any", "some") {
            @Override
            boolean eval(int t, int f) {
                return t > 0;
            }
        },

        ONE("one") {
            @Override
            boolean eval(int t, int f) {
                return t == 1;
            }
        },

        MAJORITY("majority", "most") {
            @Override
            boolean eval(int t, int f) {
                return t > f;
            }
        },

        NONE("none") {
            @Override
            boolean eval(int t, int f) {
                return t == 0;
            }
        };

        static Predicate get(String name) {
            return Stream.of(values()).filter(p -> p.names.contains(name))
                .findFirst()
                .orElseThrow(() -> new IllegalArgumentException(name));
        }

        final Set<String> names;

        Predicate(String primaryName, String... additionalNames) {
            Set<String> names = new LinkedHashSet<>();
            names.add(primaryName);
            Collections.addAll(names, additionalNames);
            this.names = Collections.unmodifiableSet(names);
        }

        Set<String> getNames() {
            return names;
        }

        abstract boolean eval(int t, int f);
    }

    /**
     * Default constructor.
     */
    public Quantifier() {
    }

    /**
     * Construct a new Quantifier with the specified value.
     * @param value the EnumeratedAttribute value.
     */
    public Quantifier(String value) {
        setValue(value);
    }

    private Quantifier(Predicate impl) {
        setValue(impl.getNames().iterator().next());
    }

    /**
     * Return the possible values.
     * @return String[] of EnumeratedAttribute values.
     */
    @Override
    public String[] getValues() {
        return VALUES;
    }

    /**
     * Evaluate a <code>boolean</code> array.
     * @param b the <code>boolean[]</code> to evaluate.
     * @return true if the argument fell within the parameters of this Quantifier.
     */
    public boolean evaluate(boolean[] b) {
        int t = 0;
        for (boolean bn : b) {
            if (bn) {
                t++;
            }
        }
        return evaluate(t, b.length - t);
    }

    /**
     * Evaluate integer <code>true</code> vs. <code>false</code> counts.
     * @param t the number of <code>true</code> values.
     * @param f the number of <code>false</code> values.
     * @return true if the arguments fell within the parameters of this Quantifier.
     */
    public boolean evaluate(int t, int f) {
        int index = getIndex();
        if (index == -1) {
            throw new BuildException("Quantifier value not set.");
        }
        return Predicate.get(VALUES[index]).eval(t, f);
    }

}

org/apache/tools/ant/types/Quantifier.java

 

Or download all of them as a single archive file:

File name: apache-ant-1.10.10-fyi.zip
File size: 2392938 bytes
Release date: 2021-04-17
Download 

 

ant-1.8.0.jar - Apache Ant

Download Apache Ant Source Package

Apache Ant - Java Build Tool

⇑⇑ Java/JAR Tools

2021-07-10, 111016👍, 0💬