public Record(final PersistentObject entity) { NullCheckingUtil.checkArgsNotNull(entity); this.entity = entity; }
/** * Return the StackTraceElement at the given offset from this method * invocation. * * @param offset * @return a StackTraceElement */ public static StackTraceElement getCaller(final int offset) { final StackTraceElement[] stes = Thread.currentThread().getStackTrace(); StackTraceElement callerSTE = null; for (int i = 0; i < stes.length - offset - 1; i++) { if (stes[i].getClassName().equals(NullCheckingUtil.class.getName()) && stes[i].getMethodName().equals("getCaller")) { callerSTE = stes[i + 1 + offset]; break; } } badStateIfNull(callerSTE, "Ouch! Can't get the stack trace back to the caller of this method!"); return callerSTE; }
/** * This method throw an IllegalStateException if the given parameter is null * * @param valueToCheck * the value to check * @param msg * the message for the thrown exception * @see IllegalStateException */ public static void badStateIfNull(final Object valueToCheck, final String msg) { badStateIfTrue(valueToCheck == null, msg); }
public SConnectorAdapter(final Connector connector) { NullCheckingUtil.checkArgsNotNull(connector); this.connector = connector; }
/** * This method throw an IllegalStateException if the given parameter is null * * @param valueToCheck * the value to check * @param msg * the message for the thrown exception * @see IllegalStateException */ public static void badStateIfNull(final Object valueToCheck, final String msg) { badStateIfTrue(valueToCheck == null, msg); }
/** * Return the StackTraceElement at the given offset from this method * invocation. * * @param offset * @return a StackTraceElement */ public static StackTraceElement getCaller(final int offset) { final StackTraceElement[] stes = Thread.currentThread().getStackTrace(); StackTraceElement callerSTE = null; for (int i = 0; i < stes.length - offset - 1; i++) { if (stes[i].getClassName().equals(NullCheckingUtil.class.getName()) && stes[i].getMethodName().equals("getCaller")) { callerSTE = stes[i + 1 + offset]; break; } } badStateIfNull(callerSTE, "Ouch! Can't get the stack trace back to the caller of this method!"); return callerSTE; }
public SConnectorAdapter(final Connector connector) { NullCheckingUtil.checkArgsNotNull(connector); this.connector = connector; }
/** * Check that the given parameters are not null. * This method should only be used to check that some parameters given to a * given method are not null. The exception message tries its best to produce * a helpful message by scanning the stack trace. * * @param params * the parameters to check * @throws IllegalArgumentException * if at least one of the parameters is null */ public static void checkArgsNotNull(final Object... params) { checkArgsNotNull(1, params); }
/** * Check that the given parameters are not null. * This method should only be used to check that some parameters given to a * given method are not null. The exception message tries its best to produce * a helpful message by scanning the stack trace. * * @param params * the parameters to check * @throws IllegalArgumentException * if at least one of the parameters is null */ public static void checkArgsNotNull(final Object... params) { checkArgsNotNull(1, params); }
public Record(final PersistentObject entity) { NullCheckingUtil.checkArgsNotNull(entity); this.entity = entity; }
public static void write(final File file, final byte[] fileContent) throws IOException { NullCheckingUtil.checkArgsNotNull(file, fileContent); if (!file.exists()) { file.getParentFile().mkdirs(); file.createNewFile(); } final OutputStream os = new FileOutputStream(file); try { os.write(fileContent); os.flush(); } finally { os.close(); } }
public static void write(final File file, final byte[] fileContent) throws IOException { NullCheckingUtil.checkArgsNotNull(file, fileContent); if (!file.exists()) { file.getParentFile().mkdirs(); file.createNewFile(); } final OutputStream os = new FileOutputStream(file); try { os.write(fileContent); os.flush(); } finally { os.close(); } }
@Override public List<SDataInstance> getDataInstances(final long containerId, final String containerType, final ParentContainerResolver parentContainerResolver, final int fromIndex, final int numberOfResults) throws SDataInstanceException { NullCheckingUtil.checkArgsNotNull(containerType); final String queryName = "getDataInstances"; final Map<String, Object> inputParameters = new HashMap<String, Object>(); final List<SDataInstance> dataInstances = getSDatainstanceOfContainers(containerId, containerType, parentContainerResolver, queryName, inputParameters); //apply pagination final int startIndex = Math.max(0, fromIndex); final int toIndex = Math.min(dataInstances.size(), fromIndex + numberOfResults); return dataInstances.subList(startIndex, toIndex); }
@Override public List<SDataInstance> getDataInstances(final long containerId, final String containerType, final ParentContainerResolver parentContainerResolver, final int fromIndex, final int numberOfResults) throws SDataInstanceException { NullCheckingUtil.checkArgsNotNull(containerType); final String queryName = "getDataInstances"; final Map<String, Object> inputParameters = new HashMap<String, Object>(); final List<SDataInstance> dataInstances = getSDatainstanceOfContainers(containerId, containerType, parentContainerResolver, queryName, inputParameters); //apply pagination final int startIndex = Math.max(0, fromIndex); final int toIndex = Math.min(dataInstances.size(), fromIndex + numberOfResults); return dataInstances.subList(startIndex, toIndex); }
@Override public List<SDataInstance> getDataInstances(final List<String> dataNames, final long containerId, final String containerType, final ParentContainerResolver parentContainerResolver) throws SDataInstanceException { logBeforeMethod("getDataInstances"); NullCheckingUtil.checkArgsNotNull(dataNames, containerType); if (dataNames.isEmpty()) { return Collections.emptyList(); } final String queryName = "getDataInstancesWithNames"; final Map<String, Object> inputParameters = new HashMap<String, Object>(); inputParameters.put("dataNames", dataNames); return getSDatainstanceOfContainers(containerId, containerType, parentContainerResolver, queryName, inputParameters); }
@Override public List<SDataInstance> getDataInstances(final List<String> dataNames, final long containerId, final String containerType, final ParentContainerResolver parentContainerResolver) throws SDataInstanceException { logBeforeMethod("getDataInstances"); NullCheckingUtil.checkArgsNotNull(dataNames, containerType); if (dataNames.isEmpty()) { return Collections.emptyList(); } final String queryName = "getDataInstancesWithNames"; final Map<String, Object> inputParameters = new HashMap<String, Object>(); inputParameters.put("dataNames", dataNames); return getSDatainstanceOfContainers(containerId, containerType, parentContainerResolver, queryName, inputParameters); }
@Override public DependencyContent getDependencyContentOnly(final long id) throws SDependencyNotFoundException, SBonitaReadException { NullCheckingUtil.checkArgsNotNull(id); SelectOneDescriptor<DependencyContent> desc = new SelectOneDescriptor<>("getPlatformDependencyContentOnly", Collections.singletonMap("id", id), SPlatformDependency.class, DependencyContent.class); return Optional.ofNullable(platformPersistenceService.selectOne(desc)).orElseThrow(() -> new SDependencyNotFoundException("Can't get content of dependency with id: " + id)); }
@Override public DependencyContent getDependencyContentOnly(final long id) throws SDependencyNotFoundException, SBonitaReadException { NullCheckingUtil.checkArgsNotNull(id); SelectOneDescriptor<DependencyContent> desc = new SelectOneDescriptor<>("getDependencyContentOnly", Collections.singletonMap("id", id), SDependency.class, DependencyContent.class); return Optional.ofNullable(persistenceService.selectOne(desc)).orElseThrow(() -> new SDependencyNotFoundException("Can't get content of dependency with id: " + id)); }