method2testcases stringlengths 118 6.63k |
|---|
### Question:
WlsDomainConfig implements WlsDomain { public synchronized WlsServerConfig getServerConfig(String serverName) { WlsServerConfig result = null; if (serverName != null && servers != null) { for (WlsServerConfig serverConfig : servers) { if (serverConfig.getName().equals(serverName)) { result = serverConfig;... |
### Question:
WlsDomainConfig implements WlsDomain { public synchronized WlsMachineConfig getMachineConfig(String machineName) { WlsMachineConfig result = null; if (machineName != null && wlsMachineConfigs != null) { result = wlsMachineConfigs.get(machineName); } return result; } WlsDomainConfig(); WlsDomainConfig(Str... |
### Question:
WlsDomainConfig implements WlsDomain { @Override @Nonnull public String[] getClusterNames() { return getClusterConfigs().keySet().toArray(new String[0]); } WlsDomainConfig(); WlsDomainConfig(String name); WlsDomainConfig(
String name,
String adminServerName,
Map<String, WlsClusterConfi... |
### Question:
WlsDomainConfig implements WlsDomain { @Override public int getReplicaLimit(String clusterName) { if (!getClusterConfigs().containsKey(clusterName)) { return 0; } return getClusterConfigs().get(clusterName).getMaxClusterSize(); } WlsDomainConfig(); WlsDomainConfig(String name); WlsDomainConfig(
St... |
### Question:
WlsDomainConfig implements WlsDomain { public Map<String, Object> toTopology() { Map<String, Object> topology = new HashMap<>(); topology.put("domainValid", "true"); topology.put("domain", createDomainTopology()); return topology; } WlsDomainConfig(); WlsDomainConfig(String name); WlsDomainConfig(
... |
### Question:
WlsClusterConfig { public synchronized int getClusterSize() { return servers.size(); } WlsClusterConfig(); WlsClusterConfig(String clusterName); WlsClusterConfig(String clusterName, WlsDynamicServersConfig dynamicServersConfig); boolean hasNamedServer(String serverName); synchronized WlsClusterConfig ad... |
### Question:
WlsClusterConfig { public synchronized boolean hasStaticServers() { return !servers.isEmpty(); } WlsClusterConfig(); WlsClusterConfig(String clusterName); WlsClusterConfig(String clusterName, WlsDynamicServersConfig dynamicServersConfig); boolean hasNamedServer(String serverName); synchronized WlsCluste... |
### Question:
WlsClusterConfig { public boolean hasDynamicServers() { return dynamicServersConfig != null; } WlsClusterConfig(); WlsClusterConfig(String clusterName); WlsClusterConfig(String clusterName, WlsDynamicServersConfig dynamicServersConfig); boolean hasNamedServer(String serverName); synchronized WlsClusterC... |
### Question:
WlsClusterConfig { public synchronized int getMaxClusterSize() { return hasDynamicServers() ? getClusterSize() + getMaxDynamicClusterSize() : getClusterSize(); } WlsClusterConfig(); WlsClusterConfig(String clusterName); WlsClusterConfig(String clusterName, WlsDynamicServersConfig dynamicServersConfig); ... |
### Question:
WlsClusterConfig { public int getDynamicClusterSize() { return dynamicServersConfig != null ? dynamicServersConfig.getDynamicClusterSize() : -1; } WlsClusterConfig(); WlsClusterConfig(String clusterName); WlsClusterConfig(String clusterName, WlsDynamicServersConfig dynamicServersConfig); boolean hasName... |
### Question:
WlsClusterConfig { public int getMinDynamicClusterSize() { return dynamicServersConfig != null ? dynamicServersConfig.getMinDynamicClusterSize() : -1; } WlsClusterConfig(); WlsClusterConfig(String clusterName); WlsClusterConfig(String clusterName, WlsDynamicServersConfig dynamicServersConfig); boolean h... |
### Question:
WlsClusterConfig { public String getUpdateDynamicClusterSizeUrl() { return "/management/weblogic/latest/edit/clusters/" + name + "/dynamicServers"; } WlsClusterConfig(); WlsClusterConfig(String clusterName); WlsClusterConfig(String clusterName, WlsDynamicServersConfig dynamicServersConfig); boolean hasN... |
### Question:
WlsClusterConfig { public String getUpdateDynamicClusterSizePayload(final int clusterSize) { return "{ dynamicClusterSize: " + clusterSize + " }"; } WlsClusterConfig(); WlsClusterConfig(String clusterName); WlsClusterConfig(String clusterName, WlsDynamicServersConfig dynamicServersConfig); boolean hasNa... |
### Question:
WlsClusterConfig { static boolean checkUpdateDynamicClusterSizeJsonResult(String jsonResult) { final String expectedResult = "{}"; boolean result = false; if (expectedResult.equals(jsonResult)) { result = true; } return result; } WlsClusterConfig(); WlsClusterConfig(String clusterName); WlsClusterConfig... |
### Question:
MacroSubstitutor { String substituteMacro(String inputValue) { if (inputValue == null) { return inputValue; } int start = 0; int idx = inputValue.indexOf(START_MACRO); if (idx == -1) { return inputValue; } StringBuilder retStr = new StringBuilder(); while (idx != -1) { retStr.append(inputValue.substring(s... |
### Question:
DomainCondition implements Comparable<DomainCondition>, PatchableComponent<DomainCondition> { public DateTime getLastTransitionTime() { return lastTransitionTime; } DomainCondition(DomainConditionType conditionType); DomainCondition(DomainCondition other); DateTime getLastProbeTime(); void setLastProbeT... |
### Question:
WatchBuilder { public WatchI<Domain> createDomainWatch(String namespace) throws ApiException { return FACTORY.createWatch( ClientPool.getInstance(), callParams, Domain.class, new ListDomainsCall(namespace)); } WatchBuilder(); WatchI<V1Service> createServiceWatch(String namespace); WatchI<V1Pod> createPodW... |
### Question:
WatchBuilder { public WatchI<V1Pod> createPodWatch(String namespace) throws ApiException { return FACTORY.createWatch( ClientPool.getInstance(), callParams, V1Pod.class, new ListPodCall(namespace)); } WatchBuilder(); WatchI<V1Service> createServiceWatch(String namespace); WatchI<V1Pod> createPodWatch(Stri... |
### Question:
PodWatcher extends Watcher<V1Pod> implements WatchListener<V1Pod>, PodAwaiterStepFactory { public Step waitForReady(V1Pod pod, Step next) { return new WaitForPodReadyStep(pod, next); } private PodWatcher(
String namespace,
String initialResourceVersion,
WatchTuning tuning,
WatchLi... |
### Question:
PodWatcher extends Watcher<V1Pod> implements WatchListener<V1Pod>, PodAwaiterStepFactory { public Step waitForDelete(V1Pod pod, Step next) { return new WaitForPodDeleteStep(pod, next); } private PodWatcher(
String namespace,
String initialResourceVersion,
WatchTuning tuning,
Watch... |
### Question:
DomainCondition implements Comparable<DomainCondition>, PatchableComponent<DomainCondition> { public boolean hasType(DomainConditionType type) { return type == this.type; } DomainCondition(DomainConditionType conditionType); DomainCondition(DomainCondition other); DateTime getLastProbeTime(); void setLa... |
### Question:
JsonSchemaMojo extends AbstractMojo { @Override public void execute() throws MojoExecutionException { main.defineClasspath(toUrls(compileClasspathElements)); main.setIncludeAdditionalProperties(includeAdditionalProperties); main.setSupportObjectReferences(supportObjectReferences); addExternalSchemas(); if... |
### Question:
DomainStatus { DateTime getStartTime() { return startTime; } DomainStatus(); DomainStatus(DomainStatus that); @Nonnull List<DomainCondition> getConditions(); DomainStatus addCondition(DomainCondition newCondition); boolean hasConditionWith(Predicate<DomainCondition> predicate); void removeConditionIf(Pre... |
### Question:
AdminServer extends Server { public AdminService getAdminService() { return adminService; } AdminServer withChannel(String channelName, int nodePort); List<String> getChannelNames(); List<Channel> getChannels(); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); Ad... |
### Question:
YamlDocGenerator { String generateForProperty(String fieldName, Map<String, Object> subSchema) { return "| " + "`" + fieldName + "`" + " | " + emptyIfNull(getType(fieldName, subSchema)) + " | " + emptyIfNull(getDescription(fieldName, subSchema)) + " |"; } YamlDocGenerator(Map<String, Object> schema); Stri... |
### Question:
YamlDocGenerator { String generateForClass(Map<String, Object> classSchema) { StringBuilder sb = new StringBuilder(CLASS_TABLE_HEADER); Map<String, Object> properties = Optional.ofNullable(subMap(classSchema, "properties")).orElse(new HashMap<>()); for (String propertyName : getSortedKeys(properties)) { s... |
### Question:
YamlDocGenerator { public String generate(String schemaName) { return generate(schemaName, schema); } YamlDocGenerator(Map<String, Object> schema); String generate(String schemaName); String generate(String reference, Map<String, Object> schema); void useKubernetesVersion(String k8sVersion); String getKub... |
### Question:
SchemaGenerator { public void useKubernetesVersion(String version) throws IOException { KubernetesSchemaReference reference = KubernetesSchemaReference.create(version); URL cacheUrl = reference.getKubernetesSchemaCacheUrl(); if (cacheUrl == null) { throw new IOException("No schema cached for Kubernetes " ... |
### Question:
KubernetesApiNames { public static boolean matches(String className, Class<?> candidateClass) { if (!candidateClass.getName().startsWith("io.kubernetes.client")) { return false; } String[] parts = className.split("\\."); if (parts.length < 2) { return false; } String last = parts[parts.length - 1]; String... |
### Question:
DomainStatus { public boolean hasConditionWith(Predicate<DomainCondition> predicate) { return !getConditionsMatching(predicate).isEmpty(); } DomainStatus(); DomainStatus(DomainStatus that); @Nonnull List<DomainCondition> getConditions(); DomainStatus addCondition(DomainCondition newCondition); boolean ha... |
### Question:
AdminServer extends Server { public AdminService createAdminService() { if (adminService == null) { adminService = new AdminService(); } return adminService; } AdminServer withChannel(String channelName, int nodePort); List<String> getChannelNames(); List<Channel> getChannels(); @Override String toString... |
### Question:
DomainStatus { public DomainStatus addServer(ServerStatus server) { synchronized (servers) { for (ListIterator<ServerStatus> it = servers.listIterator(); it.hasNext(); ) { if (Objects.equals(it.next().getServerName(), server.getServerName())) { it.remove(); } } servers.add(server); Collections.sort(server... |
### Question:
RestBackendImpl implements RestBackend { @Override public Set<String> getDomainUids() { LOGGER.entering(); authorize(null, Operation.list); Set<String> result = new TreeSet<>(); List<Domain> domains = getDomainsList(); for (Domain domain : domains) { result.add(domain.getDomainUid()); } LOGGER.exiting(res... |
### Question:
RestBackendImpl implements RestBackend { @Override public boolean isDomainUid(String domainUid) { return getDomain(domainUid).isPresent(); } RestBackendImpl(String principal, String accessToken, Collection<String> targetNamespaces); @Override Set<String> getDomainUids(); @Override boolean isDomainUid(Stri... |
### Question:
RestBackendImpl implements RestBackend { @Override public void performDomainAction(String domainUid, DomainAction params) { verifyDomain(domainUid); authorize(domainUid, Operation.update); switch (Optional.ofNullable(params.getAction()).orElse(DomainActionType.UNKNOWN)) { case INTROSPECT: introspect(domai... |
### Question:
RestBackendImpl implements RestBackend { @Override public Set<String> getClusters(String domainUid) { LOGGER.entering(domainUid); verifyDomain(domainUid); authorize(domainUid, Operation.get); Map<String, WlsClusterConfig> wlsClusterConfigs = getWlsConfiguredClusters(domainUid); Set<String> result = wlsClu... |
### Question:
RestBackendImpl implements RestBackend { @Override public boolean isCluster(String domainUid, String cluster) { LOGGER.entering(domainUid, cluster); authorize(domainUid, Operation.list); boolean result = getClusters(domainUid).contains(cluster); LOGGER.exiting(result); return result; } RestBackendImpl(Str... |
### Question:
RestBackendImpl implements RestBackend { @Override public void scaleCluster(String domainUid, String cluster, int managedServerCount) { LOGGER.entering(domainUid, cluster, managedServerCount); if (managedServerCount < 0) { throw createWebApplicationException( Status.BAD_REQUEST, MessageKeys.INVALID_MANAGE... |
### Question:
RestBackendImpl implements RestBackend { WlsDomainConfig getWlsDomainConfig(String domainUid) { for (String ns : targetNamespaces) { WlsDomainConfig config = INSTANCE.getWlsDomainConfig(ns, domainUid); if (config != null) { return config; } } return new WlsDomainConfig(null); } RestBackendImpl(String prin... |
### Question:
HttpAsyncRequestStep extends Step { @Override public NextAction apply(Packet packet) { AsyncProcessing processing = new AsyncProcessing(packet); return doSuspend(processing::process); } private HttpAsyncRequestStep(HttpRequest request, HttpResponseStep responseStep); static HttpAsyncRequestStep createGet... |
### Question:
HttpResponseStep extends Step { @Override public NextAction apply(Packet packet) { return Optional.ofNullable(getResponse(packet)).map(r -> doApply(packet, r)).orElse(doNext(packet)); } HttpResponseStep(Step next); @Override NextAction apply(Packet packet); abstract NextAction onSuccess(Packet packet, Htt... |
### Question:
Step { public String getName() { String name = getClass().getName(); int idx = name.lastIndexOf('.'); if (idx >= 0) { name = name.substring(idx + 1); } name = name.endsWith("Step") ? name.substring(0, name.length() - 4) : name; String detail = getDetail(); return detail != null ? name + "(" + detail + ")"... |
### Question:
WeightedBinaryTree { public static int getMinimumTreeWeight(int[] array) { if ((array == null) || (array.length == 0)) { throw new IllegalArgumentException("Input array is null or empty"); } int level = 0; int weight = 0; Arrays.sort(array); for (int i = 0; i < array.length; i++) { if (((i + 1) & i) == 0)... |
### Question:
Anagram { public static boolean isAnagram(String first, String second) { if (first == null || second == null) { throw new IllegalArgumentException("Input arguments cannot be null"); } if (first.length() != second.length()) { return false; } int[] occurrences = new int[256]; for (int i = 0; i < first.lengt... |
### Question:
BinaryTreesCount { public static BigInteger findBinaryTreesCount(int n) { if (n <= 0) { throw new IllegalArgumentException("Input number of vertices is not positive"); } return findBinaryTreesCount(n, new BigInteger[n + 1]); } static BigInteger findBinaryTreesCount(int n); }### Answer:
@Test(expected = ... |
### Question:
JosephusProblem { public static int getLastPerson(int n, int k) { if (n <= 0 || k <= 0) { throw new IllegalArgumentException("Input arguments should be positive"); } int lastPerson = 0; for (int i = 2; i <= n; i++) { lastPerson += k; lastPerson %= i; } return lastPerson; } static int getLastPerson(int n,... |
### Question:
CharsReplacer { public static Set<String> generatePasswords(String word, Map<Character, char[]> replacer) { if (word == null) { throw new IllegalArgumentException("Input word should be not null"); } if (replacer == null) { throw new IllegalArgumentException("Input replacer should be not null"); } Set<Stri... |
### Question:
ValidNumber { public static boolean isValid(String number) { if (number == null || number.isEmpty()) { throw new IllegalArgumentException( "Input string should be not null and not empty"); } if (number.length() == 1 && number.charAt(0) - '0' >= 0 && number.charAt(0) - '0' <= 9) { return true; } int illega... |
### Question:
TripletInSequenceWithSpecialProperty { public static int[] findTriplet(int[] a) { if ((a == null) || (a.length < 3)) { throw new IllegalArgumentException( "Array should have at least 3 elements"); } if ((a[0] < a[1]) || (a[a.length - 1] < a[a.length - 2])) { throw new IllegalArgumentException( "Array does... |
### Question:
FindNthMaxNumber { public static int findNthMaxNumberUsingSelectionSearch(int[] sequence, int n) { if (sequence == null) { throw new IllegalArgumentException("Input array is null"); } if (n < 1) { throw new IllegalArgumentException("Input n is non-positive"); } if (sequence.length < n) { throw new Illegal... |
### Question:
FindNthMaxNumber { public static int findNthMaxNumberUsingBinaryHeap(int[] sequence, int n) { if (sequence == null) { throw new IllegalArgumentException("Input array is null"); } if (n < 1) { throw new IllegalArgumentException("Input n is non-positive"); } if (sequence.length < n) { throw new IllegalArgum... |
### Question:
StringMatchesPatternString { public static boolean matches(String str, String pattern) { if (str == null || pattern == null) { throw new IllegalArgumentException("Tested string either pattern string is null"); } Boolean[][] cache = new Boolean[str.length() + 1][pattern.length() + 1]; return matches(str, p... |
### Question:
RemoveDuplicatesFromArray { public static int[] removeDuplicates(int[] sequence) { if (sequence == null || sequence.length == 0) { return sequence; } Map<Integer, Integer> unique = new HashMap<>(); int cnt = 0; for (int element : sequence) { Integer pos = unique.get(element); if (pos == null) { unique.put... |
### Question:
GlassesWithWater { public static double getAmountOfWater(int level, int column, double x) { if (x <= 0) { throw new IllegalArgumentException("Amount of water should be positive"); } if (level < 0) { throw new IllegalArgumentException("Level should be non-negative"); } if (column < 0) { throw new IllegalAr... |
### Question:
BinarySearchTreeResolver { public static boolean isBinarySearchTree(BinaryTree tree) { if (tree == null) { throw new IllegalArgumentException("Input binary tree is null"); } if (tree.left != null) { int lValue = max(tree.left); if (lValue >= tree.value) { return false; } } if (tree.right != null) { int rV... |
### Question:
FrogJumping { public static int findShortestWay(int[] array) { if (array == null || array.length == 0) { throw new IllegalArgumentException("Input array is null or empty"); } int[] jumping = new int[array.length - 1]; for (int i = jumping.length - 1; i >= 0; i--) { if (array[i] < 0) { throw new IllegalArg... |
### Question:
Bishop { public static int findShortestWay(String start, String end) { if (start == null || !BOARD_CELL_PATTERN.matcher(start).matches()) { throw new IllegalArgumentException("Start position should be 2-char string [a-h][1-8], not " + start); } if (end == null || !BOARD_CELL_PATTERN.matcher(end).matches()... |
### Question:
StockPrices { public static int findBenefit(int[] prices) { if (prices == null || prices.length < 2) { throw new IllegalArgumentException("Prices cannot be null or with length less than 2"); } int[] min = new int[prices.length]; int[] max = new int[prices.length]; min[0] = prices[0]; max[prices.length - 1... |
### Question:
TreeContainsSubtree { public static boolean containsTree(BinaryTree haystack, BinaryTree needle) { if ((haystack == needle) || (needle == null)) { return true; } return subTree(haystack, needle); } static boolean containsTree(BinaryTree haystack, BinaryTree needle); }### Answer:
@Test public void testCo... |
### Question:
AbsoluteDifferenceInTwoSortedArrays { public static Triple findMinimumDifference(int[] first, int[] second) { if (first == null || first.length == 0) { throw new IllegalArgumentException("First array is null or empty"); } if (second == null || second.length == 0) { throw new IllegalArgumentException("Seco... |
### Question:
LongestConsecutiveNumbers { public static int[] findLongestConsecutiveNumbers(int[] sequence) { if (sequence == null || sequence.length == 0) { throw new IllegalArgumentException("Input sequence is null or empty"); } Arrays.sort(sequence); int longest = 0; int i = 0; int start = -1; int end = -1; while (i... |
### Question:
BSTFromInOrderAndPreOrder { public static BinarySearchTree constructTree(int[] inOrder, int[] preOrder) { if (inOrder == null || inOrder.length == 0) { throw new IllegalArgumentException("InOrder array cannot be null or empty"); } if (preOrder == null || preOrder.length == 0) { throw new IllegalArgumentEx... |
### Question:
StackWithQuickMinOperation { public Integer peekMin() { return minStack.peekFirst(); } StackWithQuickMinOperation(); void push(Integer value); Integer pop(); Integer peek(); Integer peekMin(); int size(); }### Answer:
@Test public void testPeekMin() { StackWithQuickMinOperation stack = new StackWithQuick... |
### Question:
Trie { public boolean insertWord(String s) { if (s == null) { throw new IllegalArgumentException("Input string is null"); } TrieNode node = parent; for (int i = 0; i < s.length(); i++) { node = node.getChild(s.charAt(i)); } if (node.endOfWord) { return false; } node.endOfWord = true; size++; return true; ... |
### Question:
Trie { public int getSize() { return size; } Trie(); boolean insertWord(String s); boolean containsWord(String s); boolean containsAsPrefix(String s); boolean containsPrefixOf(String s); int getSize(); }### Answer:
@Test public void testGetSizeEmptyTrie() { Trie trie = new Trie(); assertThat(trie.getSize... |
### Question:
Knight { public static int findShortestWay(String start, String end) { if (start == null || !BOARD_CELL_PATTERN.matcher(start).matches()) { throw new IllegalArgumentException("Start position should be 2-char string [a-h][1-8], not " + start); } if (end == null || !BOARD_CELL_PATTERN.matcher(end).matches()... |
### Question:
DictionaryWordsInTiles { public static String[] findDictionaryWords(String tiles, String[] dictionary) { if (tiles == null || tiles.isEmpty() || dictionary == null || dictionary.length == 0) { return new String[0]; } Map<Character, Integer> tilesMap = new HashMap<>(); for (int i = 0; i < tiles.length(); i... |
### Question:
MultithreadedSumCalculation { public static long getSum(final long[] array, int nThreads) { if (array == null) { throw new IllegalArgumentException("Input array should be not null"); } if (nThreads <= 0) { throw new IllegalArgumentException("Number of threads should be positive"); } if (array.length == 0)... |
### Question:
LRUCache extends LinkedHashMap<K, V> { public int getMaxSize() { return maxSize; } LRUCache(int maxSize); int getMaxSize(); }### Answer:
@Test public void testLRUCachePut() { LRUCache<String, Integer> cache = new LRUCache<String, Integer>(5); assertThat(cache.getMaxSize(), is(5)); cache.put("1", 1); cach... |
### Question:
SimpleSpinlock { public V executeWithSpinLock(Callable<V> e) throws Exception { while (true) { while (alreadyLocked()) { } if (!lock()) { continue; } try { return e.call(); } finally { unlock(); } } } V executeWithSpinLock(Callable<V> e); }### Answer:
@Test public void testExecuteWithSpinlockReturnLong(... |
### Question:
ObjectSizeCalculator { public static long sizeOf(Object o) throws IllegalAccessException { return sizeOf(o, CURRENT_JVM_64_BIT); } static long sizeOf(Object o); static long sizeOf(Object o, boolean jvm64bit); }### Answer:
@Test public void testSizeOf() throws IllegalAccessException { long size64bit = si... |
### Question:
UnionFind { public int find(int i) { if (i < 0 || i >= n) { throw new IllegalArgumentException("Input element " + "should be between 0 (inclusive) " + "and " + n + " (exclusive)"); } while (i != roots[i]) { roots[i] = roots[roots[i]]; i = roots[i]; } return i; } UnionFind(int n); int find(int i); int unio... |
### Question:
UnionFind { public int union(int i, int j) { int firstRoot = find(i); int secondRoot = find(j); if (firstRoot == secondRoot) { return firstRoot; } if (ranks[firstRoot] < ranks[secondRoot]) { roots[firstRoot] = secondRoot; sizes[secondRoot] += sizes[firstRoot]; } else if (ranks[firstRoot] > ranks[secondRoo... |
### Question:
UnionFind { public int getSubsetSize(int i) { return sizes[find(i)]; } UnionFind(int n); int find(int i); int union(int i, int j); int getSubsetSize(int i); int getSubsetsCount(); }### Answer:
@Test(expected = IllegalArgumentException.class) public void testSubsetSizeIllegalArgument1() { UnionFind unionF... |
### Question:
NumberUtils { public static List<long[]> findFactoring(long b) { List<long[]> divs = new ArrayList<>(); if (BigInteger.valueOf(b).isProbablePrime(100)) { divs.add(new long[]{b, 1}); return divs; } for (long i = 2; i <= b; i++) { if (b % i == 0) { int deg = 0; while (b % i == 0) { deg++; b /= i; } divs.add... |
### Question:
BasicEditDistance { public static double getEditDistance(CharSequence s, CharSequence t) { return getEditDistance(s, t, DEFAULT_OPERATIONS_WEIGHTS); } private BasicEditDistance(); static double getEditDistance(CharSequence s, CharSequence t); static double getEditDistance(CharSequence s,
... |
### Question:
SequenceOfDivisibleNumbers { public static BigInteger getNthNumber(int n) { if (n <= 0) { throw new IllegalArgumentException("Input parameter should be positive"); } TreeSet<BigInteger> set = new TreeSet<>(); set.add(ONE); BigInteger nthNumber = ONE; while (n > 0) { nthNumber = set.ceiling(nthNumber); set... |
### Question:
GraphAlgorithms { public static UndirectedGraph getMinimumSpanningTree(UndirectedGraph graph) { if (graph == null) { throw new IllegalArgumentException("Input graph should be not null"); } List<Edge> edges = new ArrayList<>(graph.getEdgeCount()); for (int i = 0; i < graph.getVertexCount(); i++) { Iterator... |
### Question:
SegmentTreeMin { public void addValue(int left, int right, int value) { if (left < 0 || right > size) { throw new IllegalArgumentException( "Input left and round bounds should be between zero and segment tree size"); } if (right <= left) { throw new IllegalArgumentException( "Input right bound should be g... |
### Question:
SegmentTreeSum { public void addValue(int left, int right, long value) { if (left < 0 || right > size) { throw new IllegalArgumentException( "Input left and round bounds should be between zero and segment tree size"); } if (right <= left) { throw new IllegalArgumentException( "Input right bound should be ... |
### Question:
ThreeArraysInAscendingOrder { public static int getMinimumSum(int[] a, int[] b, int[] c) { if ((a == null) || (a.length == 0)) { throw new IllegalArgumentException("First array is null or empty"); } if ((b == null) || (b.length == 0)) { throw new IllegalArgumentException("Second array is null or empty"); ... |
### Question:
MovingSpacesToStartOfString { public static void moveSpaces(char[] str) { if (str == null || str.length == 0) { return; } int i = str.length - 1; int j = str.length - 1; while (i >= 0) { if (str[i] == ' ') { i--; continue; } if (i < j) { char t = str[i]; str[i] = str[j]; str[j] = t; } i--; j--; } while (j... |
### Question:
LeastDifferenceInArrayWithGivenNumber { public static int getElementWithLeastDifference(int[] sequence, int element) { if (sequence == null || sequence.length == 0) { throw new IllegalArgumentException("Input array is null or empty"); } int left = 0; int right = sequence.length - 1; while (left < right) {... |
### Question:
LeftmostElementOfEachLevelInBinaryTree { public static List<Integer> findLeftmostElements(BinaryTree root) { if (root == null) { throw new IllegalArgumentException("Input tree is null"); } ArrayList<Integer> values = new ArrayList<>(); Queue<Object[]> queue = new LinkedList<>(); queue.add(new Object[]{roo... |
### Question:
MajorityVoteAlgorithm { public static int findMajorityElement(int[] sequence) { if (sequence == null || sequence.length == 0) { throw new IllegalArgumentException("Input array is null or empty"); } int cnt = 0; int currentElement = 0; for (int element : sequence) { if (cnt == 0) { currentElement = element... |
### Question:
ConvertNumberToExcelNumber { public static String convert(int n) { if (n <= 0) { throw new IllegalArgumentException("Argument is not positive"); } StringBuilder builder = new StringBuilder(); while (n > 0) { n--; int remainder = n % 26; n /= 26; builder.append((char) (remainder + 65)); } return builder.re... |
### Question:
SumOfTwoSquares { public static int findNumberOfWays(int value) { if (value < 0) { return 0; } if (value <= 1) { return 1; } int left = 0; int right = (int) Math.sqrt(value); int numberOfWays = 0; while (left <= right) { long sum = (left + 0L) * left + (right + 0L) * right; if (sum < value) { left++; } el... |
### Question:
GenerateWhile extends LoopGenerator<E> { @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof GenerateWhile<?>)) { return false; } GenerateWhile<?> other = (GenerateWhile<?>) obj; return other.getWrappedGenerator().equals(getWrappedGenerator()) && other.test... |
### Question:
IteratorToGeneratorAdapter extends LoopGenerator<E> { @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof IteratorToGeneratorAdapter<?>)) { return false; } IteratorToGeneratorAdapter<?> that = (IteratorToGeneratorAdapter<?>) obj; return this.iter.equals(tha... |
### Question:
LoopGenerator extends BaseGenerator<E> { public void stop() { if (wrappedGenerator != null && wrappedGenerator instanceof LoopGenerator<?>) { ((LoopGenerator<?>) wrappedGenerator).stop(); } stopped = true; } LoopGenerator(); LoopGenerator(Generator<? extends E> generator); void stop(); boolean isStopped(... |
### Question:
GenerateUntil extends LoopGenerator<E> { @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof GenerateUntil<?>)) { return false; } GenerateUntil<?> other = (GenerateUntil<?>) obj; return other.getWrappedGenerator().equals(getWrappedGenerator()) && other.test... |
### Question:
GenerateUntil extends LoopGenerator<E> { @Override public int hashCode() { int result = "GenerateUntil".hashCode(); result <<= 2; Generator<?> gen = getWrappedGenerator(); result ^= gen.hashCode(); result <<= 2; result ^= test.hashCode(); return result; } GenerateUntil(Generator<? extends E> wrapped, Pred... |
### Question:
TransformedGenerator extends LoopGenerator<E> { @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof TransformedGenerator<?, ?>)) { return false; } TransformedGenerator<?, ?> other = (TransformedGenerator<?, ?>) obj; return other.getWrappedGenerator().equals... |
### Question:
TransformedGenerator extends LoopGenerator<E> { @Override public int hashCode() { int result = "TransformedGenerator".hashCode(); result <<= 2; Generator<?> gen = getWrappedGenerator(); result ^= gen.hashCode(); result <<= 2; result ^= func.hashCode(); return result; } @SuppressWarnings("unchecked") Tran... |
### Question:
TransformedGenerator extends LoopGenerator<E> { @SuppressWarnings("unchecked") public void run(final Procedure<? super E> proc) { ((Generator<? extends I>) getWrappedGenerator()).run(new Procedure<I>() { public void run(I obj) { proc.run(func.evaluate(obj)); } }); } @SuppressWarnings("unchecked") Transfo... |
### Question:
BaseGenerator implements Generator<E> { public final <T> T to(Function<Generator<? extends E>, ? extends T> transformer) { return transformer.evaluate(this); } BaseGenerator(); final T to(Function<Generator<? extends E>, ? extends T> transformer); final C to(C collection); final Collection<E> toCollection... |
### Question:
EachElement { public static <E> Generator<E> from(Iterable<? extends E> iterable) { return iterable == null ? null : EachElement.from(iterable.iterator()); } private EachElement(); static Generator<E> from(Iterable<? extends E> iterable); @SuppressWarnings("unchecked") static Generator<Map.Entry<K, V>> f... |
### Question:
Offset implements NullaryPredicate, Predicate<Object>,
BinaryPredicate<Object, Object> { public boolean test() { if (state.get() < min) { state.incrementAndGet(); return false; } return true; } Offset(int count); boolean test(); boolean test(Object obj); boolean test(Object a, Object b); @Override... |
### Question:
GenerateWhile extends LoopGenerator<E> { @Override public int hashCode() { int result = "GenerateWhile".hashCode(); result <<= 2; Generator<?> gen = getWrappedGenerator(); result ^= gen.hashCode(); result <<= 2; result ^= test.hashCode(); return result; } GenerateWhile(Generator<? extends E> wrapped, Pred... |
### Question:
Offset implements NullaryPredicate, Predicate<Object>,
BinaryPredicate<Object, Object> { @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof Offset)) { return false; } Offset other = (Offset) obj; return other.min == min; } Offset(int count); boolea... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.