Java Code Examples for org.apache.commons.lang3.Validate#validState()

The following examples show how to use org.apache.commons.lang3.Validate#validState() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SearchUtils.java    From coroutines with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Find a method within a class.
 * @param methodNodes method nodes to search through
 * @param name method name to search for
 * @param isStatic {@code true} if the method should be static
 * @param returnType return type to search for
 * @param paramTypes parameter types to search for (in the order specified)
 * @return method found (or {@code null} if no method could be found)
 * @throws NullPointerException if any argument is {@code null} or contains {@code null}
 * @throws IllegalArgumentException if any element of  {@code paramTypes} is either of sort {@link Type#METHOD} or {@link Type#VOID}, or
 * if {@code returnType} is {@link Type#METHOD}
 */
public static MethodNode findMethod(Collection<MethodNode> methodNodes, boolean isStatic, Type returnType, String name,
        Type ... paramTypes) {
    Validate.notNull(methodNodes);
    Validate.notNull(returnType);
    Validate.notNull(name);
    Validate.notNull(paramTypes);
    Validate.noNullElements(methodNodes);
    Validate.noNullElements(paramTypes);
    Validate.isTrue(returnType.getSort() != Type.METHOD);
    for (Type paramType : paramTypes) {
        Validate.isTrue(paramType.getSort() != Type.METHOD && paramType.getSort() != Type.VOID);
    }
    
    Collection<MethodNode> ret = methodNodes;
    
    ret = findMethodsWithName(ret, name);
    ret = findMethodsWithParameters(ret, paramTypes);
    if (isStatic) {
        ret = findStaticMethods(ret);
    }
    
    Validate.validState(ret.size() <= 1); // sanity check -- should never get triggered

    return ret.isEmpty() ? null : ret.iterator().next();
}
 
Example 2
Source File: AT_Row.java    From asciitable with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new row representing a rule.
 * @param type the type for the rule row, must not be null nor {@link TableRowType#CONTENT} nor {@link TableRowType#UNKNOWN}
 * @param style the style for the rule row, must not be null nor {@link TableRowStyle#UNKNOWN}
 * @return a new row representing a rule
 * @throws {@link NullPointerException} if type or style where null
 * @throws {@link IllegalStateException} if type or style where unknown or if type was {@link TableRowType#CONTENT}
 */
public static AT_Row createRule(TableRowType type, TableRowStyle style){
	Validate.notNull(type);
	Validate.validState(type!=TableRowType.UNKNOWN);
	Validate.validState(type!=TableRowType.CONTENT);
	Validate.notNull(style);
	Validate.validState(style!=TableRowStyle.UNKNOWN);

	return new AT_Row(){
		@Override
		public TableRowType getType(){
			return type;
		}

		@Override
		public TableRowStyle getStyle(){
			return style;
		}
	};
}
 
Example 3
Source File: Base64Renderer.java    From The-5zig-Mod with GNU General Public License v3.0 5 votes vote down vote up
private void prepareImage() {
	if (base64String == null) {
		delete(resourceLocation);
		this.dynamicImage = null;
		return;
	}
	ByteBuf localByteBuf1 = Unpooled.copiedBuffer(base64String, Charsets.UTF_8);
	ByteBuf localByteBuf2 = null;
	BufferedImage localBufferedImage;
	try {
		localByteBuf2 = Base64.decode(localByteBuf1);
		localBufferedImage = read(new ByteBufInputStream(localByteBuf2));
		Validate.validState(localBufferedImage.getWidth() == width, "Must be " + width + " pixels wide");
		Validate.validState(localBufferedImage.getHeight() == height, "Must be " + height + " pixels high");
	} catch (Exception e) {
		The5zigMod.logger.error("Could not prepare base64 renderer image", e);
		delete(resourceLocation);
		dynamicImage = null;
		return;
	} finally {
		localByteBuf1.release();
		if (localByteBuf2 != null) {
			localByteBuf2.release();
		}
	}
	if (this.dynamicImage == null) {
		this.dynamicImage = The5zigMod.getVars().loadDynamicImage(resourceLocation.callGetResourcePath(), localBufferedImage);
	}
}
 
Example 4
Source File: MongoDbSteps.java    From vividus with Apache License 2.0 5 votes vote down vote up
private void executeInDatabase(String connectionKey, String dbKey, Consumer<MongoDatabase> databaseConsumer)
{
    String connection = connections.get(connectionKey);
    Validate.validState(connection != null, "Connection with key '%s' does not exist", connectionKey);
    try (MongoClient client = MongoClients.create(connection))
    {
        MongoDatabase database = client.getDatabase(dbKey);
        databaseConsumer.accept(database);
    }
}
 
Example 5
Source File: Base64Renderer.java    From The-5zig-Mod with MIT License 5 votes vote down vote up
private void prepareImage() {
	if (base64String == null) {
		delete(resourceLocation);
		this.dynamicImage = null;
		return;
	}
	ByteBuf localByteBuf1 = Unpooled.copiedBuffer(base64String, Charsets.UTF_8);
	ByteBuf localByteBuf2 = null;
	BufferedImage localBufferedImage;
	try {
		localByteBuf2 = Base64.decode(localByteBuf1);
		localBufferedImage = read(new ByteBufInputStream(localByteBuf2));
		Validate.validState(localBufferedImage.getWidth() == width, "Must be " + width + " pixels wide");
		Validate.validState(localBufferedImage.getHeight() == height, "Must be " + height + " pixels high");
	} catch (Exception e) {
		The5zigMod.logger.error("Could not prepare base64 renderer image", e);
		delete(resourceLocation);
		dynamicImage = null;
		return;
	} finally {
		localByteBuf1.release();
		if (localByteBuf2 != null) {
			localByteBuf2.release();
		}
	}
	if (this.dynamicImage == null) {
		this.dynamicImage = The5zigMod.getVars().loadDynamicImage(resourceLocation.getResourcePath(), localBufferedImage);
	}
}
 
Example 6
Source File: PerformInstrumentationPass.java    From coroutines with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void pass(ClassNode classNode, InstrumentationState state) {
    Validate.notNull(classNode);
    Validate.notNull(state);


    // Methods attributes should be assigned at this point.
    Validate.validState(!state.methodAttributes().isEmpty());
    Validate.validState(state.methodAttributes().keySet().stream().allMatch(x -> x != null));
    Validate.validState(state.methodAttributes().values().stream().allMatch(x -> x != null));

    // Sanity check to make sure that we're only dealing with methodnodes in the classnode -- this should never trigger unless previous
    // passes mess up
    Validate.validState(classNode.methods.containsAll(state.methodAttributes().keySet()));


    // Instrument the methods based on the analysis we did in previous passes
    MethodInstrumenter instrumenter = new MethodInstrumenter();
    for (Entry<MethodNode, MethodAttributes> method : state.methodAttributes().entrySet()) {            
        MethodNode methodNode = method.getKey();
        MethodAttributes methodAttrs = method.getValue();

        // Instrument
        instrumenter.instrument(classNode, methodNode, methodAttrs);
    }


    // Add the "Instrumented" marker field to this class so if we ever come back to it, we can skip it
    FieldNode instrumentedMarkerField = new FieldNode(
            INSTRUMENTED_MARKER_FIELD_ACCESS,
            INSTRUMENTED_MARKER_FIELD_NAME,
            INSTRUMENTED_MARKER_FIELD_TYPE.getDescriptor(),
            null,
            INSTRUMENTED_MARKER_FIELD_VALUE);
    classNode.fields.add(instrumentedMarkerField);
}
 
Example 7
Source File: MultiLineIgnore.java    From The-5zig-Mod with GNU General Public License v3.0 4 votes vote down vote up
public void add(String message) {
	Validate.validState(startedListening, "Hadn't started listening yet!");
	messages.add(message);
}
 
Example 8
Source File: SpringContextHolder.java    From bird-java with MIT License 4 votes vote down vote up
/**
 * 取得存储在静态变量中的ApplicationContext.
 */
public static ApplicationContext getApplicationContext() {
    Validate.validState(applicationContext != null, "applicationContext属性未注入, 请在applicationContext.xml中定义SpringContextHolder.");

    return applicationContext;
}
 
Example 9
Source File: SpringContextHolder.java    From belling-admin with Apache License 2.0 4 votes vote down vote up
/**
 * 检查ApplicationContext不为空.
 */
private static void assertContextInjected() {
	Validate.validState(applicationContext != null, "applicaitonContext属性未注入, 请在applicationContext.xml中定义SpringContextHolder.");
}
 
Example 10
Source File: CacheVariables.java    From coroutines with GNU Lesser General Public License v3.0 4 votes vote down vote up
public Variable getThrowableCacheVar() {
    Validate.validState(throwableCacheVar != null, "Throwable cache variable of type not assigned");
    return throwableCacheVar;
}
 
Example 11
Source File: SpringContextHolder.java    From mysiteforme with Apache License 2.0 4 votes vote down vote up
/**
 * 检查ApplicationContext不为空.
 */
private static void assertContextInjected() {
	Validate.validState(applicationContext != null, "applicaitonContext属性未注入, 请在applicationContext.xml中定义SpringContextHolder.");
}
 
Example 12
Source File: SpringContextHolder.java    From lightconf with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 检查ApplicationContext不为空.
 */
private static void assertContextInjected() {
    Validate.validState(applicationContext != null, "applicaitonContext属性未注入, 请在applicationContext.xml中定义SpringContextHolder.");
}
 
Example 13
Source File: SpringContextHolder.java    From scaffold-cloud with MIT License 4 votes vote down vote up
/**
 * 检查ApplicationContext不为空.
 */
private static void assertContextInjected() {
	Validate.validState(applicationContext != null, "applicaitonContext属性未注入, 请在applicationContext.xml中定义SpringContextHolder.");
}
 
Example 14
Source File: MultiLineIgnore.java    From The-5zig-Mod with MIT License 4 votes vote down vote up
public void add(String message) {
	Validate.validState(startedListening, "Hadn't started listening yet!");
	messages.add(message);
}
 
Example 15
Source File: SpringContextHolder.java    From erp-framework with MIT License 4 votes vote down vote up
/**
 * 检查ApplicationContext不为空.
 */
private static void assertContextInjected() {
    Validate.validState(applicationContext != null, "applicaitonContext属性未注入, 请在applicationContext.xml中定义SpringContextHolder.");
}
 
Example 16
Source File: AutoSerializableInstrumentationPass.java    From coroutines with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void pass(ClassNode classNode, InstrumentationState state) {
    Validate.notNull(classNode);
    Validate.notNull(state);

    
    // Methods attributes should be assigned at this point.
    Validate.validState(!state.methodAttributes().isEmpty());
    Validate.validState(state.methodAttributes().keySet().stream().allMatch(x -> x != null));
    Validate.validState(state.methodAttributes().values().stream().allMatch(x -> x != null));

    // Sanity check to make sure that we're only dealing with methodnodes in the classnode -- this should never trigger unless previous
    // passes mess up
    Validate.validState(classNode.methods.containsAll(state.methodAttributes().keySet()));

    
    // Should we skip this?
    if (!state.instrumentationSettings().isAutoSerializable()) {
        return;
    }

    
    // Skip if interface
    if ((classNode.access & Opcodes.ACC_INTERFACE) == Opcodes.ACC_INTERFACE) {
        throw new IllegalArgumentException("Auto-serializing an interface not allowed");
    }
    
    
    //Add the field in
    Type serializableType = Type.getType(Serializable.class);
    String serializableTypeStr = serializableType.getInternalName();
    
    if (!classNode.interfaces.contains(serializableTypeStr)) {
        classNode.interfaces.add(serializableTypeStr);
    }

    if (!classNode.fields.stream().anyMatch(fn -> INSTRUMENTED_SERIALIZEUID_FIELD_NAME.equals(fn.name))) {
        FieldNode serialVersionUIDFieldNode = new FieldNode(
                INSTRUMENTED_SERIALIZEUID_FIELD_ACCESS,
                INSTRUMENTED_SERIALIZEUID_FIELD_NAME,
                INSTRUMENTED_SERIALIZEUID_FIELD_TYPE.getDescriptor(),
                null,
                INSTRUMENTED_SERIALIZEUID_FIELD_VALUE);
        classNode.fields.add(serialVersionUIDFieldNode);
    }
}
 
Example 17
Source File: CacheVariables.java    From coroutines with GNU Lesser General Public License v3.0 4 votes vote down vote up
public Variable getObjectReturnCacheVar() {
    Validate.validState(objectReturnCacheVar != null, "Return cache variable of type not assigned");
    return objectReturnCacheVar;
}
 
Example 18
Source File: AsciiTable.java    From asciitable with Apache License 2.0 2 votes vote down vote up
/**
 * Adds a rule row to the table with a given style.
 * @param style the rule style, must not be null nor {@link TableRowStyle#UNKNOWN}
 * @throws {@link NullPointerException} if style was null
 * @throws {@link IllegalArgumentException} if style was {@link TableRowStyle#UNKNOWN}
 */
public final void addRule(TableRowStyle style){
	Validate.notNull(style);
	Validate.validState(style!=TableRowStyle.UNKNOWN, "cannot add a rule of unknown style");
	this.rows.add(AT_Row.createRule(TableRowType.RULE, style));
}
 
Example 19
Source File: CWC_LongestWordMin.java    From asciitable with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new width object.
 * @param min the minimum width of each column, cannot be smaller than 3
 * @throws IllegalArgumentException if the parameter was less than 3
 */
public CWC_LongestWordMin(int min){
	Validate.validState(min>=3, "minimum column width cannot be smaller than 3");
	this.min = min;
}
 
Example 20
Source File: CWC_LongestWordMax.java    From asciitable with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new width object.
 * @param max the maximum width of each column, cannot be smaller than 3
 * @throws IllegalArgumentException if the parameter was less than 3
 */
public CWC_LongestWordMax(int max){
	Validate.validState(max>=3, "maximum column width cannot be smaller than 3");
	this.max = max;
}