本文整理汇总了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);
}
}
)
);
}
示例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
);
}
}
示例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);
}
}
}