code stringlengths 73 34.1k | label stringclasses 1
value |
|---|---|
public String getString(String key, String defaultValue) {
Object o = getObject(key);
if (o == null) {
return defaultValue;
}
if (!(o instanceof String)) {
throw new IllegalArgumentException("Object ["+o+"] associated with key ["+key+"] is not of type String.");
}
return (String)o;
} | java |
public boolean getBoolean(String key, boolean defaultValue) {
Object o = getObject(key);
if (o == null) {
return defaultValue;
}
boolean b = defaultValue;
try {
b = Boolean.parseBoolean(o.toString());
}
catch (Exception e) {
throw new IllegalArgumentException("Object ["+o+"] associated ... | java |
public int getInteger(String key, int defaultValue) {
Object o = getObject(key);
if (o == null) {
return defaultValue;
}
int val = defaultValue;
try {
val = Integer.parseInt(o.toString());
}
catch (Exception e) {
throw new IllegalArgumentException("Object ["+o+"] associated with key ["+... | java |
public static InvocationHandler defaultMethodHandler() {
return (proxy, method, args) -> {
if (method.isDefault()) {
return MethodHandles.lookup()
.in(method.getDeclaringClass())
.unreflectSpecial(method, method.getDeclaringClass())
.bindTo(proxy)
.invok... | java |
@SuppressWarnings("unchecked")
public <E extends T> T[] concat(T[] oldArray, E newElement) {
T[] arr = (T[]) Array.newInstance(type, oldArray.length + 1);
System.arraycopy(oldArray, 0, arr, 0, oldArray.length);
arr[oldArray.length] = newElement;
return arr;
} | java |
@Override
@SuppressWarnings("unchecked")
protected T convert(JsonNode data) {
// The (T) cast prevents the commandline javac from choking "no unique maximal instance"
return (T)this.mapper.convertValue(data, this.resultType);
} | java |
@SuppressWarnings("unchecked")
public Object runKeyword(String keyword, final Object[] params) {
Map attributes = new HashMap();
attributes.put("args", params);
try {
ApplicationContextHolder.set(context);
startJSpringBotKeyword(keyword, attributes);
Obj... | java |
public static String getAppAccessToken(String clientId, String clientSecret) {
return getAccessToken(clientId, clientSecret, null, null);
} | java |
@Override
public void execute() {
if (this.batches.isEmpty())
return;
// Reset the collection before making the call to eliminate callback chatter when
// the batches call back to the master.
List<Batch> old = this.batches;
// Reset our batches
this.batches = new ArrayList<Batch>();
t... | java |
private Batch getBatchForGraph() {
Batch lastValidBatch = this.batches.isEmpty() ? null : this.batches.get(this.batches.size()-1);
if (lastValidBatch != null && lastValidBatch.graphSize() < this.maxBatchSize)
return lastValidBatch;
else {
Batch next = new Batch(this, this.mapper, this.accessToken, ... | java |
public static SmartBinder from(Signature inbound) {
return new SmartBinder(inbound, Binder.from(inbound.type()));
} | java |
public static SmartBinder from(Class<?> retType, String[] names, Class<?>... types) {
return from(Signature.returning(retType).appendArgs(names, types));
} | java |
public static SmartBinder from(Class<?> retType, String name, Class<?> type) {
return from(Signature.returning(retType).appendArg(name, type));
} | java |
public static SmartBinder from(Lookup lookup, Signature inbound) {
return new SmartBinder(inbound, Binder.from(lookup, inbound.type()));
} | java |
public SmartBinder foldVoid(SmartHandle function) {
if (Arrays.equals(signature().argNames(), function.signature().argNames())) {
return foldVoid(function.handle());
} else {
return foldVoid(signature().asFold(void.class).permuteWith(function).handle());
}
} | java |
public SmartBinder foldStatic(String newName, Lookup lookup, Class<?> target, String method) {
Binder newBinder = binder.foldStatic(lookup, target, method);
return new SmartBinder(this, signature().prependArg(newName, newBinder.type().parameterType(0)), binder);
} | java |
public SmartBinder foldVirtual(String newName, Lookup lookup, String method) {
Binder newBinder = binder.foldVirtual(lookup, method);
return new SmartBinder(this, signature().prependArg(newName, newBinder.type().parameterType(0)), newBinder);
} | java |
public SmartBinder permute(Signature target) {
return new SmartBinder(this, target, binder.permute(signature().to(target)));
} | java |
public SmartBinder spread(String[] spreadNames, Class<?>... spreadTypes) {
return new SmartBinder(this, signature().spread(spreadNames, spreadTypes), binder.spread(spreadTypes));
} | java |
public SmartBinder spread(String baseName, int count) {
return new SmartBinder(this, signature().spread(baseName, count), binder.spread(count));
} | java |
public SmartBinder insert(int index, String[] names, Class<?>[] types, Object... values) {
return new SmartBinder(this, signature().insertArgs(index, names, types), binder.insert(index, types, values));
} | java |
public SmartBinder append(String[] names, Class<?>[] types, Object... values) {
return new SmartBinder(this, signature().appendArgs(names, types), binder.append(types, values));
} | java |
public SmartBinder prepend(String[] names, Class<?>[] types, Object... values) {
return new SmartBinder(this, signature().prependArgs(names, types), binder.prepend(types, values));
} | java |
public SmartBinder drop(String name) {
int index = signature().argOffset(name);
return new SmartBinder(this, signature().dropArg(index), binder.drop(index));
} | java |
public SmartBinder dropLast(int count) {
return new SmartBinder(this, signature().dropLast(count), binder.dropLast(count));
} | java |
public SmartBinder dropFirst(int count) {
return new SmartBinder(this, signature().dropFirst(count), binder.dropFirst(count));
} | java |
public SmartBinder collect(String outName, String namePattern) {
int index = signature().argOffsets(namePattern);
assert index >= 0 : "no arguments matching " + namePattern + " found in signature " + signature();
Signature newSignature = signature().collect(outName, namePattern);
retu... | java |
public SmartBinder cast(Signature target) {
return new SmartBinder(target, binder.cast(target.type()));
} | java |
public SmartBinder cast(Class<?> returnType, Class<?>... argTypes) {
return new SmartBinder(this, new Signature(returnType, argTypes, signature().argNames()), binder.cast(returnType, argTypes));
} | java |
public SmartBinder castVirtual(Class<?> returnType, Class<?> firstArg, Class<?>... restArgs) {
return new SmartBinder(this, new Signature(returnType, firstArg, restArgs, signature().argNames()), binder.castVirtual(returnType, firstArg, restArgs));
} | java |
public SmartBinder castArg(String name, Class<?> type) {
Signature newSig = signature().replaceArg(name, name, type);
return new SmartBinder(this, newSig, binder.cast(newSig.type()));
} | java |
public SmartBinder castReturn(Class<?> type) {
return new SmartBinder(this, signature().changeReturn(type), binder.cast(type, binder.type().parameterArray()));
} | java |
public SmartHandle invokeVirtual(Lookup lookup, String name) throws NoSuchMethodException, IllegalAccessException {
return new SmartHandle(start, binder.invokeVirtual(lookup, name));
} | java |
public SmartHandle invokeStatic(Lookup lookup, Class<?> target, String name) throws NoSuchMethodException, IllegalAccessException {
return new SmartHandle(start, binder.invokeStatic(lookup, target, name));
} | java |
public SmartHandle invoke(SmartHandle target) {
return new SmartHandle(start, binder.invoke(target.handle()));
} | java |
public SmartBinder filter(String pattern, MethodHandle filter) {
String[] argNames = signature().argNames();
Pattern pat = Pattern.compile(pattern);
Binder newBinder = binder();
Signature newSig = signature();
for (int i = 0; i < argNames.length; i++) {
if (pat.match... | java |
public static Signature from(Class<?> retval, Class<?>[] argTypes, String... argNames) {
assert argTypes.length == argNames.length;
return new Signature(retval, argTypes, argNames);
} | java |
public Signature dropArg(String name) {
String[] newArgNames = new String[argNames.length - 1];
MethodType newType = methodType;
for (int i = 0, j = 0; i < argNames.length; i++) {
if (argNames[i].equals(name)) {
newType = newType.dropParameterTypes(j, j + 1);
... | java |
public Signature dropArg(int index) {
assert index < argNames.length;
String[] newArgNames = new String[argNames.length - 1];
if (index > 0) System.arraycopy(argNames, 0, newArgNames, 0, index);
if (index < argNames.length - 1)
System.arraycopy(argNames, index + 1, newArgNam... | java |
public Signature dropLast(int n) {
return new Signature(
methodType.dropParameterTypes(methodType.parameterCount() - n, methodType.parameterCount()),
Arrays.copyOfRange(argNames, 0, argNames.length - n));
} | java |
public Signature dropFirst(int n) {
return new Signature(
methodType.dropParameterTypes(0, n),
Arrays.copyOfRange(argNames, n, argNames.length));
} | java |
public Signature replaceArg(String oldName, String newName, Class<?> newType) {
int offset = argOffset(oldName);
String[] newArgNames = argNames;
if (!oldName.equals(newName)) {
newArgNames = Arrays.copyOf(argNames, argNames.length);
newArgNames[offset] = newName;
... | java |
public Signature collect(String newName, String oldPattern) {
int start = -1;
int newCount = 0;
int gatherCount = 0;
Class<?> type = null;
Pattern pattern = Pattern.compile(oldPattern);
MethodType newType = type();
for (int i = 0; i < argNames.length; i++) {
... | java |
public Signature argName(int index, String name) {
String[] argNames = Arrays.copyOf(argNames(), argNames().length);
argNames[index] = name;
return new Signature(type(), argNames);
} | java |
public Signature argType(int index, Class<?> type) {
return new Signature(type().changeParameterType(index, type), argNames());
} | java |
public MethodHandle permuteWith(MethodHandle target, String... permuteArgs) {
return MethodHandles.permuteArguments(target, methodType, to(permute(permuteArgs)));
} | java |
public SmartHandle permuteWith(SmartHandle target) {
String[] argNames = target.signature().argNames();
return new SmartHandle(this, permuteWith(target.handle(), argNames));
} | java |
public static <E> Stream<E> streamUntil(Supplier<? extends E> supplier, Predicate<? super E> stop) {
Iterator<E> iterator = AltIterators.iterateUntil(supplier, stop);
Spliterator<E> spliterator = Spliterators.spliterator(iterator, Long.MAX_VALUE, Spliterator.ORDERED);
return StreamSupport.stream(spliterato... | java |
public static int find(int[] arr, int start, int end, int valueToFind) {
assert arr != null;
assert end >= 0;
assert end <= arr.length;
for (int i = start; i < end; i++) {
if (arr[i] == valueToFind) {
return i;
}
}
return NOT_FOUND;
} | java |
public static int find(Object[] arr, int start, int end, Object valueToFind) {
assert arr != null;
assert end >= 0;
assert end <= arr.length;
for (int i = start; i < end; i++) {
if (Objects.equals(arr[i], valueToFind)) {
return i;
}
}
return NOT_FOUND;
} | java |
public static <T> Mutator<T> mutate(T t) {
Objects.requireNonNull(t);
return new Mutator<>(t);
} | java |
private HttpResponse executeOnce(RequestSetup setup) throws IOException {
DefaultRequestDefinition req = new DefaultRequestDefinition();
setup.setup(req);
HttpResponse response = req.execute();
// This will force the request to complete, causing any timeout exceptions to happen here
response.getR... | java |
protected static void buildClassArguments(StringBuilder builder, Class<?>[] types) {
boolean second = false;
for (Class cls : types) {
if (second) builder.append(", ");
second = true;
buildClassArgument(builder, cls);
}
} | java |
protected static void buildClassArgument(StringBuilder builder, Class cls) {
buildClass(builder, cls);
builder.append(".class");
} | java |
protected static void buildClassCast(StringBuilder builder, Class cls) {
builder.append('(');
buildClass(builder, cls);
builder.append(')');
} | java |
protected static void buildPrimitiveJava(StringBuilder builder, Object value) {
builder.append(value.toString());
if (value.getClass() == Float.class) builder.append('F');
if (value.getClass() == Long.class) builder.append('L');
} | java |
private static void buildClass(StringBuilder builder, Class cls) {
int arrayDims = 0;
Class tmp = cls;
while (tmp.isArray()) {
arrayDims++;
tmp = tmp.getComponentType();
}
builder.append(tmp.getName());
if (arrayDims > 0) {
for (; array... | java |
public static String generateMethodType(MethodType source) {
StringBuilder builder = new StringBuilder("MethodType.methodType(");
buildClassArgument(builder, source.returnType());
if (source.parameterCount() > 0) {
builder.append(", ");
buildClassArguments(builder, source... | java |
protected HttpResponse execute(final HttpMethod meth, String postURL) throws IOException {
final String url = (meth == HttpMethod.POST) ? postURL : this.toString();
if (log.isLoggable(Level.FINER))
log.finer(meth + "ing: " + url);
return RequestExecutor.instance().execute(this.retries, new RequestSetup... | java |
protected String createQueryString() {
assert !this.hasBinaryAttachments;
if (this.params.isEmpty())
return "";
StringBuilder bld = null;
for (Map.Entry<String, Object> param: this.params.entrySet()) {
if (bld == null)
bld = new StringBuilder();
else
bld.append('&');
... | java |
public static FacebookCookie decode(String cookie, String appSecret)
{
// Parsing and verifying signature seems to be poorly documented, but here's what I've found:
// Look at parseSignedRequest() in https://github.com/facebook/php-sdk/blob/master/src/base_facebook.php
// Python version: https://developers.... | java |
public static Map<String, String> getKeywordMap(ApplicationContext context) {
Map<String, String> keywordToBeanMap = new HashMap<String, String>();
// Retrieve beans implementing the Keyword interface.
String[] beanNames = context.getBeanNamesForType(Keyword.class);
for (String beanNam... | java |
public static String getDescription(String keyword, ApplicationContext context, Map<String, String> beanMap) {
KeywordInfo keywordInfo = getKeywordInfo(keyword, context, beanMap);
if(keywordInfo == null) {
return "";
}
String desc = keywordInfo.description();
if(de... | java |
public static String[] getParameters(String keyword, ApplicationContext context, Map<String, String> beanMap) {
KeywordInfo keywordInfo = getKeywordInfo(keyword, context, beanMap);
return keywordInfo == null ? DEFAULT_PARAMS : keywordInfo.parameters();
} | java |
public static KeywordInfo getKeywordInfo(String keyword, ApplicationContext context, Map<String, String> beanMap) {
Object bean = context.getBean(beanMap.get(keyword));
return AnnotationUtils.findAnnotation(bean.getClass(), KeywordInfo.class);
} | java |
@Override
@JsonIgnore
protected Param[] getParams() {
Map<String, String> queries = new LinkedHashMap<String, String>();
for (QueryRequest<?> req: this.queryRequests)
queries.put(req.getName(), req.getFQL());
String json = JSONUtils.toJSON(queries, this.mapper);
return new Param[] { new Param("querie... | java |
@JsonProperty("relative_url")
public String getRelativeURL() {
StringBuilder bld = new StringBuilder();
bld.append(this.object);
Param[] params = this.getParams();
if (params != null && params.length > 0) {
bld.append('?');
boolean afterFirst = false;
for (Param param: params) {
if (afte... | java |
public static SmartHandle findStaticQuiet(Lookup lookup, Class<?> target, String name, Signature signature) {
try {
return new SmartHandle(signature, lookup.findStatic(target, name, signature.type()));
} catch (NoSuchMethodException | IllegalAccessException e) {
throw new Runtime... | java |
public SmartHandle drop(String beforeName, String newName, Class<?> type) {
return new SmartHandle(signature.insertArg(beforeName, newName, type), MethodHandles.dropArguments(handle, signature.argOffset(beforeName), type));
} | java |
public SmartHandle drop(int index, String newName, Class<?> type) {
return new SmartHandle(signature.insertArg(index, newName, type), MethodHandles.dropArguments(handle, index, type));
} | java |
public SmartHandle dropLast(String newName, Class<?> type) {
return new SmartHandle(signature.appendArg(newName, type), MethodHandles.dropArguments(handle, signature.argOffset(newName), type));
} | java |
public SmartHandle bindTo(Object obj) {
return new SmartHandle(signature.dropFirst(), handle.bindTo(obj));
} | java |
public SmartHandle returnValue(Class<?> type, Object value) {
return new SmartHandle(signature.changeReturn(type), MethodHandles.filterReturnValue(handle, MethodHandles.constant(type, value)));
} | java |
public static String toJSON(Object value, ObjectMapper mapper) {
try {
return mapper.writeValueAsString(value);
} catch (IOException ex) {
throw new FacebookException(ex);
}
} | java |
public static JsonNode toNode(String value, ObjectMapper mapper) {
try {
return mapper.readTree(value);
} catch (IOException ex) {
throw new FacebookException(ex);
}
} | java |
public static String stringifyValue(Param param, ObjectMapper mapper) {
assert !(param instanceof BinaryParam);
if (param.value instanceof String)
return (String)param.value;
if (param.value instanceof Date)
return Long.toString(((Date)param.value).getTime() / 1000);
else if (param.value instanc... | java |
public static String read(InputStream input) {
try {
StringBuilder bld = new StringBuilder();
Reader reader = new InputStreamReader(input, "utf-8");
int ch;
while ((ch = reader.read()) >= 0)
bld.append((char)ch);
return bld.toString();
} catch (IOException ex) {
throw new Runtime... | java |
public static Binder from(MethodHandles.Lookup lookup, Binder start) {
return new Binder(lookup, start);
} | java |
public Binder to(Binder other) {
assert type().equals(other.start);
Binder newBinder = new Binder(this);
for (ListIterator<Transform> iter = other.transforms.listIterator(other.transforms.size()); iter.hasPrevious(); ) {
Transform t = iter.previous();
newBinder.add(t);
... | java |
private void add(Transform transform, MethodType target) {
types.add(0, target);
transforms.add(0, transform);
} | java |
public Binder insert(int index, Class<?> type, Object value) {
return new Binder(this, new Insert(index, new Class[]{type}, value));
} | java |
public Binder append(Class<?> type, Object value) {
return new Binder(this, new Insert(type().parameterCount(), new Class[]{type}, value));
} | java |
public Binder append(Class<?>[] types, Object... values) {
return new Binder(this, new Insert(type().parameterCount(), types, values));
} | java |
public Binder prepend(Class<?> type, Object value) {
return new Binder(this, new Insert(0, new Class[]{type}, value));
} | java |
public Binder prepend(Class<?>[] types, Object... values) {
return new Binder(this, new Insert(0, types, values));
} | java |
public Binder drop(int index, int count) {
return new Binder(this, new Drop(index, Arrays.copyOfRange(type().parameterArray(), index, index + count)));
} | java |
public Binder dropLast(int count) {
assert count <= type().parameterCount();
return drop(type().parameterCount() - count, count);
} | java |
public Binder spread(Class<?>... spreadTypes) {
if (spreadTypes.length == 0) {
return dropLast();
}
return new Binder(this, new Spread(type(), spreadTypes));
} | java |
public Binder spread(int count) {
if (count == 0) {
return dropLast();
}
Class<?> aryType = type().parameterType(type().parameterCount() - 1);
assert aryType.isArray();
Class<?>[] spreadTypes = new Class[count];
Arrays.fill(spreadTypes, aryType.getComponent... | java |
public Binder collect(int index, Class<?> type) {
return new Binder(this, new Collect(type(), index, type));
} | java |
public Binder varargs(int index, Class<?> type) {
return new Binder(this, new Varargs(type(), index, type));
} | java |
public Binder foldVoid(MethodHandle function) {
if (type().returnType() == void.class) {
return fold(function);
} else {
return fold(function.asType(function.type().changeReturnType(void.class)));
}
} | java |
public Binder foldVirtual(MethodHandles.Lookup lookup, String method) {
return fold(Binder.from(type()).invokeVirtualQuiet(lookup, method));
} | java |
public Binder filterForward(int index, MethodHandle... functions) {
Binder filtered = this;
for (int i = 0; i < functions.length; i++) {
filtered = filtered.filter(index + i, functions[i]);
}
return filtered;
} | java |
public Binder catchException(Class<? extends Throwable> throwable, MethodHandle function) {
return new Binder(this, new Catch(throwable, function));
} | java |
public MethodHandle nop() {
if (type().returnType() != void.class) {
throw new InvalidTransformException("must have void return type to nop: " + type());
}
return invoke(Binder
.from(type())
.drop(0, type().parameterCount())
.cast(Objec... | java |
public MethodHandle throwException() {
if (type().parameterCount() != 1 || !Throwable.class.isAssignableFrom(type().parameterType(0))) {
throw new InvalidTransformException("incoming signature must have one Throwable type as its sole argument: " + type());
}
return invoke(MethodHandl... | java |
public MethodHandle constant(Object value) {
return invoke(MethodHandles.constant(type().returnType(), value));
} | java |
public MethodHandle invoke(MethodHandle target) {
MethodHandle current = target;
for (Transform t : transforms) {
current = t.up(current);
}
// if resulting handle's type does not match start, attempt one more cast
current = MethodHandles.explicitCastArguments(curren... | java |
public MethodHandle arrayAccess(VarHandle.AccessMode mode) {
return invoke(MethodHandles.arrayElementVarHandle(type().parameterType(0)).toMethodHandle(mode));
} | java |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.