code stringlengths 73 34.1k | label stringclasses 1
value |
|---|---|
private void addTypes(Injector injector, List<Class<?>> types) {
for (Binding<?> binding : injector.getBindings().values()) {
Key<?> key = binding.getKey();
Type type = key.getTypeLiteral().getType();
if (hasAnnotatedMethods(type)) {
types.add(((Class<?>)type)... | java |
public void map(Story story, MetaFilter metaFilter) {
if (metaFilter.allow(story.getMeta())) {
boolean allowed = false;
for (Scenario scenario : story.getScenarios()) {
// scenario also inherits meta from story
Meta inherited = scenario.getMeta().inheritFr... | java |
protected MetaMatcher createMetaMatcher(String filterAsString, Map<String, MetaMatcher> metaMatchers) {
for ( String key : metaMatchers.keySet() ){
if ( filterAsString.startsWith(key)){
return metaMatchers.get(key);
}
}
if (filterAsString.startsWith(GROOVY)) {
return new... | java |
public static URL codeLocationFromClass(Class<?> codeLocationClass) {
String pathOfClass = codeLocationClass.getName().replace(".", "/") + ".class";
URL classResource = codeLocationClass.getClassLoader().getResource(pathOfClass);
String codeLocationPath = removeEnd(getPathFromURL(classResource),... | java |
public static URL codeLocationFromPath(String filePath) {
try {
return new File(filePath).toURI().toURL();
} catch (Exception e) {
throw new InvalidCodeLocation(filePath);
}
} | java |
public static URL codeLocationFromURL(String url) {
try {
return new URL(url);
} catch (Exception e) {
throw new InvalidCodeLocation(url);
}
} | java |
public void run(Configuration configuration, List<CandidateSteps> candidateSteps, Story story) throws Throwable {
run(configuration, candidateSteps, story, MetaFilter.EMPTY);
} | java |
public void run(Configuration configuration, List<CandidateSteps> candidateSteps, Story story, MetaFilter filter)
throws Throwable {
run(configuration, candidateSteps, story, filter, null);
} | java |
public void run(Configuration configuration, List<CandidateSteps> candidateSteps, Story story, MetaFilter filter,
State beforeStories) throws Throwable {
run(configuration, new ProvidedStepsFactory(candidateSteps), story, filter, beforeStories);
} | java |
public void run(Configuration configuration, InjectableStepsFactory stepsFactory, Story story, MetaFilter filter,
State beforeStories) throws Throwable {
RunContext context = new RunContext(configuration, stepsFactory, story.getPath(), filter);
if (beforeStories != null) {
contex... | java |
public Story storyOfPath(Configuration configuration, String storyPath) {
String storyAsText = configuration.storyLoader().loadStoryAsText(storyPath);
return configuration.storyParser().parseStory(storyAsText, storyPath);
} | java |
public Story storyOfText(Configuration configuration, String storyAsText, String storyId) {
return configuration.storyParser().parseStory(storyAsText, storyId);
} | java |
public Object newInstance(String className) {
try {
return classLoader.loadClass(className).newInstance();
} catch (Exception e) {
throw new ScalaInstanceNotFound(className);
}
} | java |
@Override
public Map<String, String> values() {
Map<String, String> values = new LinkedHashMap<>();
for (Row each : delegates) {
for (Entry<String, String> entry : each.values().entrySet()) {
String name = entry.getKey();
if (!values.containsKey(name)) {
... | java |
public List<Object> stepsInstances(List<CandidateSteps> candidateSteps) {
List<Object> instances = new ArrayList<>();
for (CandidateSteps steps : candidateSteps) {
if (steps instanceof Steps) {
instances.add(((Steps) steps).instance());
}
}
return ... | java |
public List<StepCandidate> prioritise(String stepAsText, List<StepCandidate> candidates) {
return prioritisingStrategy.prioritise(stepAsText, candidates);
} | java |
protected String format(String key, String defaultPattern, Object... args) {
String escape = escape(defaultPattern);
String s = lookupPattern(key, escape);
Object[] objects = escapeAll(args);
return MessageFormat.format(s, objects);
} | java |
protected Object[] escape(final Format format, Object... args) {
// Transformer that escapes HTML,XML,JSON strings
Transformer<Object, Object> escapingTransformer = new Transformer<Object, Object>() {
@Override
public Object transform(Object object) {
return forma... | java |
protected void print(String text) {
String tableStart = format(PARAMETER_TABLE_START, PARAMETER_TABLE_START);
String tableEnd = format(PARAMETER_TABLE_END, PARAMETER_TABLE_END);
boolean containsTable = text.contains(tableStart) && text.contains(tableEnd);
String textToPrint = containsTab... | java |
private List<ParameterConverter> methodReturningConverters(final Class<?> type) {
final List<ParameterConverter> converters = new ArrayList<>();
for (final Method method : type.getMethods()) {
if (method.isAnnotationPresent(AsParameterConverter.class)) {
converters.add(new Me... | java |
static InjectionProvider<?>[] toArray(final Set<InjectionProvider<?>> injectionProviders) {
return injectionProviders.toArray(new InjectionProvider<?>[injectionProviders.size()]);
} | java |
@AsParameterConverter
public Trader retrieveTrader(String name) {
for (Trader trader : traders) {
if (trader.getName().equals(name)) {
return trader;
}
}
return mockTradePersister().retrieveTrader(name);
} | java |
private Class<?> beanType(String name) {
Class<?> type = context.getType(name);
if (ClassUtils.isCglibProxyClass(type)) {
return AopProxyUtils.ultimateTargetClass(context.getBean(name));
}
return type;
} | java |
private boolean findBinding(Injector injector, Class<?> type) {
boolean found = false;
for (Key<?> key : injector.getBindings().keySet()) {
if (key.getTypeLiteral().getRawType().equals(type)) {
found = true;
break;
}
}
if (!found &&... | java |
public List<String> scan() {
try {
JarFile jar = new JarFile(jarURL.getFile());
try {
List<String> result = new ArrayList<>();
Enumeration<JarEntry> en = jar.entries();
while (en.hasMoreElements()) {
JarEntry entry = en.... | java |
public String getMethodSignature() {
if (method != null) {
String methodSignature = method.toString();
return methodSignature.replaceFirst("public void ", "");
}
return null;
} | java |
@Override
public Configuration configuration() {
return new MostUsefulConfiguration()
// where to find the stories
.useStoryLoader(new LoadFromClasspath(this.getClass()))
// CONSOLE and TXT reporting
.useStoryReporterBuilder(new StoryReporterBuilder().withDe... | java |
public GetAssignmentGroupOptions includes(List<Include> includes) {
List<Include> assignmentDependents = Arrays.asList(Include.DISCUSSION_TOPIC, Include.ASSIGNMENT_VISIBILITY, Include.SUBMISSION);
if(includes.stream().anyMatch(assignmentDependents::contains) && !includes.contains(Include.ASSIGNMENTS)) {... | java |
private void ensureToolValidForCreation(ExternalTool tool) {
//check for the unconditionally required fields
if(StringUtils.isAnyBlank(tool.getName(), tool.getPrivacyLevel(), tool.getConsumerKey(), tool.getSharedSecret())) {
throw new IllegalArgumentException("External tool requires all of t... | java |
public GetSingleConversationOptions filters(List<String> filters) {
if(filters.size() == 1) { //Canvas API doesn't want the [] if it is only one value
addSingleItem("filter", filters.get(0));
} else {
optionsMap.put("filter[]", filters);
}
return this;
} | java |
public <T extends CanvasReader> T getReader(Class<T> type, OauthToken oauthToken) {
return getReader(type, oauthToken, null);
} | java |
public <T extends CanvasReader> T getReader(Class<T> type, OauthToken oauthToken, Integer paginationPageSize) {
LOG.debug("Factory call to instantiate class: " + type.getName());
RestClient restClient = new RefreshingRestClient();
@SuppressWarnings("unchecked")
Class<T> concreteClass = ... | java |
public <T extends CanvasWriter> T getWriter(Class<T> type, OauthToken oauthToken) {
return getWriter(type, oauthToken, false);
} | java |
public <T extends CanvasWriter> T getWriter(Class<T> type, OauthToken oauthToken, Boolean serializeNulls) {
LOG.debug("Factory call to instantiate class: " + type.getName());
RestClient restClient = new RefreshingRestClient();
@SuppressWarnings("unchecked")
Class<T> concreteClass = (Cla... | java |
public ListActiveCoursesInAccountOptions searchTerm(String searchTerm) {
if(searchTerm == null || searchTerm.length() < 3) {
throw new IllegalArgumentException("Search term must be at least 3 characters");
}
addSingleItem("search_term", searchTerm);
return this;
} | java |
public ListExternalToolsOptions searchTerm(String searchTerm) {
if(searchTerm == null || searchTerm.length() < 3) {
throw new IllegalArgumentException("Search term must be at least 3 characters");
}
addSingleItem("search_term", searchTerm);
return this;
} | java |
private List<EnrollmentTerm> parseEnrollmentTermList(final List<Response> responses) {
return responses.stream().
map(this::parseEnrollmentTermList).
flatMap(Collection::stream).
collect(Collectors.toList());
} | java |
private Response sendJsonPostOrPut(OauthToken token, String url, String json,
int connectTimeout, int readTimeout, String method) throws IOException {
LOG.debug("Sending JSON " + method + " to URL: " + url);
Response response = new Response();
HttpClient h... | java |
protected void addEnumList(String key, List<? extends Enum> list) {
optionsMap.put(key, list.stream().map(i -> i.toString()).collect(Collectors.toList()));
} | java |
public void setLargePayloadSupportEnabled(AmazonS3 s3, String s3BucketName) {
if (s3 == null || s3BucketName == null) {
String errorMessage = "S3 client and/or S3 bucket name cannot be null.";
LOG.error(errorMessage);
throw new AmazonClientException(errorMessage);
}
if (isLargePayloadSupportEnabled()) {
... | java |
private String readLine(boolean trim) throws IOException {
boolean done = false;
boolean sawCarriage = false;
// bytes to trim (the \r and the \n)
int removalBytes = 0;
while (!done) {
if (isReadBufferEmpty()) {
offset = 0;
end = 0;
int bytesRead = inputStream.read(buff... | java |
private void copyToStrBuffer(byte[] buffer, int offset, int length) {
Preconditions.checkArgument(length >= 0);
if (strBuffer.length - strBufferIndex < length) {
// cannot fit, expanding buffer
expandStrBuffer(length);
}
System.arraycopy(
buffer, offset, strBuffer, strBufferIndex, Math... | java |
public String read(int numBytes) throws IOException {
Preconditions.checkArgument(numBytes >= 0);
Preconditions.checkArgument(numBytes <= MAX_ALLOWABLE_BUFFER_SIZE);
int numBytesRemaining = numBytes;
// first read whatever we need from our buffer
if (!isReadBufferEmpty()) {
int length = Math.m... | java |
public DefaultStreamingEndpoint languages(List<String> languages) {
addPostParameter(Constants.LANGUAGE_PARAM, Joiner.on(',').join(languages));
return this;
} | java |
@Override
public void process() {
if (client.isDone() || executorService.isTerminated()) {
throw new IllegalStateException("Client is already stopped");
}
Runnable runner = new Runnable() {
@Override
public void run() {
try {
while (!client.isDone()) {
Strin... | java |
public void stop(int waitMillis) throws InterruptedException {
try {
if (!isDone()) {
setExitStatus(new Event(EventType.STOPPED_BY_USER, String.format("Stopped by user: waiting for %d ms", waitMillis)));
}
if (!waitForFinish(waitMillis)) {
logger.warn("{} Client thread failed to fi... | java |
public void fireEvent(final WorkerEvent event, final Worker worker, final String queue, final Job job,
final Object runner, final Object result, final Throwable t) {
final ConcurrentSet<WorkerListener> listeners = this.eventListenerMap.get(event);
if (listeners != null) {
for (f... | java |
public static List<String> createBacktrace(final Throwable t) {
final List<String> bTrace = new LinkedList<String>();
for (final StackTraceElement ste : t.getStackTrace()) {
bTrace.add(BT_PREFIX + ste.toString());
}
if (t.getCause() != null) {
addCauseToBacktrace(... | java |
private static void addCauseToBacktrace(final Throwable cause, final List<String> bTrace) {
if (cause.getMessage() == null) {
bTrace.add(BT_CAUSED_BY_PREFIX + cause.getClass().getName());
} else {
bTrace.add(BT_CAUSED_BY_PREFIX + cause.getClass().getName() + ": " + cause.getMessa... | java |
@SafeVarargs
public static <K, V> Map<K, V> map(final Entry<? extends K, ? extends V>... entries) {
final Map<K, V> map = new LinkedHashMap<K, V>(entries.length);
for (final Entry<? extends K, ? extends V> entry : entries) {
map.put(entry.getKey(), entry.getValue());
}
re... | java |
@SafeVarargs
public static <K> Set<K> set(final K... keys) {
return new LinkedHashSet<K>(Arrays.asList(keys));
} | java |
public static boolean nullSafeEquals(final Object obj1, final Object obj2) {
return ((obj1 == null && obj2 == null)
|| (obj1 != null && obj2 != null && obj1.equals(obj2)));
} | java |
private long size(final Jedis jedis, final String queueName) {
final String key = key(QUEUE, queueName);
final long size;
if (JedisUtils.isDelayedQueue(jedis, key)) { // If delayed queue, use ZCARD
size = jedis.zcard(key);
} else { // Else, use LLEN
size = jedis.l... | java |
private List<Job> getJobs(final Jedis jedis, final String queueName, final long jobOffset, final long jobCount) throws Exception {
final String key = key(QUEUE, queueName);
final List<Job> jobs = new ArrayList<>();
if (JedisUtils.isDelayedQueue(jedis, key)) { // If delayed queue, use ZRANGEWITHS... | java |
@SuppressWarnings("unchecked")
public void setVars(final Map<String, ? extends Object> vars) {
this.vars = (Map<String, Object>)vars;
} | java |
@JsonAnySetter
public void setUnknownField(final String name, final Object value) {
this.unknownFields.put(name, value);
} | java |
@JsonIgnore
public void setUnknownFields(final Map<String,Object> unknownFields) {
this.unknownFields.clear();
this.unknownFields.putAll(unknownFields);
} | java |
public void addJobType(final String jobName, final Class<?> jobType) {
checkJobType(jobName, jobType);
this.jobTypes.put(jobName, jobType);
} | java |
public void removeJobType(final Class<?> jobType) {
if (jobType == null) {
throw new IllegalArgumentException("jobType must not be null");
}
this.jobTypes.values().remove(jobType);
} | java |
public void setJobTypes(final Map<String, ? extends Class<?>> jobTypes) {
checkJobTypes(jobTypes);
this.jobTypes.clear();
this.jobTypes.putAll(jobTypes);
} | java |
protected void checkJobTypes(final Map<String, ? extends Class<?>> jobTypes) {
if (jobTypes == null) {
throw new IllegalArgumentException("jobTypes must not be null");
}
for (final Entry<String, ? extends Class<?>> entry : jobTypes.entrySet()) {
try {
chec... | java |
protected void checkJobType(final String jobName, final Class<?> jobType) {
if (jobName == null) {
throw new IllegalArgumentException("jobName must not be null");
}
if (jobType == null) {
throw new IllegalArgumentException("jobType must not be null");
}
if... | java |
public static void doPublish(final Jedis jedis, final String namespace, final String channel, final String jobJson) {
jedis.publish(JesqueUtils.createKey(namespace, CHANNEL, channel), jobJson);
} | java |
public static <T> T createObject(final Class<T> clazz, final Object... args) throws NoSuchConstructorException,
AmbiguousConstructorException, ReflectiveOperationException {
return findConstructor(clazz, args).newInstance(args);
} | java |
public static <T> T createObject(final Class<T> clazz, final Object[] args, final Map<String,Object> vars)
throws NoSuchConstructorException, AmbiguousConstructorException, ReflectiveOperationException {
return invokeSetters(findConstructor(clazz, args).newInstance(args), vars);
} | java |
@SuppressWarnings("rawtypes")
private static <T> Constructor<T> findConstructor(final Class<T> clazz, final Object... args)
throws NoSuchConstructorException, AmbiguousConstructorException {
final Object[] cArgs = (args == null) ? new Object[0] : args;
Constructor<T> constructorToUse = n... | java |
public static <T> T invokeSetters(final T instance, final Map<String,Object> vars)
throws ReflectiveOperationException {
if (instance != null && vars != null) {
final Class<?> clazz = instance.getClass();
final Method[] methods = clazz.getMethods();
for (final En... | java |
protected static void checkQueues(final Iterable<String> queues) {
if (queues == null) {
throw new IllegalArgumentException("queues must not be null");
}
for (final String queue : queues) {
if (queue == null || "".equals(queue)) {
throw new IllegalArgument... | java |
protected String failMsg(final Throwable thrwbl, final String queue, final Job job) throws IOException {
final JobFailure failure = new JobFailure();
failure.setFailedAt(new Date());
failure.setWorker(this.name);
failure.setQueue(queue);
failure.setPayload(job);
failure.s... | java |
protected String statusMsg(final String queue, final Job job) throws IOException {
final WorkerStatus status = new WorkerStatus();
status.setRunAt(new Date());
status.setQueue(queue);
status.setPayload(job);
return ObjectMapperFactory.get().writeValueAsString(status);
} | java |
protected String pauseMsg() throws IOException {
final WorkerStatus status = new WorkerStatus();
status.setRunAt(new Date());
status.setPaused(isPaused());
return ObjectMapperFactory.get().writeValueAsString(status);
} | java |
protected String createName() {
final StringBuilder buf = new StringBuilder(128);
try {
buf.append(InetAddress.getLocalHost().getHostName()).append(COLON)
.append(ManagementFactory.getRuntimeMXBean().getName().split("@")[0]) // PID
.append('-').append(... | java |
@Override
public void join(final long millis) throws InterruptedException {
for (final Thread thread : this.threads) {
thread.join(millis);
}
} | java |
protected static void checkChannels(final Iterable<String> channels) {
if (channels == null) {
throw new IllegalArgumentException("channels must not be null");
}
for (final String channel : channels) {
if (channel == null || "".equals(channel)) {
throw new... | java |
public static <V> V doWorkInPool(final Pool<Jedis> pool, final PoolWork<Jedis, V> work) throws Exception {
if (pool == null) {
throw new IllegalArgumentException("pool must not be null");
}
if (work == null) {
throw new IllegalArgumentException("work must not be null");
... | java |
public static <V> V doWorkInPoolNicely(final Pool<Jedis> pool, final PoolWork<Jedis, V> work) {
final V result;
try {
result = doWorkInPool(pool, work);
} catch (RuntimeException re) {
throw re;
} catch (Exception e) {
throw new RuntimeException(e);
... | java |
public static Pool<Jedis> createJedisPool(final Config jesqueConfig, final GenericObjectPoolConfig poolConfig) {
if (jesqueConfig == null) {
throw new IllegalArgumentException("jesqueConfig must not be null");
}
if (poolConfig == null) {
throw new IllegalArgumentException... | java |
public static void doEnqueue(final Jedis jedis, final String namespace, final String queue, final String jobJson) {
jedis.sadd(JesqueUtils.createKey(namespace, QUEUES), queue);
jedis.rpush(JesqueUtils.createKey(namespace, QUEUE, queue), jobJson);
} | java |
public static void doBatchEnqueue(final Jedis jedis, final String namespace, final String queue, final List<String> jobJsons) {
Pipeline pipelined = jedis.pipelined();
pipelined.sadd(JesqueUtils.createKey(namespace, QUEUES), queue);
for (String jobJson : jobJsons) {
pipelined.rpush(J... | java |
public static void doPriorityEnqueue(final Jedis jedis, final String namespace, final String queue, final String jobJson) {
jedis.sadd(JesqueUtils.createKey(namespace, QUEUES), queue);
jedis.lpush(JesqueUtils.createKey(namespace, QUEUE, queue), jobJson);
} | java |
public static boolean doAcquireLock(final Jedis jedis, final String namespace, final String lockName, final String lockHolder, final int timeout) {
final String key = JesqueUtils.createKey(namespace, lockName);
// If lock already exists, extend it
String existingLockHolder = jedis.get(key);
... | java |
public ConfigBuilder withHost(final String host) {
if (host == null || "".equals(host)) {
throw new IllegalArgumentException("host must not be null or empty: " + host);
}
this.host = host;
return this;
} | java |
public ConfigBuilder withSentinels(final Set<String> sentinels) {
if (sentinels == null || sentinels.size() < 1) {
throw new IllegalArgumentException("sentinels is null or empty: " + sentinels);
}
this.sentinels = sentinels;
return this;
} | java |
public ConfigBuilder withMasterName(final String masterName) {
if (masterName == null || "".equals(masterName)) {
throw new IllegalArgumentException("masterName is null or empty: " + masterName);
}
this.masterName = masterName;
return this;
} | java |
public static boolean ensureJedisConnection(final Jedis jedis) {
final boolean jedisOK = testJedisConnection(jedis);
if (!jedisOK) {
try {
jedis.quit();
} catch (Exception e) {
} // Ignore
try {
jedis.disconnect();
... | java |
public static boolean reconnect(final Jedis jedis, final int reconAttempts, final long reconnectSleepTime) {
int i = 1;
do {
try {
jedis.disconnect();
try {
Thread.sleep(reconnectSleepTime);
} catch (Exception e2) {
... | java |
public static boolean isRegularQueue(final Jedis jedis, final String key) {
return LIST.equalsIgnoreCase(jedis.type(key));
} | java |
public static boolean isDelayedQueue(final Jedis jedis, final String key) {
return ZSET.equalsIgnoreCase(jedis.type(key));
} | java |
public static boolean isKeyUsed(final Jedis jedis, final String key) {
return !NONE.equalsIgnoreCase(jedis.type(key));
} | java |
public static boolean canUseAsDelayedQueue(final Jedis jedis, final String key) {
final String type = jedis.type(key);
return (ZSET.equalsIgnoreCase(type) || NONE.equalsIgnoreCase(type));
} | java |
public void createNamespace() {
Map<String, String> namespaceAnnotations = annotationProvider.create(session.getId(), Constants.RUNNING_STATUS);
if (namespaceService.exists(session.getNamespace())) {
//namespace exists
} else if (configuration.isNamespaceLazyCreateEnabled()) {
... | java |
private static int getPort(Service service, Annotation... qualifiers) {
for (Annotation q : qualifiers) {
if (q instanceof Port) {
Port port = (Port) q;
if (port.value() > 0) {
return port.value();
}
}
}
... | java |
private static int getContainerPort(Service service, Annotation... qualifiers) {
for (Annotation q : qualifiers) {
if (q instanceof Port) {
Port port = (Port) q;
if (port.value() > 0) {
return port.value();
}
}
}... | java |
private static String getScheme(Service service, Annotation... qualifiers) {
for (Annotation q : qualifiers) {
if (q instanceof Scheme) {
return ((Scheme) q).value();
}
}
if (service.getMetadata() != null && service.getMetadata().getAnnotations() != null)... | java |
private static String getPath(Service service, Annotation... qualifiers) {
for (Annotation q : qualifiers) {
if (q instanceof Scheme) {
return ((Scheme) q).value();
}
}
if (service.getMetadata() != null && service.getMetadata().getAnnotations() != null) {... | java |
private static Pod getRandomPod(KubernetesClient client, String name, String namespace) {
Endpoints endpoints = client.endpoints().inNamespace(namespace).withName(name).get();
List<String> pods = new ArrayList<>();
if (endpoints != null) {
for (EndpointSubset subset : endpoints.getSu... | java |
public static URL classFileUrl(Class<?> clazz) throws IOException {
ClassLoader cl = clazz.getClassLoader();
if (cl == null) {
cl = ClassLoader.getSystemClassLoader();
}
URL res = cl.getResource(clazz.getName().replace('.', '/') + ".class");
if (res == null) {
... | java |
private static String decode(String s) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
for (int i = 0; i < s.length(); i++) {
char ch = s.charAt(i);
if (ch == '%') {
baos.write(hexToInt(s.charAt(i + 1)) * 16 + hexToInt(s.charAt(i + 2)));
... | java |
public List<? super OpenShiftResource> processTemplateResources() {
List<? extends OpenShiftResource> resources;
final List<? super OpenShiftResource> processedResources = new ArrayList<>();
templates = OpenShiftResourceFactory.getTemplates(getType());
boolean sync_instantiation = OpenSh... | java |
public ExecInspection execStartVerbose(String containerId, String... commands) {
this.readWriteLock.readLock().lock();
try {
String id = execCreate(containerId, commands);
CubeOutput output = execStartOutput(id);
return new ExecInspection(output, inspectExec(id));
... | java |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.