List of usage examples for org.joda.time LocalDateTime getMonthOfYear
public int getMonthOfYear()
From source file:com.ramzcalender.sample.Sample.java
License:Apache License
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.sample);/*from w ww. j a v a 2 s . c o m*/ mDateSelectedTv = (TextView) findViewById(R.id.txt_date); rCalendarFragment = new RWeekCalendar(); /*Define you startDate and end Date*/ rCalendarFragment.startDate(1989, 9, 1);//Start date rCalendarFragment.endDate(2018, 12, 31);//Ending date Bundle args = new Bundle(); /*Should add this attribute if you adding the NOW_BACKGROUND or DATE_SELECTOR_BACKGROUND Attribute*/ args.putString(RWeekCalendar.PACKAGENAME, getApplicationContext().getPackageName()); /* IMPORTANT: Customization for the calender commenting or un commenting any of the attribute below will reflect change in calender*/ //---------------------------------------------------------------------------------------------------------------------// //set Calender type you want if you don't set any normal calender will be set if (getIntent().getExtras().getInt(RWeekCalendar.CALENDER_TYPE) == RWeekCalendar.FDF_CALENDER) { /** Set Calender type to FIRSTDAYFIRST (FDF_CALENDER)here * the week days will start as current day as first entry * eg if current day is friday calender start with fri,sat,etc * */ args.putInt(RWeekCalendar.CALENDER_TYPE, RWeekCalendar.FDF_CALENDER); } else { /** * set Calender type to normal here the week days will * start as normal be like Sun,Mon etc * */ args.putInt(RWeekCalendar.CALENDER_TYPE, RWeekCalendar.NORMAL_CALENDER); } // args.putInt(RWeekCalender.CALENDER_BACKGROUND, ContextCompat.getColor(this,R.color.md_pink_700));//set background color to calender args.putString(RWeekCalendar.DATE_SELECTOR_BACKGROUND, "bg_select");//set background to the selected dates // args.putString(RWeekCalender.NOW_BACKGROUND,"bg_now");//set background to nowView // args.putInt(RWeekCalender.CURRENT_DATE_BACKGROUND,ContextCompat.getColor(this,R.color.md_black_1000));//set color to the currentdate // args.putInt(RWeekCalender.PRIMARY_BACKGROUND, ContextCompat.getColor(this,R.color.md_white_1000));//Set color to the primary views (Month name and dates) // args.putInt(RWeekCalender.SECONDARY_BACKGROUND, ContextCompat.getColor(this,R.color.md_green_500));//Set color to the secondary views (now view and week names) //---------------------------------------------------------------------------------------------------------------------// rCalendarFragment.setArguments(args); // Attach to the activity FragmentTransaction t = getSupportFragmentManager().beginTransaction(); t.replace(R.id.container, rCalendarFragment); t.commit(); CalenderListener listener = new CalenderListener() { @Override public void onSelectPicker() { //User can use any type of pickers here the below picker is only Just a example DatePickerDialog .newInstance(Sample.this, Calendar.getInstance().get(Calendar.YEAR), Calendar.getInstance().get(Calendar.MONTH), Calendar.getInstance().get(Calendar.DAY_OF_MONTH)) .show(getFragmentManager(), "datePicker"); } @Override public void onSelectDate(LocalDateTime mSelectedDate) { //callback when a date is selcted mDateSelectedTv.setText("" + mSelectedDate.getDayOfMonth() + "-" + mSelectedDate.getMonthOfYear() + "-" + mSelectedDate.getYear()); } }; //setting the listener rCalendarFragment.setCalenderListener(listener); }
From source file:com.ramzcalender.utils.CalUtil.java
License:Open Source License
/** * Initial calculation of the week// ww w . ja v a 2 s . co m * * @param mStartDate */ public void calculate(LocalDateTime mStartDate, int type) { //Initializing Start with current month final LocalDateTime currentDateTime = mStartDate; setStartDate(currentDateTime.getYear(), currentDateTime.getMonthOfYear(), currentDateTime.getDayOfMonth()); /*Check for difference of weeks for alignment of days*/ int weekGap = CalUtil.mDateGap(currentDateTime.dayOfWeek().getAsText().substring(0, 3).toLowerCase()); if (weekGap != 0) { //If the there is week gap we need to maintain in the calender else alignment will be a mess if (type == RWeekCalendar.FDF_CALENDER) { //If the week gap is in FDF calender first get the current days number of the week int currentWeekNumber = new LocalDateTime().dayOfWeek().get(); //Subtract it with the rest of the days(Week gap) to get the rest of the days weekGap = weekGap - currentWeekNumber; } //This will add the additional days LocalDateTime ldt = mStartDate.minusDays(weekGap); // Set the the new startDate after new calculated days setStartDate(ldt.getYear(), ldt.getMonthOfYear(), ldt.getDayOfMonth()); } else { //Some times the week gap will be zero in that case If the selected calender is FDFCalender if (type == RWeekCalendar.FDF_CALENDER) { //Subtract total days of week (7) with the week day number of current date int currentWeekNumber = 7 - new LocalDateTime().dayOfWeek().get(); if (currentWeekNumber != 0) { // Set the the new startDate after new calculated days LocalDateTime ldt = mStartDate.minusDays(currentWeekNumber); setStartDate(ldt.getYear(), ldt.getMonthOfYear(), ldt.getDayOfMonth()); } } } }
From source file:com.restservice.serviceLogic.ResultLogic.java
License:Open Source License
/** * Request handler for getting the count per hour statistic * Additional logic beyond the transactor database connection to insert additional zeros * for dates where no count (row) has been returned * /*w ww.j a va 2s. c o m*/ * @param id * search term index * @return envelope containing a status message and a search result count * per date DTO * @throws SQLException * @throws ExecutionException * @throws InterruptedException */ public Envelope getCountAndNewsPerHour(Long id, String lang) throws SQLException, InterruptedException, ExecutionException { SearchTermsPerQueryPerDate countsPerDay; Envelope env = new Envelope(); countsPerDay = transactor.getCountPerHour(id, lang); // Fill with zeros ArrayList<Integer> newCounts = new ArrayList<Integer>(); ArrayList<LocalDateTime> newDates = new ArrayList<LocalDateTime>(); if (!countsPerDay.getDates().isEmpty()) { ArrayList<LocalDateTime> oldDates = new ArrayList<>(); for (LocalDateTime curDate : countsPerDay.getDates()) { oldDates.add(new LocalDateTime(curDate.getYear(), curDate.getMonthOfYear(), curDate.getDayOfMonth(), curDate.getHourOfDay(), 0)); } newDates.add(oldDates.get(0)); newCounts.add(countsPerDay.getCounts().get(0)); for (int i = 1; i < oldDates.size(); i++) { if (!oldDates.get(i - 1).plusHours(1).equals(oldDates.get(i))) { LocalDateTime startDate = oldDates.get(i - 1); LocalDateTime endDate = oldDates.get(i); while (!startDate.equals(endDate)) { startDate = startDate.plusHours(1); if (startDate.equals(endDate)) { newDates.add(oldDates.get(i)); newCounts.add(countsPerDay.getCounts().get(i)); } else { newCounts.add(0); newDates.add(startDate); } } } else { newDates.add(oldDates.get(i)); newCounts.add(countsPerDay.getCounts().get(i)); } } } countsPerDay.setCounts(newCounts); countsPerDay.setDates(newDates); countsPerDay.updateDateStrings(); // convert to nice output format CountAndNewsPerHour countAndNews = new CountAndNewsPerHour(); for (Integer index = 0; index < countsPerDay.getCounts().size(); index++) { CountPeaksNewsAndDate element = new CountPeaksNewsAndDate(); element.setRawDate(countsPerDay.getDates().get(index)); element.setCount(countsPerDay.getCounts().get(index)); element.setPeak(false); countAndNews.getGraph().add(element); } countAndNews.setQuery(countsPerDay.getQuery()); // find and marks peaks ArrayList<Integer> peakIndices = PeaksUtil.findPeaks24(countAndNews); for (Integer peakIndex : peakIndices) { countAndNews.getGraph().get(peakIndex).setPeak(true); } if (peakIndices.size() > 0) { // create news fetchers HashMap<Integer, Future<ArrayList<NewsItem>>> newsFetchers = new HashMap<Integer, Future<ArrayList<NewsItem>>>(); ExecutorService executor = Executors.newFixedThreadPool(peakIndices.size()); for (Integer peakIndex : peakIndices) { LocalDateTime date = countAndNews.getGraph().get(peakIndex).getRawDate(); newsFetchers.put(peakIndex, executor.submit( new TopNewsFetcherThread(id, date.getDayOfMonth(), date.getMonthOfYear(), date.getYear()))); } // retrieve news fetchers results executor.shutdown(); java.util.Iterator<Entry<Integer, Future<ArrayList<NewsItem>>>> iterator = newsFetchers.entrySet() .iterator(); while (iterator.hasNext()) { Entry<Integer, Future<ArrayList<NewsItem>>> entry = iterator.next(); ArrayList<NewsItem> result = entry.getValue().get(); if (result != null) { for (NewsItem newsitem : result) { countAndNews.getGraph().get(entry.getKey()).getNews().add(newsitem.toShortString()); } } } } env.setData(countAndNews); return env; }
From source file:com.restservice.serviceLogic.ResultLogic.java
License:Open Source License
/** * Request handler for getting the count per hour statistic * /* w ww . ja v a2 s . c om*/ * @param id * search term index * @param lang * iso language code of the language (all languages are selected * if this parameter is null) * * @return envelope containing a status message and the number of * positive/negative tweets per hour * @throws SQLException */ public Envelope getSentimentPerHour(Long id, String lang) throws SQLException { SentimentPerQueryPerDate data; Envelope env = new Envelope(); // TODO: Filling these zeros shouldn't been done three times (twice // here and once in getCountPerHour). Fix it! See ticket #86 data = transactor.getSentimentPerHour(id, lang); ArrayList<LocalDateTime> oldDatesPositive = new ArrayList<>(); ArrayList<Integer> newCountsPositive = new ArrayList<Integer>(); ArrayList<LocalDateTime> newDatesPositive = new ArrayList<LocalDateTime>(); ArrayList<LocalDateTime> oldDatesNegative = new ArrayList<>(); ArrayList<Integer> newCountsNegative = new ArrayList<Integer>(); ArrayList<LocalDateTime> newDatesNegative = new ArrayList<LocalDateTime>(); // Reset minutes, seconds and miliseconds to 0 if (!data.getPositiveCounts().getDates().isEmpty()) { for (LocalDateTime curDate : data.getPositiveCounts().getDates()) { oldDatesPositive.add(new LocalDateTime(curDate.getYear(), curDate.getMonthOfYear(), curDate.getDayOfMonth(), curDate.getHourOfDay(), 0)); } } if (!data.getNegativeCounts().getDates().isEmpty()) { for (LocalDateTime curDate : data.getNegativeCounts().getDates()) { oldDatesNegative.add(new LocalDateTime(curDate.getYear(), curDate.getMonthOfYear(), curDate.getDayOfMonth(), curDate.getHourOfDay(), 0)); } } // Get first date from both (positive or negative) and fill the // other one with leading zero counts if (!oldDatesPositive.isEmpty() && !oldDatesNegative.isEmpty()) { // The first positive date is earlier than the first negative // date if (oldDatesPositive.get(0).compareTo(oldDatesNegative.get(0)) == -1) { LocalDateTime curDate = oldDatesPositive.get(0); while (!curDate.equals(oldDatesNegative.get(0))) { newCountsNegative.add(0); newDatesNegative.add(curDate); curDate = curDate.plusHours(1); } } // The first negative date is earlier than the first positive // date else if (oldDatesPositive.get(0).compareTo(oldDatesNegative.get(0)) == 1) { LocalDateTime curDate = oldDatesNegative.get(0); while (!curDate.equals(oldDatesPositive.get(0))) { newCountsPositive.add(0); newDatesPositive.add(curDate); curDate = curDate.plusHours(1); } } } // Fill hours that have 0 counts for positive tweets if (!oldDatesPositive.isEmpty()) { newDatesPositive.add(oldDatesPositive.get(0)); newCountsPositive.add(data.getPositiveCounts().getCounts().get(0)); for (int i = 1; i < oldDatesPositive.size(); i++) { if (!oldDatesPositive.get(i - 1).plusHours(1).equals(oldDatesPositive.get(i))) { LocalDateTime startDate = oldDatesPositive.get(i - 1); LocalDateTime endDate = oldDatesPositive.get(i); while (!startDate.equals(endDate)) { startDate = startDate.plusHours(1); if (startDate.equals(endDate)) { newDatesPositive.add(oldDatesPositive.get(i)); newCountsPositive.add(data.getPositiveCounts().getCounts().get(i)); } else { newCountsPositive.add(0); newDatesPositive.add(startDate); } } } else { newDatesPositive.add(oldDatesPositive.get(i)); newCountsPositive.add(data.getPositiveCounts().getCounts().get(i)); } } } // Fill hours that have 0 counts for negative tweets if (!oldDatesNegative.isEmpty()) { newDatesNegative.add(oldDatesNegative.get(0)); newCountsNegative.add(data.getNegativeCounts().getCounts().get(0)); for (int i = 1; i < oldDatesNegative.size(); i++) { if (!oldDatesNegative.get(i - 1).plusHours(1).equals(oldDatesNegative.get(i))) { LocalDateTime startDate = oldDatesNegative.get(i - 1); LocalDateTime endDate = oldDatesNegative.get(i); while (!startDate.equals(endDate)) { startDate = startDate.plusHours(1); if (startDate.equals(endDate)) { newDatesNegative.add(oldDatesNegative.get(i)); newCountsNegative.add(data.getNegativeCounts().getCounts().get(i)); } else { newCountsNegative.add(0); newDatesNegative.add(startDate); } } } else { newDatesNegative.add(oldDatesNegative.get(i)); newCountsNegative.add(data.getNegativeCounts().getCounts().get(i)); } } } // Fill negative with zeros when only positive exists if (!newDatesPositive.isEmpty() && newDatesNegative.isEmpty()) { for (LocalDateTime curDate : newDatesPositive) { newCountsNegative.add(0); newDatesNegative.add(curDate); } } // Fill positive with zeros when only negative exists else if (newDatesPositive.isEmpty() && !newDatesNegative.isEmpty()) { for (LocalDateTime curDate : newDatesNegative) { newCountsPositive.add(0); newDatesPositive.add(curDate); } } // Get last date from both (positive or negative) and fill the other // one with trailing zero counts if (!newDatesPositive.isEmpty() && !newDatesNegative.isEmpty()) { // The last positive date is later than the last negative date if (newDatesPositive.get(newDatesPositive.size() - 1) .compareTo(newDatesNegative.get(newDatesNegative.size() - 1)) == -1) { LocalDateTime curDate = newDatesPositive.get(newDatesPositive.size() - 1); while (!curDate.equals(newDatesNegative.get(newDatesNegative.size() - 1))) { newCountsNegative.add(0); newDatesNegative.add(curDate); curDate = curDate.plusHours(1); } } // The last negative date is later than the last positive date else if (newDatesPositive.get(newDatesPositive.size() - 1) .compareTo(newDatesNegative.get(newDatesNegative.size() - 1)) == 1) { LocalDateTime curDate = newDatesNegative.get(newDatesNegative.size() - 1); while (!curDate.equals(newDatesPositive.get(newDatesPositive.size() - 1))) { newCountsPositive.add(0); newDatesPositive.add(curDate); curDate = curDate.plusHours(1); } } } data.getPositiveCounts().setCounts(newCountsPositive); data.getPositiveCounts().setDates(newDatesPositive); data.getPositiveCounts().updateDateStrings(); data.getNegativeCounts().setCounts(newCountsNegative); data.getNegativeCounts().setDates(newDatesNegative); data.getNegativeCounts().updateDateStrings(); env.setData(data); return env; }
From source file:com.weekcalendar.sample.Sample.java
License:Apache License
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.sample);//from w w w . j a v a2 s . c o m mDateSelectedTv = (TextView) findViewById(R.id.txt_date); mWeekCalendarFragment = (WeekCalendarFragment) getSupportFragmentManager() .findFragmentByTag(WeekCalendarFragment.class.getSimpleName()); if (mWeekCalendarFragment == null) { mWeekCalendarFragment = new WeekCalendarFragment(); Bundle args = new Bundle(); /* Must add this attribute if using ARGUMENT_NOW_BACKGROUND or ARGUMENT_SELECTED_DATE_BACKGROUND*/ args.putString(WeekCalendarFragment.ARGUMENT_PACKAGE_NAME, getApplicationContext().getPackageName()); /* IMPORTANT: Customization for week calender fragment*/ //------------------------------------------------------------------------------------------------// //sets background drawable to the selected dates - null to disable args.putString(WeekCalendarFragment.ARGUMENT_SELECTED_DATE_BACKGROUND, "bg_select"); // args.putString(WeekCalendarFragment.ARGUMENT_SELECTED_DATE_BACKGROUND, null);// disable //Sets background color to calender args.putInt(WeekCalendarFragment.ARGUMENT_CALENDER_BACKGROUND_COLOR, ContextCompat.getColor(this, R.color.md_deep_purple_500)); // Sets text color for the selected date // args.putInt(WeekCalendarFragment.ARGUMENT_SELECTED_DATE_HIGHLIGHT_COLOR // , ContextCompat.getColor(this, R.color.md_pink_200)); // Adds N weeks from the current week (53 or 52 week is one year) args.putInt(WeekCalendarFragment.ARGUMENT_WEEK_COUNT, 1000); // Cancels date picker args.putBoolean(WeekCalendarFragment.ARGUMENT_DISPLAY_DATE_PICKER, false); // Sets background resource drawable to nowView // args.putString(WeekCalendarFragment.ARGUMENT_NOW_BACKGROUND,"bg_now"); // Sets text color to the current date // args.putInt(WeekCalendarFragment.ARGUMENT_CURRENT_DATE_TEXT_COLOR // , ContextCompat.getColor(this, R.color.md_green_500)); // Sets color to the primary views (Month name and dates) // args.putInt(WeekCalendarFragment.ARGUMENT_PRIMARY_TEXT_COLOR // , ContextCompat.getColor(this,R.color.md_yellow_500)); // Sets text size of dates // args.putInt(WeekCalendarFragment.ARGUMENT_DAY_TEXT_SIZE, 18); // // Sets typeface style of date texts // args.putInt(WeekCalendarFragment.ARGUMENT_DAY_TEXT_STYLE, Typeface.BOLD_ITALIC); // // Sets color to the secondary views (now view and week names) /* args.putInt(WeekCalendarFragment.ARGUMENT_SECONDARY_TEXT_COLOR , ContextCompat.getColor(this,R.color.md_green_500));*/ // Sets typeface size of secondary text views (now view and week names) // args.putInt(WeekCalendarFragment.ARGUMENT_SECONDARY_TEXT_SIZE, 18); // Sets typeface style of secondary text views (now view and week names) // args.putInt(WeekCalendarFragment.ARGUMENT_SECONDARY_TEXT_STYLE, Typeface.ITALIC); // Picks between three or one date header letters ex. "Sun" or "S" // two options: // 1. WeekCalendarOptions.DAY_HEADER_LENGTH_THREE_LETTERS // 2. WeekCalendarOptions.DAY_HEADER_LENGTH_ONE_LETTER args.putString(WeekCalendarFragment.ARGUMENT_DAY_HEADER_LENGTH, WeekCalendarOptions.DAY_HEADER_LENGTH_THREE_LETTERS); // Days that have events ArrayList<Calendar> eventDays = new ArrayList<>(); eventDays.add(Calendar.getInstance()); eventDays.add(Calendar.getInstance()); eventDays.add(Calendar.getInstance()); eventDays.get(1).add(Calendar.DAY_OF_MONTH, 1); eventDays.get(2).add(Calendar.WEEK_OF_MONTH, 1); args.putSerializable(WeekCalendarFragment.ARGUMENT_EVENT_DAYS, eventDays); // Sets the color of event dots // 5 options: // 1. WeekCalendarOptions.EVENT_COLOR_YELLOW, 2. WeekCalendarOptions.EVENT_COLOR_BLUE // 3. WeekCalendarOptions.EVENT_COLOR_GREEN, 4. WeekCalendarOptions.EVENT_COLOR_RED // 5. WeekCalendarOptions.EVENT_COLOR_WHITE args.putString(WeekCalendarFragment.ARGUMENT_EVENT_COLOR, WeekCalendarOptions.EVENT_COLOR_YELLOW); //------------------------------------------------------------------------------------------------// mWeekCalendarFragment.setArguments(args); // Attach to the activity FragmentTransaction t = getSupportFragmentManager().beginTransaction(); t.replace(R.id.container, mWeekCalendarFragment, WeekCalendarFragment.class.getSimpleName()); t.commit(); } CalenderListener listener = new CalenderListener() { @Override public void onSelectPicker() { //User can use any type of pickers here the below picker is only Just a example DatePickerDialog .newInstance(Sample.this, Calendar.getInstance().get(Calendar.YEAR), Calendar.getInstance().get(Calendar.MONTH), Calendar.getInstance().get(Calendar.DAY_OF_MONTH)) .show(getFragmentManager(), "datePicker"); } @Override public void onSelectDate(LocalDateTime mSelectedDate) { //callback when a date is selcted mDateSelectedTv.setText("" + mSelectedDate.getDayOfMonth() + "-" + mSelectedDate.getMonthOfYear() + "-" + mSelectedDate.getYear()); } }; //setting the listener mWeekCalendarFragment.setCalenderListener(listener); mWeekCalendarFragment.setPreSelectedDate(Calendar.getInstance()); }
From source file:com.weekcalendar.utils.CalUtil.java
License:Open Source License
public static boolean isSameDay(LocalDateTime day1, LocalDateTime day2) { return day1 != null && day2 != null && day1.getYear() == day2.getYear() && day1.getMonthOfYear() == day2.getMonthOfYear() && day1.getDayOfMonth() == day2.getDayOfMonth(); }
From source file:com.weekcalendar.utils.CalUtil.java
License:Open Source License
/** * Initial calculation of the week/*from www . j ava 2 s .c o m*/ */ public void calculate(Context mContext) { //Initializing JodaTime JodaTimeAndroid.init(mContext); //Initializing Start with current month final LocalDateTime currentDateTime = new LocalDateTime(); setStartDate(currentDateTime.getYear(), currentDateTime.getMonthOfYear(), currentDateTime.getDayOfMonth()); int weekGap = CalUtil.mDateGap(currentDateTime.dayOfWeek().getAsText().substring(0, 3).toLowerCase()); if (weekGap != 0) { //if the current date is not the first day of the week the rest of days is added //Calendar set to the current date Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DAY_OF_YEAR, -weekGap); //now the date is weekGap days back LocalDateTime ldt = LocalDateTime.fromCalendarFields(calendar); setStartDate(ldt.getYear(), ldt.getMonthOfYear(), ldt.getDayOfMonth()); } }
From source file:control.EmprestimoController.java
private static TableModel UpdateTablemodel(TableModel tb) { LocalDateTime hoje = new LocalDateTime(System.currentTimeMillis()); for (int i = 0; i < tb.getRowCount(); i++) { String in = tb.getValueAt(i, 3).toString(); String out = tb.getValueAt(i, 4).toString(); LocalDateTime inicio = new LocalDateTime(in); LocalDateTime fim = new LocalDateTime(out); tb.setValueAt("" + inicio.getDayOfMonth() + "/" + inicio.getMonthOfYear() + "/" + inicio.getYear() + "", i, 3);// w ww. j av a 2 s .c o m tb.setValueAt("" + fim.getDayOfMonth() + "/" + fim.getMonthOfYear() + "/" + fim.getYear() + "", i, 4); Period p = new Period(hoje, fim); int dias = p.getDays(); int horas = p.getHours(); int month = p.getMonths(); //System.out.println(dias+":"+horas+" :: ENTRE AS DATAS "+fim.toString()+" :: "+hoje.toString()); if (dias < 1) { if (dias == 0) { tb.setValueAt("Atraso " + horas * -1 + "h", i, 5); if (horas > 0) tb.setValueAt("Restam " + horas + "h", i, 5); } else tb.setValueAt("Atraso " + dias * -1 + "d:" + horas * -1 + "h", i, 5); } /*else if (month >= 0) tb.setValueAt("Restam "+dias+"d:"+horas+"h", i, 5); else tb.setValueAt("Restam "+month+" meses", i, 5); */ } return tb; }
From source file:control.LivroController.java
public static List<String> volumeToString(Volume v) { if (v != null) { Volume.VolumeInfo volumeInfo = v.getVolumeInfo(); Volume.SaleInfo saleInfo = v.getSaleInfo(); LocalDateTime ldt; Volume.VolumeInfo.ImageLinks links = null; String smallThumbLink = ""; String title = ""; String author = ""; String genr = ""; String identifier = ""; String pageCount = ""; String price = ""; String rating = ""; String publisher = ""; String description = ""; /* Link da thumb */ links = volumeInfo.getImageLinks(); if (links != null) smallThumbLink = links.getSmallThumbnail(); /* Ttulo */ title = "" + v.getVolumeInfo().getTitle() + ""; if (v.getVolumeInfo().getSubtitle() != null) title = title.concat(" - " + v.getVolumeInfo().getSubtitle()); /* Autores */ java.util.List<String> authors = v.getVolumeInfo().getAuthors(); if (authors != null && !authors.isEmpty()) { for (int i = 0; i < authors.size(); ++i) { author = authors.get(i); if (i < authors.size() - 1) { author = author.concat(", "); }/* w w w.j av a 2 s. c o m*/ } } /* Editora e Data de publicao */ if (volumeInfo.getPublisher() != null) publisher = volumeInfo.getPublisher(); if (volumeInfo.getPublishedDate() != null) { ldt = new LocalDateTime(volumeInfo.getPublishedDate()); publisher = publisher .concat(", " + +ldt.getDayOfMonth() + "/" + ldt.getMonthOfYear() + "/" + ldt.getYear()); } /* Descrio */ if (volumeInfo.getDescription() != null) description = "Descrio: " + volumeInfo.getDescription() + ""; /* Gneros */ java.util.List<String> genrs = volumeInfo.getCategories(); if (genrs != null && !genrs.isEmpty()) { genr = genr.concat("Genro: "); if (volumeInfo.getMainCategory() != null) genr = genr.concat(volumeInfo.getMainCategory() + ", "); for (int i = 0; i < genrs.size(); ++i) { genr = genr.concat(genrs.get(i)); if (i < genrs.size() - 1) { genr = genr.concat(", "); } } } /* Nmero de pginas */ if (volumeInfo.getPageCount() != null) pageCount = "" + volumeInfo.getPageCount() + " pginas"; /* Identificadores */ java.util.List<Volume.VolumeInfo.IndustryIdentifiers> isbn = volumeInfo.getIndustryIdentifiers(); if (isbn != null && !isbn.isEmpty()) { for (Volume.VolumeInfo.IndustryIdentifiers ii : isbn) { identifier = identifier.concat(ii.getType() + ": " + ii.getIdentifier() + ""); } } /* Avaliaes */ if (volumeInfo.getRatingsCount() != null && volumeInfo.getRatingsCount() > 0) { int fullRating = (int) Math.round(volumeInfo.getAverageRating()); rating = "Avaliao: "; for (int i = 0; i < fullRating; ++i) { rating = rating.concat(" * "); } rating = rating.concat(" (" + volumeInfo.getRatingsCount() + " avaliaes) "); } /* Informaes de Venda */ if (saleInfo != null && "FOR_SALE".equals(saleInfo.getSaleability())) { double save = saleInfo.getListPrice().getAmount() - saleInfo.getRetailPrice().getAmount(); if (save > 0.0) { price = price.concat( "Preo mdio: " + CURRENCY_FORMATTER.format(saleInfo.getListPrice().getAmount())); } price = price.concat( ", na Google Books: " + CURRENCY_FORMATTER.format(saleInfo.getRetailPrice().getAmount())); if (save > 0.0) { price = price.concat(", voc ganha: " + CURRENCY_FORMATTER.format(save) + " (" + PERCENT_FORMATTER.format(save / saleInfo.getListPrice().getAmount()) + ")"); } } List<String> details = Arrays.asList(identifier, // 0 title, // 1 author, // 2 genr, // 3 rating, // 4 price, // 5 pageCount, // 6 publisher, // 7 description, // 8 smallThumbLink); // 9 return details; } return null; }
From source file:de.avanux.smartapplianceenabler.appliance.TimeOfDayOfWeek.java
License:Open Source License
public LocalDateTime toNextOccurrence(LocalDateTime now) { LocalDateTime dateTime = new LocalDateTime(now.getYear(), now.getMonthOfYear(), now.getDayOfMonth(), getHour(), getMinute(), getSecond()); while (dateTime.get(DateTimeFieldType.dayOfWeek()) != dayOfWeek) { dateTime = dateTime.plusDays(1); }//from w w w .j av a 2 s . c om return dateTime; }