method2testcases stringlengths 118 6.63k |
|---|
### Question:
ArchCondition { public void finish(ConditionEvents events) { } ArchCondition(String description, Object... args); void init(Iterable<T> allObjectsToTest); abstract void check(T item, ConditionEvents events); void finish(ConditionEvents events); ArchCondition<T> and(ArchCondition<? super T> condition); Arc... |
### Question:
EvaluationResult { @PublicAPI(usage = ACCESS) public FailureReport getFailureReport() { return new FailureReport(rule, priority, events.getFailureMessages()); } @PublicAPI(usage = ACCESS) EvaluationResult(HasDescription rule, Priority priority); @PublicAPI(usage = ACCESS) EvaluationResult(HasDescription... |
### Question:
InitialConfiguration { public synchronized void set(T object) { checkState(this.value == null, String.format( "Configuration may only be set once - current: %s / new: %s", this.value, object)); this.value = object; } synchronized void set(T object); synchronized T get(); }### Answer:
@Test public void t... |
### Question:
InitialConfiguration { public synchronized T get() { checkState(value != null, "No value was ever set"); return value; } synchronized void set(T object); synchronized T get(); }### Answer:
@Test public void throws_exception_if_no_value_is_present_on_access() { thrown.expect(IllegalStateException.class);... |
### Question:
Locations { @PublicAPI(usage = ACCESS) public static Set<Location> of(Iterable<URL> urls) { ImmutableSet.Builder<Location> result = ImmutableSet.builder(); for (URL url : urls) { result.add(Location.of(url)); } return result.build(); } private Locations(); @PublicAPI(usage = ACCESS) static Set<Location> ... |
### Question:
Locations { @PublicAPI(usage = ACCESS) public static Set<Location> ofPackage(String pkg) { ImmutableSet.Builder<Location> result = ImmutableSet.builder(); for (Location location : getLocationsOf(asResourceName(pkg))) { result.add(location); } return result.build(); } private Locations(); @PublicAPI(usage... |
### Question:
Locations { @PublicAPI(usage = ACCESS) public static Set<Location> ofClass(Class<?> clazz) { return getLocationsOf(asResourceName(clazz.getName()) + ".class"); } private Locations(); @PublicAPI(usage = ACCESS) static Set<Location> of(Iterable<URL> urls); @PublicAPI(usage = ACCESS) static Set<Location> of... |
### Question:
Locations { @PublicAPI(usage = ACCESS) public static Set<Location> inClassPath() { ImmutableSet.Builder<Location> result = ImmutableSet.builder(); for (URL url : locationResolver.get().resolveClassPath()) { result.add(Location.of(url)); } return result.build(); } private Locations(); @PublicAPI(usage = A... |
### Question:
Location { @PublicAPI(usage = ACCESS) public boolean contains(String part) { return uri.toString().contains(part); } Location(NormalizedUri uri); @PublicAPI(usage = ACCESS) URI asURI(); @PublicAPI(usage = ACCESS) boolean contains(String part); @PublicAPI(usage = ACCESS) boolean matches(Pattern pattern); @... |
### Question:
Location { @PublicAPI(usage = ACCESS) public boolean matches(Pattern pattern) { return pattern.matcher(uri.toString()).matches(); } Location(NormalizedUri uri); @PublicAPI(usage = ACCESS) URI asURI(); @PublicAPI(usage = ACCESS) boolean contains(String part); @PublicAPI(usage = ACCESS) boolean matches(Patt... |
### Question:
Location { @PublicAPI(usage = ACCESS) public URI asURI() { return uri.toURI(); } Location(NormalizedUri uri); @PublicAPI(usage = ACCESS) URI asURI(); @PublicAPI(usage = ACCESS) boolean contains(String part); @PublicAPI(usage = ACCESS) boolean matches(Pattern pattern); @PublicAPI(usage = ACCESS) abstract b... |
### Question:
Location { Location append(String relativeURI) { relativeURI = encodeIllegalCharacters(relativeURI); if (uri.toString().endsWith("/") && relativeURI.startsWith("/")) { relativeURI = relativeURI.substring(1); } if (!uri.toString().endsWith("/") && !relativeURI.startsWith("/")) { relativeURI = "/" + relativ... |
### Question:
ClassFileImporter { @PublicAPI(usage = ACCESS) public JavaClasses importPackagesOf(Class<?>... classes) { return importPackagesOf(ImmutableSet.copyOf(classes)); } @PublicAPI(usage = ACCESS) ClassFileImporter(); @PublicAPI(usage = ACCESS) ClassFileImporter(ImportOptions importOptions); @PublicAPI(usage =... |
### Question:
ContainsOnlyCondition extends ArchCondition<Collection<? extends T>> { @Override public void check(Collection<? extends T> collection, ConditionEvents events) { ConditionEvents subEvents = new ConditionEvents(); for (T item : collection) { condition.check(item, subEvents); } if (!subEvents.isEmpty()) { ev... |
### Question:
ClassFileImporter { @PublicAPI(usage = ACCESS) public JavaClasses importUrls(Collection<URL> urls) { return importLocations(Locations.of(urls)); } @PublicAPI(usage = ACCESS) ClassFileImporter(); @PublicAPI(usage = ACCESS) ClassFileImporter(ImportOptions importOptions); @PublicAPI(usage = ACCESS) ClassFi... |
### Question:
ClassFileImporter { @PublicAPI(usage = ACCESS) public JavaClasses importUrl(URL url) { return importUrls(singletonList(url)); } @PublicAPI(usage = ACCESS) ClassFileImporter(); @PublicAPI(usage = ACCESS) ClassFileImporter(ImportOptions importOptions); @PublicAPI(usage = ACCESS) ClassFileImporter withImpo... |
### Question:
JavaClassDescriptorImporter { static JavaClassDescriptor createFromAsmObjectTypeName(String objectTypeName) { return importAsmType(Type.getObjectType(objectTypeName)); } }### Answer:
@Test public void asm_object_type() { JavaClassDescriptor objectType = JavaClassDescriptorImporter.createFromAsmObjectTy... |
### Question:
JavaClassDescriptorImporter { static JavaClassDescriptor importAsmType(Type type) { return JavaClassDescriptor.From.name(type.getClassName()); } }### Answer:
@Test public void asm_Type() throws NoSuchMethodException { Type toStringType = Type.getReturnType(Object.class.getDeclaredMethod("toString")); J... |
### Question:
JavaAccess implements HasName, HasDescription, HasOwner<JavaCodeUnit>, HasSourceCodeLocation { @Override @PublicAPI(usage = ACCESS) public String getDescription() { String description = origin.getDescription() + " " + descriptionVerb() + " " + getTarget().getDescription(); return description + " in " + ge... |
### Question:
Formatters { @PublicAPI(usage = ACCESS) public static String ensureSimpleName(String name) { int lastIndexOfDot = name.lastIndexOf('.'); String partAfterDot = lastIndexOfDot >= 0 ? name.substring(lastIndexOfDot + 1) : name; int lastIndexOf$ = partAfterDot.lastIndexOf('$'); String simpleNameCandidate = las... |
### Question:
JavaPackage implements HasName, HasAnnotations<JavaPackage> { @PublicAPI(usage = ACCESS) public JavaClass getClassWithSimpleName(String className) { return getValue(tryGetClassWithSimpleName(className), "This package does not contain any class with simple name '%s'", className); } private JavaPackage(Str... |
### Question:
JavaPackage implements HasName, HasAnnotations<JavaPackage> { @PublicAPI(usage = ACCESS) public Optional<? extends HasAnnotations<?>> tryGetPackageInfo() { return packageInfo; } private JavaPackage(String name, Set<JavaClass> classes, Map<String, JavaPackage> subPackages); @Override @PublicAPI(usage = AC... |
### Question:
JavaPackage implements HasName, HasAnnotations<JavaPackage> { @Override @PublicAPI(usage = ACCESS) public Set<? extends JavaAnnotation<JavaPackage>> getAnnotations() { if (packageInfo.isPresent()) { return FluentIterable.from(packageInfo.get().getAnnotations()).transform(toGuava(withSelfAsOwner)).toSet();... |
### Question:
JavaPackage implements HasName, HasAnnotations<JavaPackage> { @Override @PublicAPI(usage = ACCESS) public <A extends Annotation> Optional<A> tryGetAnnotationOfType(Class<A> type) { if (packageInfo.isPresent()) { return packageInfo.get().tryGetAnnotationOfType(type); } return Optional.absent(); } private ... |
### Question:
NeverCondition extends ArchCondition<T> { @Override public void init(Iterable<T> allObjectsToTest) { condition.init(allObjectsToTest); } NeverCondition(ArchCondition<T> condition); @Override void init(Iterable<T> allObjectsToTest); @Override void finish(ConditionEvents events); @Override void check(T item... |
### Question:
JavaFieldAccess extends JavaAccess<FieldAccessTarget> { @Override public int hashCode() { return 31 * super.hashCode() + accessType.hashCode(); } JavaFieldAccess(JavaFieldAccessBuilder builder); @PublicAPI(usage = ACCESS) AccessType getAccessType(); @Override int hashCode(); @Override boolean equals(Objec... |
### Question:
AnnotationProxy { public static <A extends Annotation> A of(Class<A> annotationType, JavaAnnotation<?> toProxy) { checkArgument(annotationType.getName().equals(toProxy.getRawType().getName()), "Requested annotation type %s is incompatible with %s of type %s", annotationType.getSimpleName(), JavaAnnotation... |
### Question:
JavaWildcardType implements JavaType, HasUpperBounds { @Override @PublicAPI(usage = ACCESS) public String getName() { return WILDCARD_TYPE_NAME; } JavaWildcardType(JavaWildcardTypeBuilder builder); @Override @PublicAPI(usage = ACCESS) String getName(); @Override @PublicAPI(usage = ACCESS) List<JavaType> g... |
### Question:
JavaWildcardType implements JavaType, HasUpperBounds { @Override @PublicAPI(usage = ACCESS) public List<JavaType> getUpperBounds() { return upperBounds; } JavaWildcardType(JavaWildcardTypeBuilder builder); @Override @PublicAPI(usage = ACCESS) String getName(); @Override @PublicAPI(usage = ACCESS) List<Jav... |
### Question:
JavaWildcardType implements JavaType, HasUpperBounds { @PublicAPI(usage = ACCESS) public List<JavaType> getLowerBounds() { return lowerBounds; } JavaWildcardType(JavaWildcardTypeBuilder builder); @Override @PublicAPI(usage = ACCESS) String getName(); @Override @PublicAPI(usage = ACCESS) List<JavaType> get... |
### Question:
JavaWildcardType implements JavaType, HasUpperBounds { @Override @PublicAPI(usage = ACCESS) public JavaClass toErasure() { return erasure; } JavaWildcardType(JavaWildcardTypeBuilder builder); @Override @PublicAPI(usage = ACCESS) String getName(); @Override @PublicAPI(usage = ACCESS) List<JavaType> getUppe... |
### Question:
JavaWildcardType implements JavaType, HasUpperBounds { @Override public String toString() { String bounds = boundsToString(); return getClass().getSimpleName() + '{' + getName() + bounds + '}'; } JavaWildcardType(JavaWildcardTypeBuilder builder); @Override @PublicAPI(usage = ACCESS) String getName(); @Ove... |
### Question:
QuickSort extends AbstractSort<E> { public void sort(SortableCollection<E> sortable) { int n = sortable.size(); FJQuickSort<E> qsort = new FJQuickSort<>(comparator,swapper); qsort.qsort(sortable, 0, n-1); } void sort(SortableCollection<E> sortable); }### Answer:
@Test public void canSortStrings() { fina... |
### Question:
ResourceBasedProductLookup implements ProductLookup { @Override public List<String> byQuery(String query) { log.info("query is {}", query); loadProducts(); List<String> pis = new LinkedList<>(); StringTokenizer st = new StringTokenizer(query, "&="); while (st.hasMoreTokens()) { final String key = st.nextT... |
### Question:
UniqueGuesser extends Guesser { @Override protected Guess nextGuess() { Guess guess = super.nextGuess(); while (guess.isNotUnique()) { guess = super.nextGuess(); } return guess; } @Inject UniqueGuesser(Table table); }### Answer:
@Test public void generateAllGuesses() { int numberOfGuesses = 0; Table ta... |
### Question:
Row { public boolean matches(Guess guess) { return this.guess.nrOfPartialMatches(guess) == partial && this.guess.nrOfFullMatches(guess) == full; } Row(Guess guess, int full, int partial); protected Row(Row cloneFrom); void setFull(int full); void setPartial(int partial); boolean matches(Guess guess); int... |
### Question:
Game { public Row addNewGuess(Guess guess) { final int full = secret.nrOfFullMatches(guess); final int partial = secret.nrOfPartialMatches(guess); return addGuess(guess, full, partial); } Game(Table table, Guess secret); void setFinished(); Row addGuess(Guess guess, int full, int partial); Row addNewGuess... |
### Question:
ColorManager { public Color firstColor() { return first; } @Inject ColorManager(@Named("nrColors") int nrColors, ColorFactory factory); Color firstColor(); boolean thereIsNextColor(Color color); Color nextColor(Color color); int getNrColors(); }### Answer:
@Test public void thereIsAFirstColor() { ColorM... |
### Question:
ColorManager { public Color nextColor(Color color) { return successor.get(color); } @Inject ColorManager(@Named("nrColors") int nrColors, ColorFactory factory); Color firstColor(); boolean thereIsNextColor(Color color); Color nextColor(Color color); int getNrColors(); }### Answer:
@Test public void noCo... |
### Question:
UniqueGuesser extends Guesser { @Override protected Guess nextGuess() { Guess guess = super.nextGuess(); while (!guess.isUnique()) { guess = super.nextGuess(); } return guess; } UniqueGuesser(Table table); }### Answer:
@Test public void generateAllGuesses() { int numberOfGuesses = 0; Table table = new T... |
### Question:
Row { public boolean matches(Guess guess) { return this.guess.nrOfPartialMatches(guess) == partial && this.guess.nrOfFullMatches(guess) == full; } Row(Guess guess, int full, int partial); protected Row(Row cloneFrom); boolean matches(Guess guess); int nrOfColumns(); String toString(); static final Row no... |
### Question:
Game { public Row addNewGuess(Guess guess) { assertNotFinished(); final int full = secret.nrOfFullMatches(guess); final int partial = secret.nrOfPartialMatches(guess); final Row row = new Row(guess,full,partial); table.addRow(row); if (itWasAWinningGuess(full)) { finished = true; } return row; } Game(Tabl... |
### Question:
ColorManager { public Color firstColor() { return first; } ColorManager(int nrColors, ColorFactory factory); Color firstColor(); boolean thereIsNextColor(Color color); Color nextColor(Color color); int getNrColors(); }### Answer:
@Test public void thereIsAFirstColor() { ColorManager manager = new ColorMa... |
### Question:
ColorManager { public Color nextColor(Color color) { return successor.get(color); } ColorManager(int nrColors, ColorFactory factory); Color firstColor(); boolean thereIsNextColor(Color color); Color nextColor(Color color); int getNrColors(); }### Answer:
@Test public void noColorHasNoNextColor() { ColorM... |
### Question:
Partitioner { public int partition(SortableCollection<E> sortable, int start, int end, E pivot) { int small = start; int large = end; while (large > small) { while (comparator.compare(sortable.get(small), pivot) < 0 && small < large ) { small++; } while (comparator.compare(sortable.get(large), pivot) >= 0... |
### Question:
UniqueGuesser extends Guesser { @Override protected Color[] nextGuess() { Color[] guess = super.nextGuess(); while (isNotUnique(guess)) { guess = super.nextGuess(); } return guess; } UniqueGuesser(Table table); }### Answer:
@Test public void generateAllGuesses() { int numberOfGuesses = 0; ColorManager m... |
### Question:
Row { public void setMatch(int matchedPositions, int matchedColors) { if (matchedColors + matchedPositions > positions.length) { throw new IllegalArgumentException( "Number of matches can not be more that the position."); } this.matchedColors = matchedColors; this.matchedPositions = matchedPositions; } Ro... |
### Question:
Game { public void addNewGuess(Row row) { if (isFinished()) { throw new IllegalArgumentException("You can not guess on a finished game."); } final int positionMatch = secretRow.nrMatchingPositions(row.positions); final int colorMatch = secretRow.nrMatchingColors(row.positions); row.setMatch(positionMatch,... |
### Question:
ColorManager { public Color firstColor() { return first; } ColorManager(int nrColors); Color firstColor(); Color nextColor(Color color); }### Answer:
@Test public void thereIsAFirstColor() { ColorManager manager = new ColorManager(NR_COLORS); System.out.println(manager.firstColor()); Assert.assertNotNull... |
### Question:
ColorManager { public Color nextColor(Color color) { return successor.get(color); } ColorManager(int nrColors); Color firstColor(); Color nextColor(Color color); }### Answer:
@Test public void noColorHasNoNextColor() { ColorManager manager = new ColorManager(NR_COLORS); Assert.assertNull(manager.nextColo... |
### Question:
AwsS3Utils { static String checkBucketIsAccessible(AmazonS3 amazonS3, String bucketName) { HeadBucketRequest headBucketRequest = new HeadBucketRequest(bucketName); try { amazonS3.headBucket(headBucketRequest); } catch (AmazonServiceException e) { throw new AwsS3Exception("Bucket is not accessible", args -... |
### Question:
JacksonSerializer implements TransactionSerializer, SnapshotSerializer { @Override public SerializableSnapshot deserializeSnapshot(String storeName, InputStream in) throws IOException { return m_objectMapper.reader().forType(SerializableSnapshot.class).readValue(in); } JacksonSerializer(); @Override void ... |
### Question:
StoreManagerBuilderConfigurator { static String getProperty(Properties properties, String key) { String property = properties.getProperty(key); if (property != null) { StringBuffer result = new StringBuffer(); Matcher matcher = VARIABLE_REGEX_PATTERN.matcher(property); while (matcher.find()) { String name... |
### Question:
SnapshotPostProcessor { @VisibleForTesting static long updateVersionAndCheckConsistency(long localVersion, long newVersion, String errorMessage) { if (localVersion == -1) { return newVersion; } else { if (localVersion != newVersion) { throw new UnrecoverableStoreException(errorMessage, args -> args.add("l... |
### Question:
SnapshotPostProcessor { long getConsistentApplicationModelVersion() { long applicationModelVersion = 0; if (m_beforePostProcessingVersion > 0) { applicationModelVersion = m_beforePostProcessingVersion; } if (m_afterPostProcessingVersion > 0) { applicationModelVersion = m_afterPostProcessingVersion; } retu... |
### Question:
SnapshotPostProcessor { SerializableSnapshot apply(String storeName, SerializableSnapshot serializableSnapshot) { m_beforePostProcessingVersion = updateVersionAndCheckConsistency(m_beforePostProcessingVersion, serializableSnapshot.getApplicationModelVersion(), "Snapshot serializable application model vers... |
### Question:
OAuthAsyncCompletionHandler extends AsyncCompletionHandler<T> { @Override public T onCompleted(com.ning.http.client.Response ningResponse) { try { final Map<String, String> headersMap = new HashMap<>(); for (Map.Entry<String, List<String>> header : ningResponse.getHeaders().entrySet()) { final StringBuild... |
### Question:
HMACSha1SignatureService implements SignatureService { @Override public String getSignature(String baseString, String apiSecret, String tokenSecret) { try { Preconditions.checkEmptyString(baseString, "Base string cant be null or empty string"); Preconditions.checkEmptyString(apiSecret, "Api secret cant be... |
### Question:
RSASha1SignatureService implements SignatureService { @Override public String getSignatureMethod() { return METHOD; } RSASha1SignatureService(PrivateKey privateKey); @Override String getSignature(String baseString, String apiSecret, String tokenSecret); @Override String getSignatureMethod(); }### Answer:... |
### Question:
RSASha1SignatureService implements SignatureService { @Override public String getSignature(String baseString, String apiSecret, String tokenSecret) { try { final Signature signature = Signature.getInstance(RSA_SHA1); signature.initSign(privateKey); signature.update(baseString.getBytes(UTF8)); return BASE_... |
### Question:
ParameterList { public String appendTo(String url) { Preconditions.checkNotNull(url, "Cannot append to null URL"); final String queryString = asFormUrlEncodedString(); if (queryString.equals(EMPTY_STRING)) { return url; } else { return url + (url.indexOf(QUERY_STRING_SEPARATOR) == -1 ? QUERY_STRING_SEPARA... |
### Question:
Token implements Serializable { public String getParameter(String parameter) { String value = null; for (String str : rawResponse.split("&")) { if (str.startsWith(parameter + '=')) { final String[] part = str.split("="); if (part.length > 1) { value = part[1].trim(); } break; } } return value; } protected... |
### Question:
OAuthRequest { public void addOAuthParameter(String key, String value) { oauthParameters.put(checkKey(key), value); } OAuthRequest(Verb verb, String url); void addOAuthParameter(String key, String value); Map<String, String> getOauthParameters(); void setRealm(String realm); String getRealm(); String getC... |
### Question:
MultipartUtils { public static void checkBoundarySyntax(String boundary) { if (boundary == null || !BOUNDARY_REGEXP.matcher(boundary).matches()) { throw new IllegalArgumentException("{'boundary'='" + boundary + "'} has invalid syntax. Should be '" + BOUNDARY_PATTERN + "'."); } } private MultipartUtils();... |
### Question:
Preconditions { public static void checkNotNull(Object object, String errorMsg) { check(object != null, errorMsg); } static void checkNotNull(Object object, String errorMsg); static void checkEmptyString(String string, String errorMsg); static boolean hasText(String str); }### Answer:
@Test(expected = I... |
### Question:
Preconditions { public static void checkEmptyString(String string, String errorMsg) { check(hasText(string), errorMsg); } static void checkNotNull(Object object, String errorMsg); static void checkEmptyString(String string, String errorMsg); static boolean hasText(String str); }### Answer:
@Test(expecte... |
### Question:
FitBitJsonTokenExtractor extends OAuth2AccessTokenJsonExtractor { @Override public void generateError(String rawResponse) throws IOException { final JsonNode errorNode = OAuth2AccessTokenJsonExtractor.OBJECT_MAPPER.readTree(rawResponse) .get("errors").get(0); OAuth2Error errorCode; try { errorCode = OAuth... |
### Question:
OAuthEncoder { public static String encode(String plain) { Preconditions.checkNotNull(plain, "Cannot encode null object"); String encoded; try { encoded = URLEncoder.encode(plain, CHARSET); } catch (UnsupportedEncodingException uee) { throw new OAuthException("Charset not found while encoding string: " + ... |
### Question:
OAuthEncoder { public static String decode(String encoded) { Preconditions.checkNotNull(encoded, "Cannot decode null object"); try { return URLDecoder.decode(encoded, CHARSET); } catch (UnsupportedEncodingException uee) { throw new OAuthException("Charset not found while decoding string: " + CHARSET, uee)... |
### Question:
StreamUtils { public static String getStreamContents(InputStream is) throws IOException { Preconditions.checkNotNull(is, "Cannot get String from a null object"); final char[] buffer = new char[0x10000]; final StringBuilder out = new StringBuilder(); try (Reader in = new InputStreamReader(is, "UTF-8")) { i... |
### Question:
OAuthAsyncCompletionHandler implements Callback { @Override public void onResponse(Call call, okhttp3.Response okHttpResponse) { try { final Response response = OkHttpHttpClient.convertResponse(okHttpResponse); try { @SuppressWarnings("unchecked") final T t = converter == null ? (T) response : converter.c... |
### Question:
OAuthAsyncCompletionHandler implements Callback { @Override public void onFailure(Call call, IOException exception) { try { okHttpFuture.setException(exception); if (callback != null) { callback.onThrowable(exception); } } finally { okHttpFuture.finish(); } } OAuthAsyncCompletionHandler(OAuthAsyncRequestC... |
### Question:
HMACSha1SignatureService implements SignatureService { @Override public String getSignatureMethod() { return METHOD; } @Override String getSignature(String baseString, String apiSecret, String tokenSecret); @Override String getSignatureMethod(); }### Answer:
@Test public void shouldReturnSignatureMethod... |
### Question:
CSRFToken implements Serializable { public String getParameterName() { return parameterName; } CSRFToken(String token); CSRFToken(String headerName, String parameterName, String token); String getHeaderName(); String getParameterName(); String getToken(); }### Answer:
@Test public void testPOSTRequestsW... |
### Question:
FileSystemLogRepository implements ExecutionLogRepository { @Override public void update(ExecutionLog log) { store(log, readJson(logFileFor(log.getTaskName(), log.getId())).map(obj -> obj.getAsJsonPrimitive("previous")).map( JsonPrimitive::getAsString)); } FileSystemLogRepository(String basePath, int disp... |
### Question:
FileSystemLogRepository implements ExecutionLogRepository { @Override public Stream<ExecutionLog> executionsFor(String taskName, Optional<String> start, int max) { String id; if (start.isPresent()) { id = start.get(); } else { JsonObject index = readIndexJson(); if (!index.has(taskName)) { return Stream.e... |
### Question:
ExecutionLog { public static ExecutionLog newExecutionFor(String taskName) { return new ExecutionLog(UUID.randomUUID().toString().replace("-", ""), DateTime.now(), Optional.empty(), TaskState.RUNNING, Objects.requireNonNull(taskName), Optional.empty(), Collections.emptySet(), computeHostName(), Optional.e... |
### Question:
ExecutionLog { public static ExecutionLog newCustomExecution(String taskName, String code, String user) { return new ExecutionLog(UUID.randomUUID().toString().replace("-", ""), DateTime.now(), Optional.empty(), TaskState.RUNNING, Objects.requireNonNull(taskName), Optional.empty(), Collections.emptySet(), ... |
### Question:
ExecutionLog { @Override public boolean equals(Object obj) { if (obj instanceof ExecutionLog) { ExecutionLog other = (ExecutionLog) obj; return Objects.equals(id, other.id) && Objects.equals(start, other.start) && Objects.equals(end, other.end) && Objects.equals(state, other.state) && Objects.equals(taskN... |
### Question:
GuitarString { public void tic() { double newAveragedDouble = DECAY * (buffer.dequeue() + buffer.peek()) / 2; buffer.enqueue(newAveragedDouble); } GuitarString(double frequency); void pluck(); void tic(); double sample(); }### Answer:
@Test public void testTic() { GuitarString s = new GuitarString(11025)... |
### Question:
Plip extends Creature { public Action chooseAction(Map<Direction, Occupant> neighbors) { List<Direction> emptySpaces = getNeighborsOfType(neighbors, "empty"); List<Direction> cloruses = getNeighborsOfType(neighbors, "clorus"); if (emptySpaces.isEmpty()) { return new Action(Action.ActionType.STAY); } if (e... |
### Question:
Board implements WorldState { public int tileAt(int i, int j) { if (i < 0 || i >= N || j < 0 || j >= N) { throw new IndexOutOfBoundsException("Invalid row and/or column"); } return tiles[i][j]; } Board(int[][] tiles); int tileAt(int i, int j); int size(); int hamming(); int manhattan(); int hashCode(); bo... |
### Question:
IntList { public static IntList list(Integer... args) { IntList result, p; if (args.length > 0) { result = new IntList(args[0], null); } else { return null; } int k; for (k = 1, p = result; k < args.length; k += 1, p = p.rest) { p.rest = new IntList(args[k], null); } return result; } IntList(int first0, I... |
### Question:
IntList { public static void dSquareList(IntList L) { while (L != null) { L.first = L.first * L.first; L = L.rest; } } IntList(int first0, IntList rest0); IntList(); static void dSquareList(IntList L); static IntList squareListIterative(IntList L); static IntList squareListRecursive(IntList L); static In... |
### Question:
IntList { public static IntList squareListRecursive(IntList L) { if (L == null) { return null; } return new IntList(L.first * L.first, squareListRecursive(L.rest)); } IntList(int first0, IntList rest0); IntList(); static void dSquareList(IntList L); static IntList squareListIterative(IntList L); static I... |
### Question:
IntList { public static IntList dcatenate(IntList A, IntList B) { return null; } IntList(int first0, IntList rest0); IntList(); static void dSquareList(IntList L); static IntList squareListIterative(IntList L); static IntList squareListRecursive(IntList L); static IntList dcatenate(IntList A, IntList B);... |
### Question:
IntList { public static IntList catenate(IntList A, IntList B) { return null; } IntList(int first0, IntList rest0); IntList(); static void dSquareList(IntList L); static IntList squareListIterative(IntList L); static IntList squareListRecursive(IntList L); static IntList dcatenate(IntList A, IntList B); ... |
### Question:
Boggle { public static String answerString(List<String> answers, int numberOfAnswers) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < answers.size() && i < numberOfAnswers; i++) { sb.append(answers.get(i)).append('\n'); } sb.setLength(sb.length() - 1); return sb.toString(); } static void ma... |
### Question:
Arithmetic { public static int product(int a, int b) { return a * b; } static int product(int a, int b); static int sum(int a, int b); }### Answer:
@Test public void testProduct() { assertEquals(30, Arithmetic.product(5, 6)); assertEquals(-30, Arithmetic.product(5, -6)); assertEquals(0, Arithmetic.produ... |
### Question:
Arithmetic { public static int sum(int a, int b) { return a * b; } static int product(int a, int b); static int sum(int a, int b); }### Answer:
@Test public void testSum() { assertEquals(11, Arithmetic.sum(5, 6)); assertEquals(-1, Arithmetic.sum(5, -6)); assertEquals(-6, Arithmetic.sum(0, -6)); assertEq... |
### Question:
Trie { public List<String> getWordsContainingPrefix(String prefix) { LinkedList<String> words = new LinkedList<>(); Node pointer = root; for (int i = 0; i < prefix.length(); i++) { char currentChar = prefix.charAt(i); if (!pointer.children.containsKey(currentChar)) { return words; } pointer = pointer.chil... |
### Question:
BinaryTrie implements Serializable { public Match longestPrefixMatch(BitSequence querySequence) { StringBuilder currentBitSeq = new StringBuilder(); Node pointer = root; for (int i = 0; i < querySequence.length(); i++) { if (querySequence.bitAt(i) == 0 && pointer.leftChild != null) { currentBitSeq.append(... |
### Question:
BinaryTrie implements Serializable { public Map<Character, BitSequence> buildLookupTable() { Map<Character, BitSequence> lookupTable = new HashMap<>(); Map<Node, String> nodeBitPrefixTable = new HashMap<>(); nodeBitPrefixTable.put(root, ""); Stack<Node> nodeStack = new Stack<>(); nodeStack.push(root); whi... |
### Question:
Dog { public String noise() { if (size < 10) { return "yip"; } return "bark"; } Dog(int s); String noise(); }### Answer:
@Test public void testSmall() { Dog d = new Dog(3); assertEquals("yip", d.noise()); }
@Test public void testLarge() { Dog d = new Dog(20); assertEquals("bark", d.noise()); } |
### Question:
SimpleOomage implements Oomage { @Override public boolean equals(Object o) { if (o == null || getClass() != o.getClass()) { return false; } if (this == o || this.hashCode() == o.hashCode()) { return true; } return false; } SimpleOomage(int r, int g, int b); @Override boolean equals(Object o); @Override in... |
### Question:
SimpleOomage implements Oomage { public static SimpleOomage randomSimpleOomage() { int red = StdRandom.uniform(0, 51) * 5; int green = StdRandom.uniform(0, 51) * 5; int blue = StdRandom.uniform(0, 51) * 5; return new SimpleOomage(red, green, blue); } SimpleOomage(int r, int g, int b); @Override boolean eq... |
### Question:
Clorus extends Creature { @Override public Clorus replicate() { energy /= 2; return new Clorus(energy); } Clorus(double energy); @Override void move(); @Override void attack(Creature c); @Override Clorus replicate(); @Override void stay(); @Override Action chooseAction(Map<Direction, Occupant> neighbors);... |
### Question:
Clorus extends Creature { @Override public Action chooseAction(Map<Direction, Occupant> neighbors) { List<Direction> emptySpaces = getNeighborsOfType(neighbors, "empty"); List<Direction> plips = getNeighborsOfType(neighbors, "plip"); if (emptySpaces.isEmpty()) { return new Action(Action.ActionType.STAY); ... |
### Question:
Plip extends Creature { public Plip replicate() { energy /= 2; return new Plip(energy); } Plip(double e); Plip(); Color color(); void attack(Creature c); void move(); void stay(); Plip replicate(); Action chooseAction(Map<Direction, Occupant> neighbors); }### Answer:
@Test public void testReplicate() { ... |
### Question:
StringWritableCsv { public static StringBuffer writeTo(StringBuffer sb, StringWritable... values) throws IllegalArgumentException { checkNotNull(sb, "sb"); if(null == values || values.length == 0) { return sb; } writeStringWritableToStringBuffer(values[0], sb); int i = 1; while (i < values.length) { sb.ap... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.