当前位置: 首页>>代码示例>>Java>>正文


Java Immutable类代码示例

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


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

示例1: checkImmutability

import com.jcabi.aspects.Immutable; //导入依赖的package包/类
/**
 * Test for immutability.
 * Checks that all classes in package {@code com.jcabi.github }
 * have {@code @Immutable} annotation.
 *
 * @throws Exception If some problem inside
 */
@Test
public void checkImmutability() throws Exception {
    MatcherAssert.assertThat(
        Iterables.filter(
            this.classpath.allTypes(),
            new Predicate<Class<?>>() {
                @Override
                public boolean apply(final Class<?> input) {
                    return !ImmutabilityTest.skip().contains(
                        input.getName()
                    );
                }
            }
        ),
        Matchers.everyItem(
            new CustomTypeSafeMatcher<Class<?>>("annotated type") {
                @Override
                protected boolean matchesSafely(final Class<?> item) {
                    return item.isAnnotationPresent(Immutable.class);
                }
            }
        )
    );
}
 
开发者ID:cvrebert,项目名称:typed-github,代码行数:32,代码来源:ImmutabilityTest.java

示例2: checkArray

import com.jcabi.aspects.Immutable; //导入依赖的package包/类
/**
 * This array field immutable?
 * @param field The field to check
 * @throws Violation If it is mutable.
 */
private void checkArray(final Field field)
    throws ImmutabilityChecker.Violation {
    if (!field.isAnnotationPresent(Immutable.Array.class)) {
        throw new ImmutabilityChecker.Violation(
            String.format(
                // @checkstyle LineLength (1 line)
                "Field '%s' is an array and is not annotated with @Immutable.Array",
                field.getName()
            )
        );
    }
    final Class<?> type = field.getType().getComponentType();
    try {
        this.check(type);
    } catch (final ImmutabilityChecker.Violation ex) {
        throw new ImmutabilityChecker.Violation(
            String.format(
                "Field array component type '%s' is mutable",
                type.getName()
            ),
            ex
        );
    }
}
 
开发者ID:jcabi,项目名称:jcabi-aspects,代码行数:30,代码来源:ImmutabilityChecker.java

示例3: check

import com.jcabi.aspects.Immutable; //导入依赖的package包/类
/**
 * This class is immutable?
 * @param type The class to check
 * @throws ImmutabilityChecker.Violation If it is mutable
 */
private void check(final Class<?> type)
    throws ImmutabilityChecker.Violation {
    synchronized (this.immutable) {
        if (!this.ignore(type)) {
            if (type.isInterface()
                && !type.isAnnotationPresent(Immutable.class)) {
                throw new ImmutabilityChecker.Violation(
                    String.format(
                        "Interface '%s' is not annotated with @Immutable",
                        type.getName()
                    )
                );
            }
            if (!type.isInterface()
                && !Modifier.isFinal(type.getModifiers())) {
                throw new Violation(
                    String.format(
                        "Class '%s' is not final",
                        type.getName()
                    )
                );
            }
            try {
                this.fields(type);
            } catch (final ImmutabilityChecker.Violation ex) {
                throw new ImmutabilityChecker.Violation(
                    String.format("Class '%s' is mutable", type.getName()),
                    ex
                );
            }
            this.immutable.add(type);
            Logger.debug(this, "#check(%s): immutability checked", type);
        }
    }
}
 
开发者ID:jcabi,项目名称:jcabi-aspects,代码行数:41,代码来源:ImmutabilityChecker.java


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