SimpleDateFormat("yyyy-MM-dd").parse("1984-11-19")); Calendar now = Calendar.getInstance(); int year1 = now.get(Calendar.YEAR); int year2 = birth.get(Calendar.YEAR); int age = year1 - year2; int month1 = now.get(Calendar.MONTH); int month2 = birth.get(Calendar.MONTH); if (month2 > month1) { age--; } else if (month1 == month2) { int day1 = now.get(Calendar.DAY_OF_MONTH); int day2 = birth.get(Calendar.DAY_OF_MONTH); if (day2 > day1) { age--; } } return age; } Calendar
= new ArrayMap<>(); for (Post post : posts) { User user = post.getUser(); users.put(user.getObjectId(), user); } for (Comment comment : comments) { User user = comment.getUser(); users.put(user.getObjectId(), user); } return new ArrayList<>(users.values()); } RxJava
"https://api.github.com/" + "users/" + user + "/repos"; Volley.newRequestQueue(context) .add(new StringRequest(url, res -> { callback.done((List<Repo>) new Gson() .fromJson(res, new TypeToken<List<Repo>>(){}.getType())); }), e -> callback.error(e))); } API Volley
"https://api.github.com/" + "users/" + user + "/repos"; Volley.newRequestQueue(context) .add(new StringRequest(url, res -> { callback.done((List<Repo>) new Gson() .fromJson(res, new TypeToken<List<Repo>>(){}.getType())); }), e -> callback.error(e))); } void getStarredUsers(String repo, final Callback<User> callback)? API Volley
soundcard = computer.getSoundcard(); if (soundcard != null) { USB usb = soundcard.getUSB(); if (usb != null) { version = usb.getVersion(); } } } Null check class USB { String getVersion() {} } class Soundcard { USB getUsb() {} } class Computer { Soundcard getSoundcard() {} }
if second emit Null check RxJava1 class USB { Observable<String> getVersion() {} } class Soundcard { Observable<USB> getUsb() {} } class Computer { Observable<Soundcard> getSoundcard() {} }