code stringlengths 73 34.1k | label stringclasses 1
value |
|---|---|
public static br_broker force_reboot(nitro_service client, br_broker resource) throws Exception
{
return ((br_broker[]) resource.perform_operation(client, "force_reboot"))[0];
} | java |
public static br_broker force_stop(nitro_service client, br_broker resource) throws Exception
{
return ((br_broker[]) resource.perform_operation(client, "force_stop"))[0];
} | java |
public static br_broker start(nitro_service client, br_broker resource) throws Exception
{
return ((br_broker[]) resource.perform_operation(client, "start"))[0];
} | java |
@Override
public void visit(Visitable visitable) {
if (isCommitable(visitable)) {
ObjectUtils.setField(visitable, "lastModifiedBy", ((Auditable) visitable).getModifiedBy());
ObjectUtils.setField(visitable, "lastModifiedOn", ((Auditable) visitable).getModifiedOn());
ObjectUtils.setField(visitable... | java |
protected boolean isCommitable(Object visitable) {
return (visitable instanceof Auditable && (target == null || identity(visitable) == identity(target)));
} | java |
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
public void apply() {
if (editing == null) {
return;
}
try {
editing.apply();
} catch (Exception ex) {
editing.commit(); // Fallback in case low api lever.
}
editing = null;
} | java |
public boolean commit() {
if (editing == null) {
return false;
}
final boolean result = editing.commit();
editing = null;
return result;
} | java |
public static sdxtools_image[] get_filtered(nitro_service service, filtervalue[] filter) throws Exception
{
sdxtools_image obj = new sdxtools_image();
options option = new options();
option.set_filter(filter);
sdxtools_image[] response = (sdxtools_image[]) obj.getfiltered(service, option);
return respo... | java |
public static synchronized void set(final ObjectFactory objectFactory) {
Assert.state(objectFactoryReference == null, "The ObjectFactory reference is already set to ({0})",
objectFactoryReference);
objectFactoryReference = objectFactory;
} | java |
public static ns_ns_runningconfig get(nitro_service client, ns_ns_runningconfig resource) throws Exception
{
resource.validate("get");
return ((ns_ns_runningconfig[]) resource.get_resources(client))[0];
} | java |
protected void setUp() throws SQLException {
Connection connection = getConnection();
try {
if (!isSetUp(connection)) {
Statement stmt = connection.createStatement();
stmt.execute(Query.CREATE_TABLE_RECORDS);
stmt.execute(Query.CREATE_TABLE_FIL... | java |
protected PreparedStatement statement(Connection connection, String query)
throws SQLException {
return connection.prepareStatement(query);
} | java |
protected PreparedStatement setObjects(Connection connection, String query,
Object... objects) throws SQLException {
PreparedStatement ps = statement(connection, query);
setObjects(ps, objects);
return ps;
} | java |
protected int selectRecordId(String hash) throws SQLException {
int id = -1;
Connection connection = getConnection();
try {
PreparedStatement ps = setObjects(connection, Query.GET_RECORD_ID,
hash);
ResultSet rs = ps.executeQuery();
try {
... | java |
protected int insertRecord(Connection connection, String hash)
throws SQLException {
int id = -1;
PreparedStatement ps = setObjects(connection, Query.INSERT_RECORD, hash);
ps.execute();
ResultSet rs = ps.getGeneratedKeys();
try {
while (rs.next()) {
... | java |
protected void deleteRecord(Connection connection, String hash)
throws SQLException {
int id = selectRecordId(hash);
if (id > 0) {
String[] queries = new String[] { Query.DELETE_FILEHASHES,
Query.DELETE_METAS, Query.DELETE_CVES,
Query.DELET... | java |
protected VALUE withCaching(KEY key, Supplier<VALUE> cacheLoader) {
return getCache()
.map(CachingTemplate::with)
.<VALUE>map(template -> template.withCaching(key, () -> {
setCacheMiss();
return cacheLoader.get();
}))
.orElseGet(cacheLoader);
} | java |
public static xen_websensevpx_image[] get_filtered(nitro_service service, filtervalue[] filter) throws Exception
{
xen_websensevpx_image obj = new xen_websensevpx_image();
options option = new options();
option.set_filter(filter);
xen_websensevpx_image[] response = (xen_websensevpx_image[]) obj.getfiltere... | java |
@Override
public int compare(final Ordered ordered1, final Ordered ordered2) {
return (ordered1.getIndex() < ordered2.getIndex() ? -1 : (ordered1.getIndex() > ordered2.getIndex() ? 1 : 0));
} | java |
private static boolean safeSleep(long milliseconds) {
boolean interrupted = false;
long timeout = (System.currentTimeMillis() + milliseconds);
while (System.currentTimeMillis() < timeout) {
try {
Thread.sleep(milliseconds);
}
catch (InterruptedException cause) {
interrup... | java |
public void accumulate(List<? extends StandardMetricResult> metricValues) {
if (metricValues == null || metricValues.isEmpty()) return;
for (StandardMetricResult v : metricValues) {
if (lastOffset < v.offset) values.put(v.value.intValue());
}
lastOffset = ListUtils.last(metri... | java |
public boolean isExceeded() {
lastAggregatedValue = getAggregatedValue();
lastExceededValue = false;
switch (operator) {
case lessThan:
lastExceededValue = (lastAggregatedValue < thresholdValue);
break;
case greaterThan: lastExceededValue =... | java |
public String getReason() {
if (lastExceededValue) {
return String.format("Metric '%s' has aggregated-value=%d %s %d as threshold", metric.name(), lastAggregatedValue, operator.symbol, thresholdValue);
} else {
return String.format("Metric %s: aggregated-value=%d", metric.name(),... | java |
public static ns_ssl_certkey_policy get(nitro_service client) throws Exception
{
ns_ssl_certkey_policy resource = new ns_ssl_certkey_policy();
resource.validate("get");
return ((ns_ssl_certkey_policy[]) resource.get_resources(client))[0];
} | java |
public static <T, E extends Throwable> @NonNull Consumer<T> rethrowConsumer(final @NonNull ThrowingConsumer<T, E> consumer) {
return consumer;
} | java |
public static <T, U, E extends Throwable> @NonNull BiConsumer<T, U> rethrowBiConsumer(final @NonNull ThrowingBiConsumer<T, U, E> consumer) {
return consumer;
} | java |
public static <T, R, E extends Throwable> @NonNull Function<T, R> rethrowFunction(final @NonNull ThrowingFunction<T, R, E> function) {
return function;
} | java |
public static <T, U, R, E extends Throwable> @NonNull BiFunction<T, U, R> rethrowBiFunction(final @NonNull ThrowingBiFunction<T, U, R, E> function) {
return function;
} | java |
public static <T, E extends Throwable> @NonNull Predicate<T> rethrowPredicate(final @NonNull ThrowingPredicate<T, E> predicate) {
return predicate;
} | java |
public static <E extends Throwable> @NonNull Runnable rethrowRunnable(final @NonNull ThrowingRunnable<E> runnable) {
return runnable;
} | java |
public static <T, E extends Throwable> @NonNull Supplier<T> rethrowSupplier(final @NonNull ThrowingSupplier<T, E> supplier) {
return supplier;
} | java |
public static <E extends Throwable> @NonNull RuntimeException rethrow(final @NonNull Throwable exception) throws E {
throw (E) exception;
} | java |
public static @NonNull Throwable unwrap(final @NonNull Throwable throwable) {
if(throwable instanceof InvocationTargetException) {
final /* @Nullable */ Throwable cause = throwable.getCause();
if(cause != null) {
return cause;
}
}
return throwable;
} | java |
public static ns_ns_savedconfig get(nitro_service client, ns_ns_savedconfig resource) throws Exception
{
resource.validate("get");
return ((ns_ns_savedconfig[]) resource.get_resources(client))[0];
} | java |
protected void create(File cache) throws VictimsException {
try {
FileUtils.forceMkdir(cache);
} catch (IOException e) {
throw new VictimsException("Could not create an on disk cache", e);
}
} | java |
public void purge() throws VictimsException {
try {
File cache = new File(location);
if (cache.exists()) {
FileUtils.deleteDirectory(cache);
}
create(cache);
} catch (IOException e) {
throw new VictimsException("Could not purge ... | java |
protected String hash(String key) throws VictimsException {
try {
MessageDigest mda = MessageDigest
.getInstance(MessageDigestAlgorithms.SHA_256);
return Hex.encodeHexString(mda.digest(key.getBytes()));
} catch (NoSuchAlgorithmException e) {
throw ... | java |
public boolean exists(String key) {
try {
key = hash(key);
return FileUtils.getFile(location, key).exists();
} catch (VictimsException e) {
return false;
}
} | java |
public void delete(String key) throws VictimsException {
key = hash(key);
try {
FileUtils.forceDelete(FileUtils.getFile(location, key));
} catch (IOException e) {
throw new VictimsException(String.format(
"Could not delete the cached entry from disk: %... | java |
public void add(String key, Collection<String> cves)
throws VictimsException {
key = hash(key);
if (exists(key)) {
delete(key);
}
String result = "";
if (cves != null) {
result = StringUtils.join(cves, ",");
}
try {
... | java |
public HashSet<String> get(String key) throws VictimsException {
key = hash(key);
try {
HashSet<String> cves = new HashSet<String>();
String result = FileUtils.readFileToString(
FileUtils.getFile(location, key)).trim();
for (String cve : StringUtil... | java |
public final static byte[] decode(byte[] sArr) {
// Check special case
int sLen = sArr.length;
// Count illegal characters (including '\r', '\n') to know what size the returned array will be,
// so we don't have to reallocate & copy it later.
int sepCnt = 0; // Number of... | java |
@Override
public <E> List<E> sort(final List<E> elements) {
for (int index = 0, size = elements.size(), length = (size - 1); index < length; index++) {
int minIndex = index;
for (int j = (index + 1); j < size; j++) {
if (getOrderBy().compare(elements.get(j), elements.get(minIndex)) < 0) {
... | java |
public static backup_policy get(nitro_service client, backup_policy resource) throws Exception
{
resource.validate("get");
return ((backup_policy[]) resource.get_resources(client))[0];
} | java |
public static synchronized void registerFieldsToFilter(Class<?> containingClass,
String ... fieldNames) {
fieldFilterMap =
registerFilter(fieldFilterMap, containingClass, fieldNames);
} | java |
public static synchronized void registerMethodsToFilter(Class<?> containingClass,
String ... methodNames) {
methodFilterMap =
registerFilter(methodFilterMap, containingClass, methodNames);
} | java |
public static Calendar create(long timeInMilliseconds) {
Calendar dateTime = Calendar.getInstance();
dateTime.clear();
dateTime.setTimeInMillis(timeInMilliseconds);
return dateTime;
} | java |
public void execute(ChannelQueryListener listener) {
addChannelQueryListener(listener);
// Make a local copy to avoid synchronization
Result localResult = result;
// If the query was executed, just call the listener
if (localResult != null) {
listener.queryExecuted(localResult);
} else {
execute... | java |
public static current_timezone get(nitro_service client) throws Exception
{
current_timezone resource = new current_timezone();
resource.validate("get");
return ((current_timezone[]) resource.get_resources(client))[0];
} | java |
public static mps_network_config get(nitro_service client) throws Exception
{
mps_network_config resource = new mps_network_config();
resource.validate("get");
return ((mps_network_config[]) resource.get_resources(client))[0];
} | java |
@Override
@SuppressWarnings("unchecked")
public void visit(final Visitable visitable) {
if (visitable instanceof Identifiable) {
((Identifiable) visitable).setId(null);
}
} | java |
@Override
public int compare(final Orderable<T> orderable1, final Orderable<T> orderable2) {
return orderable1.getOrder().compareTo(orderable2.getOrder());
} | java |
public static xen_supplemental_pack install(nitro_service client, xen_supplemental_pack resource) throws Exception
{
return ((xen_supplemental_pack[]) resource.perform_operation(client, "install"))[0];
} | java |
public static jazz_license get(nitro_service client) throws Exception
{
jazz_license resource = new jazz_license();
resource.validate("get");
return ((jazz_license[]) resource.get_resources(client))[0];
} | java |
public static xen_hotfix apply(nitro_service client, xen_hotfix resource) throws Exception
{
return ((xen_hotfix[]) resource.perform_operation(client, "apply"))[0];
} | java |
public static String toInitialCase(String s) {
if (isBlank(s)) return s;
if (s.length() == 1) return s.toUpperCase();
return s.substring(0, 1).toUpperCase() + s.substring(1);
} | java |
public static String replicate(String s, int times) {
if (s==null) return null;
if (times <= 0 || s.length() == 0) return "";
StringBuilder b = new StringBuilder(s.length() * times);
for (int k = 1; k <= times; ++k) b.append(s);
return b.toString();
} | java |
public static String md5(String s) {
try {
MessageDigest md5 = MessageDigest.getInstance("MD5");
byte[] digest = md5.digest(s.getBytes(Charset.forName("UTF-8")));
StringBuilder buf = new StringBuilder(2 * digest.length);
for (byte oneByte : digest) {
... | java |
public static String percentageBar(double percentage) {
final char dot = '.';
final char mark = '#';
final int slots = 40;
StringBuilder bar = new StringBuilder(replicate(String.valueOf(dot), slots));
int numSlots = (int) (slots * percentage / 100.0);
for (int k =... | java |
public static final ChannelInitializer<Channel> httpServer(
final SimpleChannelInboundHandler<HttpRequest> handler) {
Preconditions.checkArgument(handler.isSharable());
return new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel channel) throws Exception {
... | java |
public static final ChannelInitializer<Channel> httpClient(
final SimpleChannelInboundHandler<HttpResponse> handler) {
return new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel channel) throws Exception {
ChannelPipeline pipeline = channel.pipeline();
... | java |
@NullSafe
public static boolean isBlocked(Thread thread) {
return (thread != null && Thread.State.BLOCKED.equals(thread.getState()));
} | java |
@NullSafe
public static boolean isNew(Thread thread) {
return (thread != null && Thread.State.NEW.equals(thread.getState()));
} | java |
@NullSafe
public static boolean isTimedWaiting(Thread thread) {
return (thread != null && Thread.State.TIMED_WAITING.equals(thread.getState()));
} | java |
@NullSafe
public static boolean isWaiting(Thread thread) {
return (thread != null && Thread.State.WAITING.equals(thread.getState()));
} | java |
@NullSafe
public static ClassLoader getContextClassLoader(Thread thread) {
return (thread != null ? thread.getContextClassLoader() : ThreadUtils.class.getClassLoader());
} | java |
@NullSafe
public static String getName(Thread thread) {
return (thread != null ? thread.getName() : null);
} | java |
@NullSafe
public static StackTraceElement[] getStackTrace(Thread thread) {
return (thread != null ? thread.getStackTrace() : new StackTraceElement[0]);
} | java |
@NullSafe
public static Thread.State getState(Thread thread) {
return (thread != null ? thread.getState() : null);
} | java |
@NullSafe
public static ThreadGroup getThreadGroup(Thread thread) {
return (thread != null ? thread.getThreadGroup() : null);
} | java |
@NullSafe
public static void interrupt(Thread thread) {
Optional.ofNullable(thread).ifPresent(Thread::interrupt);
} | java |
@NullSafe
public static boolean join(Thread thread, long milliseconds, int nanoseconds) {
try {
if (thread != null) {
thread.join(milliseconds, nanoseconds);
return true;
}
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
return false;
} | java |
public static boolean sleep(long milliseconds, int nanoseconds) {
try {
Thread.sleep(milliseconds, nanoseconds);
return true;
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
return false;
}
} | java |
protected void runEchoService(ServerSocket serverSocket) {
if (isRunning(serverSocket)) {
echoService = newExecutorService();
echoService.submit(() -> {
try {
while (isRunning(serverSocket)) {
Socket echoClient = serverSocket.accept();
getLogger().info(() -> ... | java |
protected boolean stopEchoService() {
return Optional.ofNullable(getEchoService()).map(localEchoService -> {
localEchoService.shutdown();
try {
if (!localEchoService.awaitTermination(30, TimeUnit.SECONDS)) {
localEchoService.shutdownNow();
if (!localEchoService.awaitTermin... | java |
public static ns reboot(nitro_service client, ns resource) throws Exception
{
return ((ns[]) resource.perform_operation(client, "reboot"))[0];
} | java |
public static ns stop(nitro_service client, ns resource) throws Exception
{
return ((ns[]) resource.perform_operation(client, "stop"))[0];
} | java |
public static ns force_reboot(nitro_service client, ns resource) throws Exception
{
return ((ns[]) resource.perform_operation(client, "force_reboot"))[0];
} | java |
public static ns force_stop(nitro_service client, ns resource) throws Exception
{
return ((ns[]) resource.perform_operation(client, "force_stop"))[0];
} | java |
public static ns start(nitro_service client, ns resource) throws Exception
{
return ((ns[]) resource.perform_operation(client, "start"))[0];
} | java |
public static ns[] get_filtered(nitro_service service, filtervalue[] filter) throws Exception
{
ns obj = new ns();
options option = new options();
option.set_filter(filter);
ns[] response = (ns[]) obj.getfiltered(service, option);
return response;
} | java |
public void put(ElementType x) {
if (full()) {
getIdx = (getIdx + 1) % elements.length;
} else {
size++;
}
elements[putIdx] = x;
putIdx = (putIdx + 1) % elements.length;
} | java |
public ElementType get() {
if (empty()) throw new IllegalArgumentException("Empty queue");
ElementType x = (ElementType) elements[getIdx];
getIdx = (getIdx + 1) % elements.length;
size--;
return x;
} | java |
public Iterator<ElementType> iterator() {
return new Iterator<ElementType>() {
int idx = getIdx;
int N = size;
public boolean hasNext() {
return N > 0;
}
public ElementType next() {
ElementType x = (ElementType) elemen... | java |
public List<ElementType> toList() {
List<ElementType> result = new ArrayList<ElementType>(size());
for (ElementType e : this) result.add(e);
return result;
} | java |
protected <T> T defaultIfNotSet(String propertyName, T defaultValue, Class<T> type) {
return (isSet(propertyName) ? convert(propertyName, type) : defaultValue);
} | java |
public PropertiesAdapter filter(Filter<String> filter) {
Properties properties = new Properties();
for (String propertyName : this) {
if (filter.accept(propertyName)) {
properties.setProperty(propertyName, get(propertyName));
}
}
return from(properties);
} | java |
public static mail_profile get(nitro_service client, mail_profile resource) throws Exception
{
resource.validate("get");
return ((mail_profile[]) resource.get_resources(client))[0];
} | java |
@Override
public int compare(final TimeUnit timeUnitOne, final TimeUnit timeUnitTwo) {
return Integer.valueOf(String.valueOf(TIME_UNIT_VALUE.get(timeUnitOne))).compareTo(
TIME_UNIT_VALUE.get(timeUnitTwo));
} | java |
@NullSafe
public static Class[] getArgumentTypes(Object... arguments) {
Class[] argumentTypes = null;
if (arguments != null) {
argumentTypes = new Class[arguments.length];
for (int index = 0; index < arguments.length; index++) {
argumentTypes[index] = getClass(arguments[index]);
}
... | java |
public static final long nextPermutation(long val) {
long tmp = val | (val - 1);
return (tmp + 1) | (((-tmp & -~tmp) - 1) >> (Long.numberOfTrailingZeros(val) + 1));
} | java |
public static final int[] getBitsSet(final long val) {
long tmp = val;
int[] retVal = new int[Long.bitCount(val)];
for (int i = 0; i < retVal.length; i++) {
retVal[i] = Long.numberOfTrailingZeros(tmp);
tmp = tmp ^ Long.lowestOneBit(tmp);
}
return retVal;
} | java |
@Override
@SuppressWarnings("unchecked")
public <E> E[] sort(final E... elements) {
return (E[]) sort(new SortableArrayList(elements)).toArray(
(E[]) Array.newInstance(elements.getClass().getComponentType(), elements.length));
} | java |
@Override
public <E> List<E> sort(final List<E> elements) {
if (elements.size() > 1) {
int size = elements.size();
int count = ((size / 2) + (size % 2));
List<E> leftElements = sort(elements.subList(0, count));
List<E> rightElements = sort(elements.subList(count, size));
return mer... | java |
public static Metadata fromPomProperties(InputStream is) {
Metadata metadata = new Metadata();
BufferedReader input = new BufferedReader(new InputStreamReader(is));
try {
String line;
while ((line = input.readLine()) != null) {
if (line.startsWith("#"))
... | java |
public static Metadata fromManifest(InputStream is) {
try {
Manifest mf = new Manifest(is);
return fromManifest(mf);
} catch (IOException e) {
// Problems? Too bad!
}
return new Metadata();
} | java |
public static af_persistant_stat_info[] get_filtered(nitro_service service, filtervalue[] filter) throws Exception
{
af_persistant_stat_info obj = new af_persistant_stat_info();
options option = new options();
option.set_filter(filter);
af_persistant_stat_info[] response = (af_persistant_stat_info[]) obj.... | java |
@SuppressWarnings("unchecked")
public <T extends VALUE> T withCaching(KEY key, Supplier<VALUE> cacheableOperation) {
Assert.notNull(key, "Key is required");
Assert.notNull(cacheableOperation, "Supplier is required");
ReadWriteLock lock = getLock();
return (T) Optional.ofNullable(read(lock, key)).or... | java |
public static syslog_server[] get_filtered(nitro_service service, filtervalue[] filter) throws Exception
{
syslog_server obj = new syslog_server();
options option = new options();
option.set_filter(filter);
syslog_server[] response = (syslog_server[]) obj.getfiltered(service, option);
return response;
... | java |
public Object string_to_resource(Class<?> responseClass, String response)
{
try
{
Gson gson = new Gson();
return gson.fromJson(response, responseClass);
}catch(Exception e)
{
System.out.println(e.getMessage());
}
return null;
} | java |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.