List of usage examples for com.google.common.base Preconditions checkNotNull
public static <T> T checkNotNull(T reference, @Nullable Object errorMessage)
From source file:com.github.jeluard.guayaba.lang.Classes.java
/** * @param type//w w w . j av a2 s. c om * @return all superClasses of specified {@link Class} */ public static List<Class<?>> allSuperClasses(final Class<?> type) { Preconditions.checkNotNull(type, "null type"); final List<Class<?>> superClasses = new LinkedList<Class<?>>(); Class<?> superClass = type.getSuperclass(); while (superClass != null) { superClasses.add(superClass); superClass = superClass.getSuperclass(); } return superClasses; }
From source file:com.github.jeluard.stone.helper.Loggers.java
/** * @param suffix/*from www.ja v a 2s. c o m*/ * @return a configured {@link Logger} */ public static Logger create(final String suffix) { Preconditions.checkNotNull(suffix, "null suffix"); return Logger.getLogger(Loggers.BASE_LOGGER_NAME + "." + suffix); }
From source file:org.fusesource.process.manager.support.FileUtils.java
public static void extractArchive(File archiveFile, File targetDirectory, String extractCommand, Duration timeLimit, Executor executor) throws CommandFailedException { Preconditions.checkNotNull(archiveFile, "archiveFile is null"); Preconditions.checkNotNull(targetDirectory, "targetDirectory is null"); Preconditions.checkArgument(targetDirectory.isDirectory(), "targetDirectory is not a directory: " + targetDirectory.getAbsolutePath()); final String[] commands = extractCommand.split(" "); final String[] args = Arrays.copyOf(commands, commands.length + 1); args[args.length - 1] = archiveFile.getAbsolutePath(); new Command(args).setDirectory(targetDirectory).setTimeLimit(timeLimit).execute(executor); }
From source file:com.github.jeluard.guayaba.lang.ToStringBuilders.java
/** * @param object// ww w . ja v a2s.c o m * @return a {@link String} representation of specified object. */ public static String reflectionToString(final Object object) { Preconditions.checkNotNull(object, "null object"); final Objects.ToStringHelper toStringHelper = Objects.toStringHelper(object); for (final Field field : Classes.allFields(object.getClass())) { field.setAccessible(true); toStringHelper.add(field.getName(), Fields.get(field, object)); } return toStringHelper.toString(); }
From source file:com.marand.thinkmed.medications.TherapyTaggingUtils.java
public static String generateTag(final TherapyTagEnum therapyTagEnum, @Nonnull final String centralCaseId) { Preconditions.checkNotNull(centralCaseId, "centralCaseId"); return therapyTagEnum.getPrefix() + centralCaseId; }
From source file:com.tansun.rocketmq.connect.tools.FastBeanUtils.java
public static Object copyProperties(Object source, Class<?> target) { Preconditions.checkNotNull(source, "Source must not be null!"); Preconditions.checkNotNull(target, "Target must not be null!"); Object targetObject = ReflectUtils.newInstance(target); BeanCopier beanCopier = BeanCopier.create(source.getClass(), target, false); beanCopier.copy(source, targetObject, null); return targetObject; }
From source file:tv.icntv.recommend.common.ReflectionUtils.java
public static Object newInstance(String className) throws ClassNotFoundException, IllegalAccessException, InstantiationException { Preconditions.checkNotNull(null != className, "class name null"); return classLoader.loadClass(className).newInstance(); }
From source file:io.pravega.common.io.StreamHelpers.java
/** * Reads at most 'maxLength' bytes from the given input stream, as long as the stream still has data to serve. * * @param stream The InputStream to read from. * @param target The target array to write data to. * @param startOffset The offset within the target array to start writing data to. * @param maxLength The maximum number of bytes to copy. * @return The number of bytes copied.// ww w . ja va 2 s.c o m * @throws IOException If unable to read from the given stream. */ public static int readAll(InputStream stream, byte[] target, int startOffset, int maxLength) throws IOException { Preconditions.checkNotNull(stream, "stream"); Preconditions.checkNotNull(stream, "target"); Preconditions.checkElementIndex(startOffset, target.length, "startOffset"); Exceptions.checkArgument(maxLength >= 0, "maxLength", "maxLength must be a non-negative number."); int totalBytesRead = 0; while (totalBytesRead < maxLength) { int bytesRead = stream.read(target, startOffset + totalBytesRead, maxLength - totalBytesRead); if (bytesRead < 0) { // End of stream/ break; } totalBytesRead += bytesRead; } return totalBytesRead; }
From source file:com.google.security.zynamics.binnavi.Gui.Debug.RemoteBrowser.FileBrowser.CRemoteBrowserHelpers.java
/** * Determines whether a given file is a drive or not. * * @param file The file in question./*from w ww .j a v a2 s . c o m*/ * * @return True, if the file is a drive. False, otherwise. */ public static boolean isDrive(final File file) { Preconditions.checkNotNull(file, "IE01493: File argument can not be null"); return file.getParent() == null; }
From source file:io.pravega.common.concurrent.ExecutorServiceHelpers.java
/** * Gets a snapshot of the given ExecutorService. * * @param service The ExecutorService to request a snapshot on. * @return A Snapshot of the given ExecutorService, or null if not supported. */// w ww . j a v a2 s .c om public static Snapshot getSnapshot(ExecutorService service) { Preconditions.checkNotNull(service, "service"); if (service instanceof ThreadPoolExecutor) { val tpe = (ThreadPoolExecutor) service; return new Snapshot(tpe.getQueue().size(), tpe.getActiveCount(), tpe.getPoolSize()); } else if (service instanceof ForkJoinPool) { val fjp = (ForkJoinPool) service; return new Snapshot(fjp.getQueuedSubmissionCount(), fjp.getActiveThreadCount(), fjp.getPoolSize()); } else { return null; } }