code
stringlengths
73
34.1k
label
stringclasses
1 value
public String resource_to_string(base_resource resrc, options option) { String result = "{ "; if (option != null && option.get_action() != null) result = result + "\"params\": {\"action\":\"" + option.get_action() + "\"},"; result = result + "\"" + resrc.get_object_type() + "\":" + this.resource_to_str...
java
public String resource_to_string(base_resource resources[], options option) { String objecttype = resources[0].get_object_type(); String request = "{"; if (option != null && option.get_action() != null) request = request + "\"params\": {\"action\": \"" + option.get_action() + "\"},"; request = req...
java
public String resource_to_string(base_resource resources[], options option, String onerror) { String objecttype = resources[0].get_object_type(); String request = "{"; if ( (option != null && option.get_action() != null) || (!onerror.equals("")) ) { request = request + "\"params\":{"; if ...
java
@NullSafe public static Class<?> getClass(Object obj) { return obj != null ? obj.getClass() : null; }
java
@NullSafe public static String getClassSimpleName(Object obj) { return obj != null ? obj.getClass().getSimpleName() : null; }
java
@SuppressWarnings({ "unchecked", "all" }) public static <T> Constructor<T> findConstructor(Class<T> type, Object... arguments) { for (Constructor<?> constructor : type.getDeclaredConstructors()) { Class<?>[] parameterTypes = constructor.getParameterTypes(); if (ArrayUtils.nullSafeLength(arguments) ...
java
public static <T> Constructor<T> getConstructor(Class<T> type, Class<?>... parameterTypes) { try { return type.getDeclaredConstructor(parameterTypes); } catch (NoSuchMethodException cause) { throw new ConstructorNotFoundException(cause); } }
java
public static <T> Constructor<T> resolveConstructor(Class<T> type, Class<?>[] parameterTypes, Object... arguments) { try { return getConstructor(type, parameterTypes); } catch (ConstructorNotFoundException cause) { Constructor<T> constructor = findConstructor(type, arguments); Assert.no...
java
public static Field getField(Class<?> type, String fieldName) { try { return type.getDeclaredField(fieldName); } catch (NoSuchFieldException cause) { if (type.getSuperclass() != null) { return getField(type.getSuperclass(), fieldName); } throw new FieldNotFoundException(ca...
java
@SuppressWarnings("all") public static Method findMethod(Class<?> type, String methodName, Object... arguments) { for (Method method : type.getDeclaredMethods()) { if (method.getName().equals(methodName)) { Class<?>[] parameterTypes = method.getParameterTypes(); if (ArrayUtils.nullSafeLe...
java
public static Method getMethod(Class<?> type, String methodName, Class<?>... parameterTypes) { try { return type.getDeclaredMethod(methodName, parameterTypes); } catch (NoSuchMethodException cause) { if (type.getSuperclass() != null) { return getMethod(type.getSuperclass(), methodName,...
java
public static Method resolveMethod(Class<?> type, String methodName, Class<?>[] parameterTypes, Object[] arguments, Class<?> returnType) { try { return getMethod(type, methodName, parameterTypes); } catch (MethodNotFoundException cause) { Method method = findMethod(type, methodName, argu...
java
protected static String getMethodSignature(Method method) { return getMethodSignature(method.getName(), method.getParameterTypes(), method.getReturnType()); }
java
protected static String getMethodSignature(String methodName, Class<?>[] parameterTypes, Class<?> returnType) { StringBuilder buffer = new StringBuilder(methodName); buffer.append("("); if (parameterTypes != null) { int index = 0; for (Class<?> parameterType : parameterTypes) { buff...
java
@NullSafe public static String getName(Class type) { return type != null ? type.getName() : null; }
java
@NullSafe public static String getSimpleName(Class type) { return type != null ? type.getSimpleName() : null; }
java
@NullSafe public static boolean instanceOf(Object obj, Class<?> type) { return type != null && type.isInstance(obj); }
java
@NullSafe public static boolean isAnnotationPresent(Class<? extends Annotation> annotation, AnnotatedElement... members) { return stream(ArrayUtils.nullSafeArray(members, AnnotatedElement.class)) .anyMatch(member -> member != null && member.isAnnotationPresent(annotation)); }
java
@NullSafe public static boolean isClass(Class type) { return type != null && !(type.isAnnotation() || type.isArray() || type.isEnum() || type.isInterface() || type.isPrimitive()); }
java
public static <T> Class<T> loadClass(String fullyQualifiedClassName) { return loadClass(fullyQualifiedClassName, DEFAULT_INITIALIZE_LOADED_CLASS, Thread.currentThread().getContextClassLoader()); }
java
@NullSafe @SuppressWarnings("all") public static boolean notInstanceOf(Object obj, Class... types) { boolean result = true; for (int index = 0; result && index < ArrayUtils.nullSafeLength(types); index++) { result &= !instanceOf(obj, types[index]); } return result; }
java
public static byte[] encrypt(byte[] data, byte[] key) { checkNotNull(data); checkNotNull(key); checkArgument(key.length >= 5 && key.length <= 256); StreamCipher rc4 = new RC4Engine(); rc4.init(true, new KeyParameter(key)); byte[] encrypted = new byte[data.length]; ...
java
public static OutputStream encrypt(OutputStream outputStream, byte[] key) { checkNotNull(outputStream); checkNotNull(key); checkArgument(key.length >= 5 && key.length <= 256); StreamCipher rc4 = new RC4Engine(); rc4.init(true, new KeyParameter(key)); return new CipherOutp...
java
public static byte[] decrypt(byte[] data, byte[] key) { checkNotNull(data); checkNotNull(key); checkArgument(key.length >= 5 && key.length <= 256); StreamCipher rc4 = new RC4Engine(); rc4.init(false, new KeyParameter(key)); byte[] decrypted = new byte[data.length]; ...
java
public static InputStream decrypt(InputStream inputStream, byte[] key) { checkNotNull(inputStream); checkNotNull(key); checkArgument(key.length >= 5 && key.length <= 256); StreamCipher rc4 = new RC4Engine(); rc4.init(false, new KeyParameter(key)); return new CipherInputSt...
java
public static StreamCipher createRC4DropCipher(byte[] key, int drop) { checkArgument(key.length >= 5 && key.length <= 256); checkArgument(drop > 0); RC4Engine rc4Engine = new RC4Engine(); rc4Engine.init(true, new KeyParameter(key)); byte[] dropBytes = new byte[drop]; Arra...
java
public static xen_health_interface get(nitro_service client, xen_health_interface resource) throws Exception { resource.validate("get"); return ((xen_health_interface[]) resource.get_resources(client))[0]; }
java
private Map<String, Long> listFiles() throws FtpException { int attempts = 0; Map<String, Long> files = new LinkedHashMap<String, Long>(); while (true){ try { FTPListParseEngine engine = null; if (type.startsWith("UNIX")) { engine = ftpClient.initiateListParsing(FTPClientConfig.SYST_UNIX, null); ...
java
public static String normalizeKey(Algorithms alg) { if (alg.equals(Algorithms.SHA512)) { return FieldName.SHA512; } return alg.toString().toLowerCase(); }
java
<O extends Message> JsonResponseFuture<O> newProvisionalResponse(ClientMethod<O> method) { long requestId = RANDOM.nextLong(); JsonResponseFuture<O> outputFuture = new JsonResponseFuture<>(requestId, method); inFlightRequests.put(requestId, outputFuture); return outputFuture; }
java
public static String concat(String[] values, String delimiter) { Assert.notNull(values, "The array of String values to concatenate cannot be null!"); StringBuilder buffer = new StringBuilder(); for (String value : values) { buffer.append(buffer.length() > 0 ? delimiter : EMPTY_STRING); buffer...
java
@NullSafe public static boolean contains(String text, String value) { return text != null && value != null && text.contains(value); }
java
@NullSafe public static boolean containsDigits(String value) { for (char chr : toCharArray(value)) { if (Character.isDigit(chr)) { return true; } } return false; }
java
@NullSafe public static boolean containsLetters(String value) { for (char chr: toCharArray(value)) { if (Character.isLetter(chr)) { return true; } } return false; }
java
@NullSafe public static boolean containsWhitespace(String value) { for (char chr : toCharArray(value)) { if (Character.isWhitespace(chr)) { return true; } } return false; }
java
@NullSafe public static String defaultIfBlank(String value, String... defaultValues) { if (isBlank(value)) { for (String defaultValue : defaultValues) { if (hasText(defaultValue)) { return defaultValue; } } } return value; }
java
@NullSafe public static boolean equalsIgnoreCase(String stringOne, String stringTwo) { return stringOne != null && stringOne.equalsIgnoreCase(stringTwo); }
java
public static String getDigits(String value) { StringBuilder digits = new StringBuilder(value.length()); for (char chr : value.toCharArray()) { if (Character.isDigit(chr)) { digits.append(chr); } } return digits.toString(); }
java
public static String getLetters(String value) { StringBuilder letters = new StringBuilder(value.length()); for (char chr : value.toCharArray()) { if (Character.isLetter(chr)) { letters.append(chr); } } return letters.toString(); }
java
public static String getSpaces(int number) { Assert.argument(number >= 0, "The number [{0}] of desired spaces must be greater than equal to 0", number); StringBuilder spaces = new StringBuilder(Math.max(number, 0)); while (number > 0) { int count = Math.min(SPACES.length - 1, number); spaces....
java
@NullSafe public static int indexOf(String text, String value) { return text != null && value != null ? text.indexOf(value) : -1; }
java
@NullSafe public static boolean isDigits(String value) { for (char chr : toCharArray(value)) { if (!Character.isDigit(chr)) { return false; } } return hasText(value); }
java
@NullSafe public static boolean isLetters(String value) { for (char chr : toCharArray(value)) { if (!Character.isLetter(chr)) { return false; } } return hasText(value); }
java
@NullSafe public static int lastIndexOf(String text, String value) { return text != null && value != null ? text.lastIndexOf(value) : -1; }
java
@NullSafe public static String pad(String value, int length) { return pad(value, SINGLE_SPACE_CHAR, length); }
java
@NullSafe @SuppressWarnings("all") public static String pad(String value, char padding, int length) { assertThat(length).throwing(new IllegalArgumentException(String.format( "[%d] must be greater than equal to 0", length))).isGreaterThanEqualTo(0); if (length > 0) { StringBuilder builder = ne...
java
public static String singleSpaceObjects(Object... values) { List<String> valueList = new ArrayList<>(values.length); for (Object value : values) { valueList.add(String.valueOf(value)); } return trim(concat(valueList.toArray(new String[valueList.size()]), SINGLE_SPACE)); }
java
public static String singleSpaceString(String value) { Assert.hasText(value, "String value must contain text"); return trim(concat(value.split("\\s+"), SINGLE_SPACE)); }
java
@NullSafe public static String toLowerCase(String value) { return value != null ? value.toLowerCase() : null; }
java
@NullSafe @SuppressWarnings("all") public static String[] toStringArray(String delimitedValue, String delimiter) { return ArrayUtils.transform(ObjectUtils.defaultIfNull(delimitedValue, EMPTY_STRING).split( defaultIfBlank(delimiter, COMMA_DELIMITER)), StringUtils::trim); }
java
@NullSafe public static String toUpperCase(String value) { return value != null ? value.toUpperCase() : null; }
java
@NullSafe public static String trim(String value) { return value != null ? value.trim() : null; }
java
@NullSafe public static String truncate(String value, int length) { assertThat(length).throwing(new IllegalArgumentException(String.format( "[%d] must be greater than equal to 0", length))).isGreaterThanEqualTo(0); return (value != null ? value.substring(0, Math.min(value.length(), length)) : null); ...
java
public static String wrap(String line, int widthInCharacters, String indent) { StringBuilder buffer = new StringBuilder(); int lineCount = 1; int spaceIndex; // if indent is null, then do not indent the wrapped lines indent = (indent != null ? indent : EMPTY_STRING); while (line.length() > w...
java
public static boolean init(Object initableObj) { if (initableObj instanceof Initable) { ((Initable) initableObj).init(); return true; } return false; }
java
public static xen_health_monitor_fan_speed[] get_filtered(nitro_service service, filtervalue[] filter) throws Exception { xen_health_monitor_fan_speed obj = new xen_health_monitor_fan_speed(); options option = new options(); option.set_filter(filter); xen_health_monitor_fan_speed[] response = (xen_health_...
java
public static ns_vserver_appflow_config[] get_filtered(nitro_service service, filtervalue[] filter) throws Exception { ns_vserver_appflow_config obj = new ns_vserver_appflow_config(); options option = new options(); option.set_filter(filter); ns_vserver_appflow_config[] response = (ns_vserver_appflow_conf...
java
public static techsupport[] get_filtered(nitro_service service, filtervalue[] filter) throws Exception { techsupport obj = new techsupport(); options option = new options(); option.set_filter(filter); techsupport[] response = (techsupport[]) obj.getfiltered(service, option); return response; }
java
public static double cylinderSurfaceArea(final double radius, final double height) { return ((2.0d * Math.PI * Math.pow(radius, 2)) + (2.0d * Math.PI * radius * height)); }
java
public static BigInteger factorial(BigInteger value) { Assert.notNull(value, "value must not be null"); Assert.isTrue(value.compareTo(BigInteger.ZERO) >= 0, String.format(NUMBER_LESS_THAN_ZERO_ERROR_MESSAGE, value)); if (value.compareTo(TWO) <= 0) { return (value.equals(TWO) ? TWO : BigInteger.ONE); ...
java
public static int[] fibonacciSequence(final int n) { Assert.argument(n > 0, "The number of elements from the Fibonacci Sequence to calculate must be greater than equal to 0!"); int[] fibonacciNumbers = new int[n]; for (int position = 0; position < n; position++) { if (position == 0) { fibona...
java
@NullSafe public static double max(final double... values) { double maxValue = Double.NaN; if (values != null) { for (double value : values) { maxValue = (Double.isNaN(maxValue) ? value : Math.max(maxValue, value)); } } return maxValue; }
java
@NullSafe public static double min(final double... values) { double minValue = Double.NaN; if (values != null) { for (double value : values) { minValue = (Double.isNaN(minValue) ? value : Math.min(minValue, value)); } } return minValue; }
java
@NullSafe public static int multiply(final int... numbers) { int result = 0; if (numbers != null) { result = (numbers.length > 0 ? 1 : 0); for (int number : numbers) { result *= number; } } return result; }
java
public static double rectangularPrismSurfaceArea(final double length, final double height, final double width) { return ((2 * length * height) + (2 * length * width) + (2 * height * width)); }
java
@NullSafe public static int sum(final int... numbers) { int sum = 0; if (numbers != null) { for (int number : numbers) { sum += number; } } return sum; }
java
public static mps get(nitro_service client) throws Exception { mps resource = new mps(); resource.validate("get"); return ((mps[]) resource.get_resources(client))[0]; }
java
public static Serializable copy(Serializable obj) { try { ByteArrayOutputStream buf = new ByteArrayOutputStream(4096); ObjectOutputStream out = new ObjectOutputStream(buf); out.writeObject(obj); out.close(); ByteArrayInputStream buf2 = new ByteArrayIn...
java
public static <T> Constructor<T> getConstructor(Class<T> cls, Class... params) { try { return cls.getConstructor(params); } catch (Exception e) { throw new ClientException(e); } }
java
public static <T> T newInstance(Constructor<T> constructor, Object... args) { try { return constructor.newInstance(args); } catch (Exception e) { throw new ClientException(e); } }
java
private static <T> @NonNull List<T> topologicalSort(final @NonNull Graph<T> graph, final @NonNull SortType<T> type) { checkArgument(graph.isDirected(), "the graph must be directed"); checkArgument(!graph.allowsSelfLoops(), "the graph cannot allow self loops"); final Map<T, Integer> requiredCounts = new Has...
java
private <I extends Message, O extends Message> void invoke( ServerMethod<I, O> method, ByteString payload, long requestId, Channel channel) { FutureCallback<O> callback = new ServerMethodCallback<>(method, requestId, channel); try { I request = method.inputParser().parseFrom(payload); Listenab...
java
public String getPreferenceValue(String key, String defaultValue) { if (userCFProperties.containsKey(key)) return userCFProperties.getProperty(key); else if (userHomeCFProperties.containsKey(key)) return userHomeCFProperties.getProperty(key); else if (systemCFProperties.containsKey(key)) return systemCFP...
java
public static xen_health_monitor_temp[] get_filtered(nitro_service service, filtervalue[] filter) throws Exception { xen_health_monitor_temp obj = new xen_health_monitor_temp(); options option = new options(); option.set_filter(filter); xen_health_monitor_temp[] response = (xen_health_monitor_temp[]) obj....
java
public static <L, R> @NonNull Pair<L, R> left(final @Nullable L left) { return of(left, null); }
java
public static <L, R> @NonNull Pair<L, R> right(final @Nullable R right) { return of(null, right); }
java
public static <L, R> @NonNull Pair<L, R> of(final Map.Entry<L, R> entry) { return of(entry.getKey(), entry.getValue()); }
java
public static <L, R> @NonNull Pair<L, R> of(final @Nullable L left, final @Nullable R right) { return new Pair<>(left, right); }
java
public <NL, NR> @NonNull Pair<NL, NR> map(final @NonNull Function<? super L, ? extends NL> left, final @NonNull Function<? super R, ? extends NR> right) { return new Pair<>(left.apply(this.left), right.apply(this.right)); }
java
public <NL> @NonNull Pair<NL, R> lmap(final @NonNull Function<? super L, ? extends NL> function) { return new Pair<>(function.apply(this.left), this.right); }
java
public <NR> @NonNull Pair<L, NR> rmap(final @NonNull Function<? super R, ? extends NR> function) { return new Pair<>(this.left, function.apply(this.right)); }
java
public static String defaultURL(String driver) { assert Driver.exists(driver); String home = ""; try { home = VictimsConfig.home().toString(); } catch (VictimsException e) { // Ignore and use cwd } return Driver.url(driver, FilenameUtils.concat(hom...
java
public static xen_brvpx_image get(nitro_service client, xen_brvpx_image resource) throws Exception { resource.validate("get"); return ((xen_brvpx_image[]) resource.get_resources(client))[0]; }
java
protected base_resource[] get_resources(nitro_service service, options option) throws Exception { if (!service.isLogin()) service.login(); String response = _get(service, option); return get_nitro_response(service, response); }
java
public base_resource[] perform_operation(nitro_service service) throws Exception { if (!service.isLogin() && !get_object_type().equals("login")) service.login(); return post_request(service, null); }
java
protected base_resource[] add_resource(nitro_service service, options option) throws Exception { if (!service.isLogin() && !get_object_type().equals("login")) service.login(); String request = resource_to_string(service, option); return post_data(service, request); }
java
protected base_resource[] update_resource(nitro_service service, options option) throws Exception { if (!service.isLogin() && !get_object_type().equals("login")) service.login(); String request = resource_to_string(service, option); return put_data(service,request); }
java
protected base_resource[] delete_resource(nitro_service service) throws Exception { if (!service.isLogin()) service.login(); String str = nitro_util.object_to_string_withoutquotes(this); String response = _delete(service, str); return get_nitro_response(service, response); }
java
private String _delete(nitro_service service, String req_args) throws Exception { StringBuilder responseStr = new StringBuilder(); HttpURLConnection httpURLConnection = null; try { String urlstr; String ipaddress = service.get_ipaddress(); String version = service.get_version(); String ses...
java
protected static base_resource[] update_bulk_request(nitro_service service,base_resource resources[]) throws Exception { if (!service.isLogin()) service.login(); String objtype = resources[0].get_object_type(); String onerror = service.get_onerror(); //String id = service.get_sessionid(); Str...
java
public void uninstallBundle(final String symbolicName, final String version) { Bundle bundle = bundleDeployerService.getExistingBundleBySymbolicName(symbolicName, version, null); if (bundle != null) { stateChanged = true; Logger.info("Uninstalling bundle: " + bundle); ...
java
public void setResponse(Envelope response) { if (response.hasControl() && response.getControl().hasError()) { setException(new Exception(response.getControl().getError())); return; } try { set(clientMethod.outputParser().parseFrom(response.getPayload())); clientLogger.logSuccess(clie...
java
public static host_interface reset(nitro_service client, host_interface resource) throws Exception { return ((host_interface[]) resource.perform_operation(client, "reset"))[0]; }
java
public static Collection<String> getTagNames(Channel channel) { Collection<String> tagNames = new HashSet<String>(); for (Tag tag : channel.getTags()) { tagNames.add(tag.getName()); } return tagNames; }
java
public static Collection<String> getAllTagNames(Collection<Channel> channels) { Collection<String> tagNames = new HashSet<String>(); for (Channel channel : channels) { tagNames.addAll(getTagNames(channel)); } return tagNames; }
java
public static Collection<String> getPropertyNames(Channel channel) { Collection<String> propertyNames = new HashSet<String>(); for (Property property : channel.getProperties()) { if (property.getValue() != null) propertyNames.add(property.getName()); } return propertyNames; }
java
@Deprecated public static Tag getTag(Channel channel, String tagName) { Collection<Tag> tag = Collections2.filter(channel.getTags(), new TagNamePredicate(tagName)); if (tag.size() == 1) return tag.iterator().next(); else return null; }
java
@Deprecated public static Property getProperty(Channel channel, String propertyName) { Collection<Property> property = Collections2.filter( channel.getProperties(), new PropertyNamePredicate(propertyName)); if (property.size() == 1) return property.iterator().next(); else return null; }
java
public static Collection<String> getPropertyNames( Collection<Channel> channels) { Collection<String> propertyNames = new HashSet<String>(); for (Channel channel : channels) { propertyNames.addAll(getPropertyNames(channel)); } return propertyNames; }
java
public static Collection<String> getChannelNames( Collection<Channel> channels) { Collection<String> channelNames = new HashSet<String>(); for (Channel channel : channels) { channelNames.add(channel.getName()); } return channelNames; }
java