mirror of
				https://e.coding.net/circlecloud/YumCore.git
				synced 2025-11-03 23:06:02 +00:00 
			
		
		
		
	
							
								
								
									
										2
									
								
								pom.xml
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								pom.xml
									
									
									
									
									
								
							@@ -4,7 +4,7 @@
 | 
				
			|||||||
    <modelVersion>4.0.0</modelVersion>
 | 
					    <modelVersion>4.0.0</modelVersion>
 | 
				
			||||||
    <groupId>pw.yumc</groupId>
 | 
					    <groupId>pw.yumc</groupId>
 | 
				
			||||||
    <artifactId>YumCore</artifactId>
 | 
					    <artifactId>YumCore</artifactId>
 | 
				
			||||||
    <version>1.8.5</version>
 | 
					    <version>1.8.6</version>
 | 
				
			||||||
    <build>
 | 
					    <build>
 | 
				
			||||||
        <finalName>${project.artifactId}</finalName>
 | 
					        <finalName>${project.artifactId}</finalName>
 | 
				
			||||||
        <plugins>
 | 
					        <plugins>
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										46
									
								
								src/main/java/pw/yumc/YumCore/utils/Assert.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								src/main/java/pw/yumc/YumCore/utils/Assert.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,46 @@
 | 
				
			|||||||
 | 
					package pw.yumc.YumCore.utils;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.Objects;
 | 
				
			||||||
 | 
					import java.util.function.Consumer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Created with IntelliJ IDEA
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @author 喵♂呜
 | 
				
			||||||
 | 
					 * Created on 2017/9/1 10:49.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					public class Assert<T> {
 | 
				
			||||||
 | 
					    private T t;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static <T> Assert<T> of(T value) {
 | 
				
			||||||
 | 
					        return new Assert<>(value);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static void runIsTrue(Boolean bool, Runnable runnable) {
 | 
				
			||||||
 | 
					        if (bool)
 | 
				
			||||||
 | 
					            runnable.run();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static void runOrElse(Boolean bool, Runnable t, Runnable f) {
 | 
				
			||||||
 | 
					        if (bool)
 | 
				
			||||||
 | 
					            t.run();
 | 
				
			||||||
 | 
					        else
 | 
				
			||||||
 | 
					            f.run();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public Assert(T t) {
 | 
				
			||||||
 | 
					        this.t = t;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void runNonNull(Consumer<? super T> consumer) {
 | 
				
			||||||
 | 
					        runIsTrue(Objects.nonNull(t), () -> consumer.accept(t));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void runIsNull(Consumer<? super T> consumer) {
 | 
				
			||||||
 | 
					        runIsTrue(Objects.isNull(t), () -> consumer.accept(t));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void runIsAssignable(Class clazz, Consumer<? super T> consumer) {
 | 
				
			||||||
 | 
					        runIsTrue(clazz.isAssignableFrom(t.getClass()), () -> consumer.accept(t));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user