• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Closure类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.commons.collections4.Closure的典型用法代码示例。如果您正苦于以下问题:Java Closure类的具体用法?Java Closure怎么用?Java Closure使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Closure类属于org.apache.commons.collections4包,在下文中一共展示了Closure类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: chainedClosure

import org.apache.commons.collections4.Closure; //导入依赖的package包/类
/**
 * Create a new Closure that calls each closure in turn, passing the
 * result into the next closure. The ordering is that of the iterator()
 * method on the collection.
 *
 * @param <E> the type that the closure acts on
 * @param closures  a collection of closures to chain
 * @return the <code>chained</code> closure
 * @throws NullPointerException if the closures collection is null
 * @throws NullPointerException if any closure in the collection is null
 */
@SuppressWarnings("unchecked")
public static <E> Closure<E> chainedClosure(final Collection<? extends Closure<? super E>> closures) {
    if (closures == null) {
        throw new NullPointerException("Closure collection must not be null");
    }
    if (closures.size() == 0) {
        return NOPClosure.<E>nopClosure();
    }
    // convert to array like this to guarantee iterator() ordering
    final Closure<? super E>[] cmds = new Closure[closures.size()];
    int i = 0;
    for (final Closure<? super E> closure : closures) {
        cmds[i++] = closure;
    }
    FunctorUtils.validate(cmds);
    return new ChainedClosure<E>(false, cmds);
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:29,代码来源:ChainedClosure.java


示例2: switchClosure

import org.apache.commons.collections4.Closure; //导入依赖的package包/类
/**
 * Create a new Closure that calls one of the closures depending
 * on the predicates.
 * <p>
 * The Map consists of Predicate keys and Closure values. A closure
 * is called if its matching predicate returns true. Each predicate is evaluated
 * until one returns true. If no predicates evaluate to true, the default
 * closure is called. The default closure is set in the map with a
 * null key. The ordering is that of the iterator() method on the entryset
 * collection of the map.
 *
 * @param <E> the type that the closure acts on
 * @param predicatesAndClosures  a map of predicates to closures
 * @return the <code>switch</code> closure
 * @throws NullPointerException if the map is null
 * @throws NullPointerException if any closure in the map is null
 * @throws ClassCastException  if the map elements are of the wrong type
 */
@SuppressWarnings("unchecked")
public static <E> Closure<E> switchClosure(final Map<Predicate<E>, Closure<E>> predicatesAndClosures) {
    if (predicatesAndClosures == null) {
        throw new NullPointerException("The predicate and closure map must not be null");
    }
    // convert to array like this to guarantee iterator() ordering
    final Closure<? super E> defaultClosure = predicatesAndClosures.remove(null);
    final int size = predicatesAndClosures.size();
    if (size == 0) {
        return (Closure<E>) (defaultClosure == null ? NOPClosure.<E>nopClosure() : defaultClosure);
    }
    final Closure<E>[] closures = new Closure[size];
    final Predicate<E>[] preds = new Predicate[size];
    int i = 0;
    for (final Map.Entry<Predicate<E>, Closure<E>> entry : predicatesAndClosures.entrySet()) {
        preds[i] = entry.getKey();
        closures[i] = entry.getValue();
        i++;
    }
    return new SwitchClosure<E>(false, preds, closures, defaultClosure);
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:40,代码来源:SwitchClosure.java


示例3: processTag

import org.apache.commons.collections4.Closure; //导入依赖的package包/类
/**
 * A tag processor template method which takes as input a closure that is
 * responsible for extracting the information from the tag and saving it to
 * the database. The contents of the closure is called inside the
 * START_DOCUMENT case of the template code.
 * 
 * @param parser
 *            a reference to our StAX XMLStreamReader.
 * @param tagProcessor
 *            a reference to the Closure to process the tag.
 * @throws Exception
 *             if one is thrown.
 */
private void processTag(XMLStreamReader parser,
        Closure<XMLStreamReader> tagProcessor) throws Exception {
    int depth = 0;
    int event = parser.getEventType();
    String startTag = formatTag(parser.getName());
    FOR_LOOP: for (;;) {
        switch (event) {
        case XMLStreamConstants.START_ELEMENT:
            String tagName = formatTag(parser.getName());
            tagProcessor.execute(parser);
            depth++;
            break;
        case XMLStreamConstants.END_ELEMENT:
            tagName = formatTag(parser.getName());
            depth--;
            if (tagName.equals(startTag) && depth == 0) {
                break FOR_LOOP;
            }
            break;
        default:
            break;
        }
        event = parser.next();
    }
}
 
开发者ID:sherlok,项目名称:ruta-ontologies,代码行数:39,代码来源:OwlParser.java


示例4: ifClosure

import org.apache.commons.collections4.Closure; //导入依赖的package包/类
/**
 * Factory method that performs validation.
 *
 * @param <E> the type that the closure acts on
 * @param predicate  predicate to switch on
 * @param trueClosure  closure used if true
 * @param falseClosure  closure used if false
 * @return the <code>if</code> closure
 * @throws NullPointerException if any argument is null
 */
public static <E> Closure<E> ifClosure(final Predicate<? super E> predicate,
                                       final Closure<? super E> trueClosure,
                                       final Closure<? super E> falseClosure) {
    if (predicate == null) {
        throw new NullPointerException("Predicate must not be null");
    }
    if (trueClosure == null || falseClosure == null) {
        throw new NullPointerException("Closures must not be null");
    }
    return new IfClosure<E>(predicate, trueClosure, falseClosure);
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:22,代码来源:IfClosure.java


示例5: copy

import org.apache.commons.collections4.Closure; //导入依赖的package包/类
/**
 * Clone the closures to ensure that the internal reference can't be messed with.
 *
 * @param closures  the closures to copy
 * @return the cloned closures
 */
@SuppressWarnings("unchecked")
static <E> Closure<E>[] copy(final Closure<? super E>... closures) {
    if (closures == null) {
        return null;
    }
    return (Closure<E>[]) closures.clone();
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:14,代码来源:FunctorUtils.java


示例6: validate

import org.apache.commons.collections4.Closure; //导入依赖的package包/类
/**
 * Validate the closures to ensure that all is well.
 *
 * @param closures  the closures to validate
 */
static void validate(final Closure<?>... closures) {
    if (closures == null) {
        throw new NullPointerException("The closure array must not be null");
    }
    for (int i = 0; i < closures.length; i++) {
        if (closures[i] == null) {
            throw new NullPointerException(
                    "The closure array must not contain a null closure, index " + i + " was null");
        }
    }
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:17,代码来源:FunctorUtils.java


示例7: whileClosure

import org.apache.commons.collections4.Closure; //导入依赖的package包/类
/**
 * Factory method that performs validation.
 *
 * @param <E> the type that the closure acts on
 * @param predicate  the predicate used to evaluate when the loop terminates, not null
 * @param closure  the closure the execute, not null
 * @param doLoop  true to act as a do-while loop, always executing the closure once
 * @return the <code>while</code> closure
 * @throws NullPointerException if the predicate or closure is null
 */
public static <E> Closure<E> whileClosure(final Predicate<? super E> predicate,
                                          final Closure<? super E> closure, final boolean doLoop) {
    if (predicate == null) {
        throw new NullPointerException("Predicate must not be null");
    }
    if (closure == null) {
        throw new NullPointerException("Closure must not be null");
    }
    return new WhileClosure<E>(predicate, closure, doLoop);
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:21,代码来源:WhileClosure.java


示例8: SwitchClosure

import org.apache.commons.collections4.Closure; //导入依赖的package包/类
/**
 * Hidden constructor for the use by the static factory methods.
 *
 * @param clone  if {@code true} the input arguments will be cloned
 * @param predicates  array of predicates, no nulls
 * @param closures  matching array of closures, no nulls
 * @param defaultClosure  the closure to use if no match, null means nop
 */
@SuppressWarnings("unchecked")
private SwitchClosure(final boolean clone, final Predicate<? super E>[] predicates,
                      final Closure<? super E>[] closures, final Closure<? super E> defaultClosure) {
    super();
    iPredicates = clone ? FunctorUtils.copy(predicates) : predicates;
    iClosures = clone ? FunctorUtils.copy(closures) : closures;
    iDefault = (Closure<? super E>) (defaultClosure == null ? NOPClosure.<E>nopClosure() : defaultClosure);
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:17,代码来源:SwitchClosure.java


示例9: test

import org.apache.commons.collections4.Closure; //导入依赖的package包/类
public void test() {
    List<A> aList = new ArrayList<A>();
    A a = new A(1);
    aList.add(a);
    aList.add(new A(2));
    CollectionUtils.forAllDo(aList, new Closure<A>() {
        @Override
        public void execute(A input) {
            input.setId(5);
        }
    });

    System.out.println(aList);
}
 
开发者ID:Qunzer,项目名称:learningJava,代码行数:15,代码来源:CollectionUtilExample.java


示例10: generateIOExceptionClosure

import org.apache.commons.collections4.Closure; //导入依赖的package包/类
private static <T>Closure<T> generateIOExceptionClosure() {
    return new CatchAndRethrowClosure<T>() {
        @Override
        protected void executeAndThrow(final T input) throws IOException {
            throw new IOException();
        }
    };
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:9,代码来源:CatchAndRethrowClosureTest.java


示例11: generateNullPointerExceptionClosure

import org.apache.commons.collections4.Closure; //导入依赖的package包/类
private static <T>Closure<T> generateNullPointerExceptionClosure() {
    return new CatchAndRethrowClosure<T>() {
        @Override
        protected void executeAndThrow(final T input) {
            throw new NullPointerException();
        }
    };
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:9,代码来源:CatchAndRethrowClosureTest.java


示例12: generateNoExceptionClosure

import org.apache.commons.collections4.Closure; //导入依赖的package包/类
private static <T>Closure<T> generateNoExceptionClosure() {
    return new CatchAndRethrowClosure<T>() {
        @Override
        protected void executeAndThrow(final T input) {
        }
    };
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:8,代码来源:CatchAndRethrowClosureTest.java


示例13: closureSanityTests

import org.apache.commons.collections4.Closure; //导入依赖的package包/类
@Test
public void closureSanityTests() throws Exception {
    fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "closureSanityTests");
    final Closure<?> closure = generateClosure();
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),4410,closure);
    fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:8,代码来源:AbstractClosureTest.java


示例14: inspectTypes

import org.apache.commons.collections4.Closure; //导入依赖的package包/类
private static Map<Integer, String> inspectTypes() {
	Collection<Field> fields = CollectionUtils.select(Arrays.asList( java.sql.Types.class.getFields() ), (Predicate<? super Field>) new Predicate<Field>() {
		@Override
		public boolean evaluate(Field f) {
			
					return Modifier.isStatic(f.getModifiers())
							&& f.getType().getName().equals("int");
		}
	});
			
	final HashMap<Integer, String> intToName = new HashMap<Integer, String>( 0 );
	
	CollectionUtils.forAllDo(fields, (Closure<? super Field>) new Closure<Field>() {

		@Override
		public void execute(Field arg0) {
			try {
				String name = arg0.getName();
				Integer val;
				val = (Integer)( arg0.get(java.sql.Types.class) );
				intToName.put(val, name );
			} catch (IllegalArgumentException | IllegalAccessException e) {
				// ok, we cannot access it
			}
		}
	});
	return intToName;
}
 
开发者ID:danidemi,项目名称:jlubricant,代码行数:29,代码来源:TypesUtils.java


示例15: execute

import org.apache.commons.collections4.Closure; //导入依赖的package包/类
/**
 * Execute a list of closures.
 *
 * @param input  the input object passed to each closure
 */
public void execute(final E input) {
    for (final Closure<? super E> iClosure : iClosures) {
        iClosure.execute(input);
    }
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:11,代码来源:ChainedClosure.java


示例16: generateClosure

import org.apache.commons.collections4.Closure; //导入依赖的package包/类
@Override
protected <T>Closure<T> generateClosure() {
    return CatchAndRethrowClosureTest.generateNoExceptionClosure();
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:5,代码来源:CatchAndRethrowClosureTest.java


示例17: forClosure

import org.apache.commons.collections4.Closure; //导入依赖的package包/类
/**
 * Factory method that performs validation.
 * <p>
 * A null closure or zero count returns the <code>NOPClosure</code>.
 * A count of one returns the specified closure.
 *
 * @param <E> the type that the closure acts on
 * @param count  the number of times to execute the closure
 * @param closure  the closure to execute, not null
 * @return the <code>for</code> closure
 */
@SuppressWarnings("unchecked")
public static <E> Closure<E> forClosure(final int count, final Closure<? super E> closure) {
    if (count <= 0 || closure == null) {
        return NOPClosure.<E>nopClosure();
    }
    if (count == 1) {
        return (Closure<E>) closure;
    }
    return new ForClosure<E>(count, closure);
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:22,代码来源:ForClosure.java


示例18: IfClosure

import org.apache.commons.collections4.Closure; //导入依赖的package包/类
/**
 * Constructor that performs no validation.
 * Use <code>ifClosure</code> if you want that.
 *
 * @param predicate  predicate to switch on, not null
 * @param trueClosure  closure used if true, not null
 * @param falseClosure  closure used if false, not null
 */
public IfClosure(final Predicate<? super E> predicate, final Closure<? super E> trueClosure,
                 final Closure<? super E> falseClosure) {
    super();
    iPredicate = predicate;
    iTrueClosure = trueClosure;
    iFalseClosure = falseClosure;
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:16,代码来源:IfClosure.java


示例19: transformerClosure

import org.apache.commons.collections4.Closure; //导入依赖的package包/类
/**
 * Factory method that performs validation.
 * <p>
 * A null transformer will return the <code>NOPClosure</code>.
 *
 * @param <E> the type that the closure acts on
 * @param transformer  the transformer to call, null means nop
 * @return the <code>transformer</code> closure
 */
public static <E> Closure<E> transformerClosure(final Transformer<? super E, ?> transformer) {
    if (transformer == null) {
        return NOPClosure.<E>nopClosure();
    }
    return new TransformerClosure<E>(transformer);
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:16,代码来源:TransformerClosure.java


示例20: WhileClosure

import org.apache.commons.collections4.Closure; //导入依赖的package包/类
/**
 * Constructor that performs no validation.
 * Use <code>whileClosure</code> if you want that.
 *
 * @param predicate  the predicate used to evaluate when the loop terminates, not null
 * @param closure  the closure the execute, not null
 * @param doLoop  true to act as a do-while loop, always executing the closure once
 */
public WhileClosure(final Predicate<? super E> predicate, final Closure<? super E> closure, final boolean doLoop) {
    super();
    iPredicate = predicate;
    iClosure = closure;
    iDoLoop = doLoop;
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:15,代码来源:WhileClosure.java



注:本文中的org.apache.commons.collections4.Closure类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Particle类代码示例发布时间:2022-05-23
下一篇:
Java Blob类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap