method2testcases stringlengths 118 6.63k |
|---|
### Question:
JsonUtil { public static String toJson(long[] ids) { StringBuilder sb = new StringBuilder(); sb.append("["); if (ids != null) { for (int i = 0; i < ids.length; i++) { if (i > 0) { sb.append(", "); } sb.append(ids[i]); } } sb.append("]"); return sb.toString(); } static String toJsonStr(String value); stat... |
### Question:
MemCacheTemplate implements CacheAble<T> { @Override public boolean set(String key, T value) { return set(key, value, expireTime); } @Override T get(String key); @Override Map<String, T> getMulti(String[] keys); @Override boolean set(String key, T value); @Override boolean set(String key, T value, Date e... |
### Question:
MD5Util { public static String md5(String src) { return md5(src.getBytes()); } static String md5(String src); static String md5(byte[] bytes); static String encodeHex(byte[] bytes); static String md5(long[] array); static byte[] long2Byte(long[] longArray); static void main(String[] args); }### Answer:
... |
### Question:
Crc32Util { public static long getCrc32(byte[] b) { CRC32 crc = crc32Provider.get(); crc.reset(); crc.update(b); return crc.getValue(); } static long getCrc32(byte[] b); static long getCrc32(String str); static void main(String[] args); }### Answer:
@Test public void testCrc32() { long h = Crc32Util.get... |
### Question:
ArrayUtil { public static int[] toRawIntArr(String strArr[]) { int[] intArr = new int[strArr.length]; for (int i = 0; i < strArr.length; i++) { intArr[i] = Integer.parseInt(strArr[i]); } return intArr; } private ArrayUtil(); static Long[] toLongArr(String[] strArr); static Long[] toLongArr(long[] longArr... |
### Question:
ArrayUtil { public static long[] reverseCopy(long[] original, int newLength) { long[] result = new long[newLength]; int originalLimit = original.length - newLength; for (int i = original.length - 1, resultIdx = 0; i >= originalLimit; i--) { result[resultIdx++] = original[i]; } return result; } private Ar... |
### Question:
ArrayUtil { public static long[] sort(long left[], long right[]) { long[] result = addTo(left, right); Arrays.sort(result); return result; } private ArrayUtil(); static Long[] toLongArr(String[] strArr); static Long[] toLongArr(long[] longArr); static long[] toRawLongArr(String[] strArr); static int[] to... |
### Question:
ArrayUtil { public static void sortDesc(long[] a) { Arrays.sort(a); reverse(a); } private ArrayUtil(); static Long[] toLongArr(String[] strArr); static Long[] toLongArr(long[] longArr); static long[] toRawLongArr(String[] strArr); static int[] toRawIntArr(String strArr[]); static long[] toLongArr(Collect... |
### Question:
ArrayUtil { public static long[] addTo(long[] left, long[] right){ if (left == null) { return ArrayUtils.clone(right); } else if (right == null) { return ArrayUtils.clone(left); } long[] result = new long[left.length + right.length]; int pos = 0; System.arraycopy(left, 0, result, pos, left.length); pos +=... |
### Question:
ArrayUtil { public static long[] getLimited(long[] arr, int limit) { if (arr == null) { return arr; } if (arr.length > limit) { long[] result = new long[limit]; System.arraycopy(arr, arr.length - limit, result, 0, limit); return result; } else { return arr; } } private ArrayUtil(); static Long[] toLongAr... |
### Question:
MemCacheTemplate implements CacheAble<T> { @Override public boolean delete(String key) { boolean rs = delete(key, master); if (rs == false) { return rs; } if(slave != null){ delete(key, slave); } delete(key, masterL1List); delete(key, slaveL1List); return rs; } @Override T get(String key); @Override Map<... |
### Question:
Util { public static int convertInt(Object obj) { return convertInt(obj, 0); } static String toStr(byte[] data); static byte[] toBytes(String str); static double convertDouble(String src); static double convertDouble(String src, double defaultValue); static int convertInt(Object obj); static int convertI... |
### Question:
Util { public static long convertLong(String src) { return convertLong(src, 0); } static String toStr(byte[] data); static byte[] toBytes(String str); static double convertDouble(String src); static double convertDouble(String src, double defaultValue); static int convertInt(Object obj); static int conve... |
### Question:
Util { public static String urlEncoder(String s, String charcoding) { if (s == null) return null; try { return URLEncoder.encode(s, charcoding); } catch (Exception e) { } return null; } static String toStr(byte[] data); static byte[] toBytes(String str); static double convertDouble(String src); static do... |
### Question:
Util { public static String urlDecoder(String s, String charcoding) { if (s == null) return null; try { return URLDecoder.decode(s, charcoding); } catch (Exception e) { } return null; } static String toStr(byte[] data); static byte[] toBytes(String str); static double convertDouble(String src); static do... |
### Question:
Util { public static String htmlEscapeOnce(String s) { if (StringUtils.isBlank(s)){ return s; } s = s.replaceAll("&", "&"); s = s.replaceAll("<", "<"); s = s.replaceAll(">", ">"); s = s.replaceAll("\"", """); return s; } static String toStr(byte[] data); static byte[] toBytes(String str); ... |
### Question:
Util { public static String htmlUnEscapeOnce(String s) { if (StringUtils.isBlank(s)){ return s; } s = s.replaceAll("&", "&"); s = s.replaceAll("<", "<"); s = s.replaceAll(">", ">"); s = s.replaceAll(""", "\""); return s; } static String toStr(byte[] data); static byte[] toBytes(String str)... |
### Question:
MemCacheTemplate implements CacheAble<T> { @Override public boolean cas(String key, CasValue<T> casValue) { boolean result = cas(key, casValue, expireTime); if (result == false) { ApiLogger.warn("MemCacheTemplate cas key:" + key + ", result:" + result); } return result; } @Override T get(String key); @Ov... |
### Question:
IpUtil { public static boolean isIp(String in){ if(in==null){ return false; } return ipPattern.matcher(in).matches(); } static String intToIp(int i); static int ipToInt(final String addr); static long ipToLong(final String addr); static String longToIp(long i); static boolean isIp(String in); static Map<... |
### Question:
IpUtil { public static int ipToInt(final String addr) { final String[] addressBytes = addr.split("\\."); int ip = 0; for (int i = 0; i < 4; i++) { ip <<= 8; ip |= Integer.parseInt(addressBytes[i]); } return ip; } static String intToIp(int i); static int ipToInt(final String addr); static long ipToLong(fi... |
### Question:
IpUtil { public static String getLocalIp() { Map<String,String> ips = getLocalIps(); List<String> faceNames = new ArrayList<String>(ips.keySet()); Collections.sort(faceNames); for(String name:faceNames){ if("lo".equals(name)){ continue; } String ip = ips.get(name); if(!StringUtils.isBlank(ip)){ return ip;... |
### Question:
IpUtil { public static int ramdomAvailablePort(){ int port = 0; do{ port = (int) ((MAX_USER_PORT_NUMBER-MIN_USER_PORT_NUMBER) * Math.random())+MIN_USER_PORT_NUMBER; }while(!availablePort(port)); return port; } static String intToIp(int i); static int ipToInt(final String addr); static long ipToLong(final... |
### Question:
HashUtil { public static int getHash(long id, int splitCount, String hashAlg) { return getHash(id, splitCount, hashAlg, NoneHash.NEW); } static int getHash(long id, int splitCount, String hashAlg); static int getHash(long id, int splitCount, String hashAlg, String noneHash); }### Answer:
@Test public vo... |
### Question:
DateUtil { public static String formateDateTime(Date date){ return dateTimeSdf.get().format(date); } static String getYearMonth(Date date); static String formateYearMonthDay(Date date); static Date parseYearMonthDay(String timeStr, Date defaultValue); static String formateDateTime(Date date); static Date... |
### Question:
DateUtil { public static Date parseDateTime(String timeStr, Date defaultValue){ if(timeStr == null){ return defaultValue; } try { return dateTimeSdf.get().parse(timeStr); } catch (ParseException e) { return defaultValue; } } static String getYearMonth(Date date); static String formateYearMonthDay(Date da... |
### Question:
DateUtil { public static String getYearMonth(Date date){ return yearMonthSdf.get().format(date); } static String getYearMonth(Date date); static String formateYearMonthDay(Date date); static Date parseYearMonthDay(String timeStr, Date defaultValue); static String formateDateTime(Date date); static Date p... |
### Question:
ApacheHttpClient implements ApiHttpClient { @Deprecated public String requestURL(String url, Map<String, ?> nameValues) { if(HttpManager.isBlockResource(url)){ debug("requestURL blockResource url="+url); return null; } ByteArrayOutputStream out = new ByteArrayOutputStream(); String result = null; try { lo... |
### Question:
DateUtil { public static String formateYearMonthDay(Date date){ return yearMonthDaySdf.get().format(date); } static String getYearMonth(Date date); static String formateYearMonthDay(Date date); static Date parseYearMonthDay(String timeStr, Date defaultValue); static String formateDateTime(Date date); sta... |
### Question:
DateUtil { public static Date parseYearMonthDay(String timeStr, Date defaultValue){ if(timeStr == null){ return defaultValue; } try { return yearMonthDaySdf.get().parse(timeStr); } catch (ParseException e) { return defaultValue; } } static String getYearMonth(Date date); static String formateYearMonthDay... |
### Question:
DateUtil { public static Date getFirstDayInMonth(Date date){ Calendar calendar = Calendar.getInstance(); if(date != null){ calendar.setTime(date); } calendar.set(Calendar.DAY_OF_MONTH, 1); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); return cal... |
### Question:
DateUtil { public static boolean isCurrentMonth(Date date){ if(date != null){ Calendar dest = Calendar.getInstance(); dest.setTime(date); Calendar now = Calendar.getInstance(); return now.get(Calendar.YEAR) == dest.get(Calendar.YEAR) && now.get(Calendar.MONTH) == dest.get(Calendar.MONTH); } return false; ... |
### Question:
StandardThreadExecutor extends java.util.concurrent.AbstractExecutorService { public StandardThreadExecutor(){ this(DEFAULT_MIN_SPARE_THREADS,DEFAULT_MAX_THREADS); } StandardThreadExecutor(); StandardThreadExecutor(int minSpareThreads,int maxThreads); StandardThreadExecutor(int minSpareThreads,int maxTh... |
### Question:
StandardThreadExecutor extends java.util.concurrent.AbstractExecutorService { public int getPoolSize() { return executor.getPoolSize(); } StandardThreadExecutor(); StandardThreadExecutor(int minSpareThreads,int maxThreads); StandardThreadExecutor(int minSpareThreads,int maxThreads,int taskQueueCapacity)... |
### Question:
ApacheHttpClient implements ApiHttpClient { @Override public String get(String url) { return get(url,DEFAULT_CHARSET); } ApacheHttpClient(); ApacheHttpClient(int maxConPerHost, int conTimeOutMs, int soTimeOutMs, int maxSize); ApacheHttpClient(int maxConPerHost, int conTimeOutMs, int soTimeOutMs, int max... |
### Question:
ApacheHttpClient implements ApiHttpClient { @Override public String post(String url, Map<String, ?> nameValues) { return post(url,nameValues,DEFAULT_CHARSET); } ApacheHttpClient(); ApacheHttpClient(int maxConPerHost, int conTimeOutMs, int soTimeOutMs, int maxSize); ApacheHttpClient(int maxConPerHost, in... |
### Question:
LoginViewModel extends BaseViewModel { public void login() { if (InputHelper.isEmpty(userName) || InputHelper.isEmpty(password)) { AlertUtils.showToastShortMessage(App.getInstance(), "Please input username and password!"); return; } String auth = StringUtils.getBasicAuth(userName, password); execute(true,... |
### Question:
GirlService { public Girl findOne(Integer id) { return girlRepository.findOne(id); } @Transactional void insertTwo(); void getAge(Integer id); Girl findOne(Integer id); }### Answer:
@Test public void findOne() throws Exception { Girl girl = girlService.findOne(19); Assert.assertEquals(new Integer(14), g... |
### Question:
GirlController { @GetMapping(value = "/girls") public List<Girl> girlList() { logger.info("girlList"); return girlRepository.findAll(); } @GetMapping(value = "/girls") List<Girl> girlList(); @PostMapping(value = "/girls") Object girlAdd(@Valid Girl girl, BindingResult bindingResult); @GetMapping(value = ... |
### Question:
RedisLockUtil { public static boolean tryGetDistributedLock(Jedis jedis, String lockKey, String requestId, int expireTime) { String result = jedis.set(lockKey, requestId, SET_IF_NOT_EXIST, SET_WITH_EXPIRE_TIME_UNIT, expireTime); return LOCK_SUCCESS.equals(result); } static boolean tryGetDistributedLock(J... |
### Question:
RedisLockUtil { public static boolean releaseDistributedLock(Jedis jedis, String lockKey, String requestId) { String script = "if redis.call('get', KEYS[1]) == ARGV[1] then return redis.call('del', KEYS[1]) else return 0 end"; Object result = jedis.eval(script, Collections.singletonList(lockKey), Collecti... |
### Question:
HttpUtil { public static String get(String requestUrl) { HttpGet get = new HttpGet(requestUrl); return executeRequest(get, Charset.forName(DEFAULT_ENCODING)); } static String get(String requestUrl); static String post(String requestUrl, Object data, ContentType contentType); static String uploadFile(Stri... |
### Question:
HttpUtil { public static String post(String requestUrl, Object data, ContentType contentType) { if (StringUtils.isBlank(requestUrl)) { throw new RuntimeException("requestUrl cann't be null"); } if (contentType == null) { throw new RuntimeException("contentType cann't be null"); } HttpPost post = new HttpP... |
### Question:
HttpUtil { public static String uploadFile(String requestUrl, Object data) { if (StringUtils.isBlank(requestUrl)) { throw new RuntimeException("requestUrl cann't be null"); } MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create().setCharset(Charset.forName(DEFAULT_ENCODING)); Cont... |
### Question:
ImageUtil { public static List<String> generateThumbnail2Directory(String path, String... files) throws IOException { return generateThumbnail2Directory(DEFAULT_SCALE, path, files); } static List<String> generateThumbnail2Directory(String path, String... files); static List<String> generateThumbnail2Dire... |
### Question:
ImageUtil { public static void generateDirectoryThumbnail(String pathname) throws IOException { generateDirectoryThumbnail(pathname, DEFAULT_SCALE); } static List<String> generateThumbnail2Directory(String path, String... files); static List<String> generateThumbnail2Directory(double scale, String pathna... |
### Question:
ReflectionUtil { public static @NotNull List<String> getArgsForMethod(@NotNull List<String> args, @NotNull Method method) { if (args.size() == 0 && method.getParameterCount() == 0) { return Collections.emptyList(); } List<String> argsOut = new ArrayList<>(); if (args.size() < method.getParameterCount()) {... |
### Question:
TypeHandler { public @NotNull Object[] instantiateTypes(Class<?>[] classes, List<String> input) throws InputException { return instantiateTypes(classes, input, null); } TypeHandler(Logger logger); @Nullable String getOutputFor(@Nullable Object object); @NotNull Object[] instantiateTypes(Class<?>[] classes... |
### Question:
TypeHandler { public @Nullable String getOutputFor(@Nullable Object object) { if (object == null) { return null; } OHandler handler = getOHandlerForClass(object.getClass()); if (handler != null) { return handler.getFormattedOutput(object); } else { return String.valueOf(object); } } TypeHandler(Logger log... |
### Question:
ReflectionUtil { public static @NotNull String getMethodId(Method method) { return getFormattedMethodSignature(method).replaceAll(" ", ""); } static @NotNull List<String> getArgsForMethod(@NotNull List<String> args, @NotNull Method method); static @NotNull String getFormattedMethodSignature(Method method... |
### Question:
ReflectionUtil { public static @NotNull String getArgMismatchString(Method method) { final String methodName = method.getName(); final Class<?> returnType = method.getReturnType(); final String returnTypeName = returnType.getSimpleName(); String returnInfo; if (returnType.equals(Void.TYPE)) { returnInfo =... |
### Question:
MethodMap { public @NotNull Set<Method> getAllMethods() { return new HashSet<>(backingMap.values()); } private MethodMap(); MethodMap(@NotNull Class<?> clazz); @Nullable Method getById(String identifier); boolean containsId(String identifier); @NotNull Set<Method> getAllMethods(); @NotNull Set<String> ... |
### Question:
MethodMap { public @NotNull Set<String> getAllIds() { return new HashSet<>(backingMap.keySet()); } private MethodMap(); MethodMap(@NotNull Class<?> clazz); @Nullable Method getById(String identifier); boolean containsId(String identifier); @NotNull Set<Method> getAllMethods(); @NotNull Set<String> getA... |
### Question:
MethodMap { @Override public int hashCode() { return 67 * backingMap.hashCode(); } private MethodMap(); MethodMap(@NotNull Class<?> clazz); @Nullable Method getById(String identifier); boolean containsId(String identifier); @NotNull Set<Method> getAllMethods(); @NotNull Set<String> getAllIds(); @NotNul... |
### Question:
FileDownloader { public static void setup(Context context) { FileDownloadHelper.holdContext(context.getApplicationContext()); } static void setup(Context context); static DownloadMgrInitialParams.InitCustomMaker setupOnApplicationOnCreate(Application application); static void init(final Context context);... |
### Question:
FileDownloader { public static DownloadMgrInitialParams.InitCustomMaker setupOnApplicationOnCreate(Application application) { final Context context = application.getApplicationContext(); FileDownloadHelper.holdContext(context); DownloadMgrInitialParams.InitCustomMaker customMaker = new DownloadMgrInitialP... |
### Question:
DownloadRunnable implements Runnable { @Override public void run() { Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); FileDownloadConnection connection = null; final long beginOffset = connectTask.getProfile().currentOffset; boolean isConnected = false; do { try { if (paused) { return; } isC... |
### Question:
ErrorParser { @NonNull static StripeError parseError(String rawError) { StripeError stripeError = new StripeError(); try { JSONObject jsonError = new JSONObject(rawError); JSONObject errorObject = jsonError.getJSONObject(FIELD_ERROR); stripeError.charge = errorObject.optString(FIELD_CHARGE); stripeError.c... |
### Question:
ModelUtils { static boolean isWholePositiveNumber(@Nullable String value) { return value != null && TextUtils.isDigitsOnly(value); } }### Answer:
@Test public void wholePositiveNumberShouldPassWithLeadingZero() { assertTrue(ModelUtils.isWholePositiveNumber("000")); }
@Test public void wholePositiveNumb... |
### Question:
ModelUtils { static int normalizeYear(int year, Calendar now) { if (year < 100 && year >= 0) { String currentYear = String.valueOf(now.get(Calendar.YEAR)); String prefix = currentYear.substring(0, currentYear.length() - 2); year = Integer.parseInt(String.format(Locale.US, "%s%02d", prefix, year)); } retur... |
### Question:
SourceCodeVerification extends StripeJsonModel { @NonNull @Override public JSONObject toJson() { JSONObject jsonObject = new JSONObject(); try{ jsonObject.put(FIELD_ATTEMPTS_REMAINING, mAttemptsRemaining); StripeJsonUtils.putStringIfNotNull(jsonObject, FIELD_STATUS, mStatus); } catch (JSONException ignore... |
### Question:
SourceCodeVerification extends StripeJsonModel { @NonNull @Override public Map<String, Object> toMap() { Map<String, Object> hashMap = new HashMap<>(); hashMap.put(FIELD_ATTEMPTS_REMAINING, mAttemptsRemaining); if (mStatus != null) { hashMap.put(FIELD_STATUS, mStatus); } return hashMap; } SourceCodeVerifi... |
### Question:
SourceReceiver extends StripeJsonModel { @NonNull @Override public JSONObject toJson() { JSONObject jsonObject = new JSONObject(); StripeJsonUtils.putStringIfNotNull(jsonObject, FIELD_ADDRESS, mAddress); try { jsonObject.put(FIELD_AMOUNT_CHARGED, mAmountCharged); jsonObject.put(FIELD_AMOUNT_RECEIVED, mAmo... |
### Question:
SourceReceiver extends StripeJsonModel { @NonNull @Override public Map<String, Object> toMap() { Map<String, Object> hashMap = new HashMap<>(); if (!StripeTextUtils.isBlank(mAddress)) { hashMap.put(FIELD_ADDRESS, mAddress); } hashMap.put(FIELD_ADDRESS, mAddress); hashMap.put(FIELD_AMOUNT_CHARGED, mAmountC... |
### Question:
StripeSourceTypeModel extends StripeJsonModel { @Nullable static Map<String, Object> jsonObjectToMapWithoutKeys( @Nullable JSONObject jsonObject, @Nullable Set<String> omitKeys) { if (jsonObject == null) { return null; } Set<String> keysToOmit = omitKeys == null ? new HashSet<String>() : omitKeys; Map<Str... |
### Question:
StripeJsonUtils { @Nullable static String getString( @NonNull JSONObject jsonObject, @NonNull @Size(min = 1) String fieldName) throws JSONException { return nullIfNullOrEmpty(jsonObject.getString(fieldName)); } }### Answer:
@Test public void getString_whenFieldContainsRawNull_returnsNull() { JSONObject... |
### Question:
StripeSourceTypeModel extends StripeJsonModel { static void putAdditionalFieldsIntoJsonObject( @Nullable JSONObject jsonObject, @Nullable Map<String, Object> additionalFields) { if (jsonObject == null || additionalFields == null || additionalFields.isEmpty()) { return; } for (String key : additionalFields... |
### Question:
StripeSourceTypeModel extends StripeJsonModel { static void putAdditionalFieldsIntoMap( @Nullable Map<String, Object> map, @Nullable Map<String, Object> additionalFields) { if (map == null || additionalFields == null || additionalFields.isEmpty()) { return; } for(String key : additionalFields.keySet()) { ... |
### Question:
LoggingUtils { static void addNameAndVersion( @NonNull Map<String, Object> paramsObject, @NonNull Context context) { Context applicationContext = context.getApplicationContext(); if (applicationContext != null && applicationContext.getPackageManager() != null) { try { PackageInfo info = applicationContext... |
### Question:
LoggingUtils { @NonNull static String getEventParamName(@NonNull @LoggingEventName String eventName) { return ANALYTICS_NAME + '.' + eventName; } }### Answer:
@Test public void getEventParamName_withTokenCreation_createsExpectedParameter() { final String expectedEventParam = "stripe_android.token_creat... |
### Question:
LoggingUtils { @NonNull static String getAnalyticsUa() { return ANALYTICS_PREFIX + "." + ANALYTICS_NAME + "-" + ANALYTICS_VERSION; } }### Answer:
@Test public void getAnalyticsUa_returnsExpectedValue() { final String androidAnalyticsUserAgent = "analytics.stripe_android-1.0"; assertEquals(androidAnalyt... |
### Question:
CardUtils { @NonNull @Card.CardBrand public static String getPossibleCardType(@Nullable String cardNumber) { return getPossibleCardType(cardNumber, true); } @NonNull @Card.CardBrand static String getPossibleCardType(@Nullable String cardNumber); static boolean isValidCardNumber(@Nullable String cardNumbe... |
### Question:
StripeJsonUtils { @Nullable static String optString( @NonNull JSONObject jsonObject, @NonNull @Size(min = 1) String fieldName) { return nullIfNullOrEmpty(jsonObject.optString(fieldName)); } }### Answer:
@Test public void optString_whenFieldPresent_findsAndReturnsField() { JSONObject jsonObject = new JS... |
### Question:
CardUtils { static boolean isValidCardLength(@Nullable String cardNumber) { return cardNumber != null && isValidCardLength(cardNumber, getPossibleCardType(cardNumber, false)); } @NonNull @Card.CardBrand static String getPossibleCardType(@Nullable String cardNumber); static boolean isValidCardNumber(@Null... |
### Question:
CardUtils { static boolean isValidLuhnNumber(@Nullable String cardNumber) { if (cardNumber == null) { return false; } boolean isOdd = true; int sum = 0; for (int index = cardNumber.length() - 1; index >= 0; index--) { char c = cardNumber.charAt(index); if (!Character.isDigit(c)) { return false; } int digi... |
### Question:
StripeJsonUtils { @Nullable static Map<String, Object> jsonObjectToMap(@Nullable JSONObject jsonObject) { if (jsonObject == null) { return null; } Map<String, Object> map = new HashMap<>(); Iterator<String> keyIterator = jsonObject.keys(); while(keyIterator.hasNext()) { String key = keyIterator.next(); Ob... |
### Question:
MaskedCardView extends LinearLayout { @VisibleForTesting int[] getTextColorValues() { int[] colorValues = new int[4]; colorValues[0] = mSelectedColorInt; colorValues[1] = mSelectedAlphaColorInt; colorValues[2] = mUnselectedTextColorInt; colorValues[3] = mUnselectedTextAlphaColorInt; return colorValues; } ... |
### Question:
SelectShippingMethodWidget extends FrameLayout { public ShippingMethod getSelectedShippingMethod() { return mShippingMethodAdapter.getSelectedShippingMethod(); } SelectShippingMethodWidget(Context context); SelectShippingMethodWidget(Context context, AttributeSet attrs); SelectShippingMethodWidget(Conte... |
### Question:
ExpiryDateEditText extends StripeEditText { public boolean isDateValid() { return mIsDateValid; } ExpiryDateEditText(Context context); ExpiryDateEditText(Context context, AttributeSet attrs); ExpiryDateEditText(Context context, AttributeSet attrs, int defStyleAttr); boolean isDateValid(); @Nullable @Siz... |
### Question:
ExpiryDateEditText extends StripeEditText { @VisibleForTesting int updateSelectionIndex( int newLength, int editActionStart, int editActionAddition) { int newPosition, gapsJumped = 0; boolean skipBack = false; if (editActionStart <= 2 && editActionStart + editActionAddition >= 2) { gapsJumped = 1; } if (e... |
### Question:
ExpiryDateEditText extends StripeEditText { @Nullable @Size(2) public int[] getValidDateFields() { if (!mIsDateValid) { return null; } int [] monthYearPair = new int[2]; String rawNumericInput = getText().toString().replaceAll("/", ""); String[] dateFields = DateUtils.separateDateStringParts(rawNumericInp... |
### Question:
StripeJsonUtils { @Nullable @SuppressWarnings("unchecked") static JSONObject mapToJsonObject(@Nullable Map<String, ? extends Object> mapObject) { if (mapObject == null) { return null; } JSONObject jsonObject = new JSONObject(); for (String key : mapObject.keySet()) { Object value = mapObject.get(key); if ... |
### Question:
StripeJsonUtils { @Nullable @SuppressWarnings("unchecked") static JSONArray listToJsonArray(@Nullable List values) { if (values == null) { return null; } JSONArray jsonArray = new JSONArray(); for (Object object : values) { if (object instanceof Map<?, ?>) { try { Map<String, Object> mapObject = (Map<Stri... |
### Question:
CardNumberEditText extends StripeEditText { public boolean isCardNumberValid() { return mIsCardNumberValid; } CardNumberEditText(Context context); CardNumberEditText(Context context, AttributeSet attrs); CardNumberEditText(Context context, AttributeSet attrs, int defStyleAttr); @NonNull @Card.CardBrand ... |
### Question:
CardNumberEditText extends StripeEditText { @Nullable public String getCardNumber() { return mIsCardNumberValid ? StripeTextUtils.removeSpacesAndHyphens(getText().toString()) : null; } CardNumberEditText(Context context); CardNumberEditText(Context context, AttributeSet attrs); CardNumberEditText(Contex... |
### Question:
StripeJsonUtils { @Nullable static List<Object> jsonArrayToList(@Nullable JSONArray jsonArray) { if (jsonArray == null) { return null; } List<Object> objectList = new ArrayList<>(); for (int i = 0; i < jsonArray.length(); i++) { try { Object ob = jsonArray.get(i); if (ob instanceof JSONArray) { objectList... |
### Question:
StripeEditText extends TextInputEditText { @ColorInt @SuppressWarnings("deprecation") public int getDefaultErrorColorInt() { @ColorInt int errorColor; determineDefaultErrorColor(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { errorColor = getResources().getColor(mDefaultErrorColorResId, null); } ... |
### Question:
PaymentMethodsActivity extends AppCompatActivity { @VisibleForTesting void initializeCustomerSourceData() { Customer cachedCustomer = mCustomerSessionProxy == null ? CustomerSession.getInstance().getCachedCustomer() : mCustomerSessionProxy.getCachedCustomer(); if (cachedCustomer != null) { mCustomer = cac... |
### Question:
CardMultilineWidget extends LinearLayout { @Nullable public Card getCard() { if (validateAllFields()) { String cardNumber = mCardNumberEditText.getCardNumber(); int[] cardDate = mExpiryDateEditText.getValidDateFields(); String cvcValue = mCvcEditText.getText().toString(); Card card = new Card(cardNumber, ... |
### Question:
CardMultilineWidget extends LinearLayout { static boolean isPostalCodeMaximalLength(boolean isZip, @Nullable String text) { return isZip && text != null && text.length() == 5; } CardMultilineWidget(Context context); CardMultilineWidget(Context context, AttributeSet attrs); CardMultilineWidget(Context co... |
### Question:
CardMultilineWidget extends LinearLayout { public void clear() { mCardNumberEditText.setText(""); mExpiryDateEditText.setText(""); mCvcEditText.setText(""); mPostalCodeEditText.setText(""); mCardNumberEditText.setShouldShowError(false); mExpiryDateEditText.setShouldShowError(false); mCvcEditText.setShould... |
### Question:
CardMultilineWidget extends LinearLayout { public void setShouldShowPostalCode(boolean shouldShowPostalCode) { mShouldShowPostalCode = shouldShowPostalCode; adjustViewForPostalCodeAttribute(); } CardMultilineWidget(Context context); CardMultilineWidget(Context context, AttributeSet attrs); CardMultiline... |
### Question:
DateUtils { @IntRange(from = 1000, to = 9999) static int convertTwoDigitYearToFour(@IntRange(from = 0, to = 99) int inputYear) { return convertTwoDigitYearToFour(inputYear, Calendar.getInstance()); } }### Answer:
@Test public void convertTwoDigitYearToFour_whenCurrentYearIsLessThanEighty_addsNormalBase... |
### Question:
DateUtils { static String createDateStringFromIntegerInput( @IntRange(from = 1, to = 12) int month, @IntRange(from = 0, to = 9999) int year) { String monthString = String.valueOf(month); if (monthString.length() == 1) { monthString = "0" + monthString; } String yearString = String.valueOf(year); if (yearS... |
### Question:
DateUtils { static boolean isExpiryDataValid(int expiryMonth, int expiryYear) { return isExpiryDataValid(expiryMonth, expiryYear, Calendar.getInstance()); } }### Answer:
@Test public void isExpiryDataValid_whenDateIsAfterCalendarYear_returnsTrue() { Calendar testCalendar = Calendar.getInstance(); testC... |
### Question:
DateUtils { @Size(2) @NonNull static String[] separateDateStringParts(@NonNull @Size(max = 4) String expiryInput) { String[] parts = new String[2]; if (expiryInput.length() >= 2) { parts[0] = expiryInput.substring(0, 2); parts[1] = expiryInput.substring(2); } else { parts[0] = expiryInput; parts[1] = ""; ... |
### Question:
DateUtils { static boolean isValidMonth(@Nullable String monthString) { if (monthString == null) { return false; } try { int monthInt = Integer.parseInt(monthString); return monthInt > 0 && monthInt <= 12; } catch (NumberFormatException numEx) { return false; } } }### Answer:
@Test public void isValidM... |
### Question:
CountryAdapter extends ArrayAdapter { @NonNull @Override public Filter getFilter() { return mFilter; } CountryAdapter(Context context, List<String> countries); @Override int getCount(); @Override String getItem(int i); @Override long getItemId(int i); @Override View getView(int i, View view, ViewGroup vie... |
### Question:
ViewUtils { static TypedValue getThemeAccentColor(Context context) { int colorAttr; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { colorAttr = android.R.attr.colorAccent; } else { colorAttr = context .getResources() .getIdentifier("colorAccent", "attr", context.getPackageName()); } TypedValu... |
### Question:
ViewUtils { static TypedValue getThemeColorControlNormal(Context context) { int colorAttr; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { colorAttr = android.R.attr.colorControlNormal; } else { colorAttr = context .getResources() .getIdentifier("colorControlNormal", "attr", context.getPackag... |
### Question:
ViewUtils { static boolean isColorTransparent(@ColorInt int color) { return Color.alpha(color) < 0x10; } }### Answer:
@Test public void isColorTransparent_whenColorIsZero_returnsTrue() { assertTrue(ViewUtils.isColorTransparent(0)); }
@Test public void isColorTransparent_whenColorIsNonzeroButHasLowAlpha... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.