List of usage examples for java.time LocalDate getYear
public int getYear()
From source file:org.dozer.converters.LocalDateConverter.java
@Override public Object convert(Class destClass, Object srcObj) { LocalDate convertedValue = null; try {/*from w w w . ja v a 2s . co m*/ if (srcObj instanceof String) { convertedValue = LocalDate.parse((String) srcObj); } else { LocalDate srcObject = (LocalDate) srcObj; convertedValue = LocalDate.of(srcObject.getYear(), srcObject.getMonth(), srcObject.getDayOfMonth()); } } catch (Exception e) { MappingUtils.throwMappingException("Cannot convert [" + srcObj + "] to LocalDate.", e); } return convertedValue; }
From source file:datojava.jcalendar.DJJCalendar.java
public void fechasOcupadas() throws IOException, ClientProtocolException, JSONException, ParseException { for (int i = 0; i < fechasOcupadasArray.length(); i++) { JSONObject obj = (JSONObject) fechasOcupadasArray.get(i); //Date date = formato.parse(obj.get("diasOcupados").toString()); LocalDate date = LocalDate.parse(obj.get("diasOcupados").toString(), formatter); Calendar calendar = new GregorianCalendar(date.getYear(), date.getMonthValue() - 1, date.getDayOfMonth());// www . ja v a2 s .c o m //Calendar calendar = new GregorianCalendar(2015,Calendar.DECEMBER,12); fechasOcupadas.add(calendar); } System.out.println("retorne el djj"); }
From source file:org.knime.ext.textprocessing.nodes.transformation.documentdataassigner.DocumentDataAssignerCellFactory.java
/** * {@inheritDoc}/* w ww . j a va 2s . com*/ */ @Override public DataCell[] getCells(final DataRow row) { // check if cell contains missing value if (!row.getCell(m_conf.getDocumentColumnIndex()).isMissing()) { // get document content from incoming table Document doc = ((DocumentValue) row.getCell(m_conf.getDocumentColumnIndex())).getDocument(); // create document builder and set sections from incoming document DocumentBuilder docBuilder = new DocumentBuilder(doc); docBuilder.setSections(doc.getSections()); // set authors if (m_conf.getAuthorsColumnIndex() >= 0) { DataCell authorCell = row.getCell(m_conf.getAuthorsColumnIndex()); if (!authorCell.isMissing() && authorCell.getType().isCompatible(StringValue.class)) { String authors[] = ((StringCell) authorCell).getStringValue() .split(m_conf.getAuthorsSplitStr()); for (String author : authors) { final String[] names = author.split(" "); if (names.length > 1) { docBuilder.addAuthor(new Author(names[0], names[names.length - 1])); } else { docBuilder.addAuthor(new Author("", names[0])); } } } } // set document source if (m_conf.getSourceColumnIndex() < 0) { if (!m_conf.getDocSource().isEmpty()) { docBuilder.addDocumentSource(new DocumentSource(m_conf.getDocSource())); } } else { DataCell sourceCell = row.getCell(m_conf.getSourceColumnIndex()); if (!sourceCell.isMissing() && sourceCell.getType().isCompatible(StringValue.class)) { docBuilder.addDocumentSource(new DocumentSource(((StringCell) sourceCell).getStringValue())); } } // set document category if (m_conf.getCategoryColumnIndex() < 0) { if (!m_conf.getDocCategory().isEmpty()) { docBuilder.addDocumentCategory(new DocumentCategory(m_conf.getDocCategory())); } } else { DataCell categoryCell = row.getCell(m_conf.getCategoryColumnIndex()); if (!categoryCell.isMissing() && categoryCell.getType().isCompatible(StringValue.class)) { docBuilder.addDocumentCategory( new DocumentCategory(((StringCell) categoryCell).getStringValue())); } } // set document type docBuilder.setDocumentType(DocumentType.stringToDocumentType(m_conf.getDocType())); // set publication date if (m_conf.getPubDateColumnIndex() >= 0) { final DataCell pubDateCell = row.getCell(m_conf.getPubDateColumnIndex()); if (!pubDateCell.isMissing()) { // new LocalDate type LocalDate date = ((LocalDateValue) pubDateCell).getLocalDate(); setPublicationDate(docBuilder, date.getYear(), date.getMonthValue(), date.getDayOfMonth()); } } else { LocalDate date = m_conf.getDocPubDate(); setPublicationDate(docBuilder, date.getYear(), date.getMonthValue(), date.getDayOfMonth()); } // return new data cell DataCellCache dataCellCache = getDataCellCache(); return new DataCell[] { dataCellCache.getInstance(docBuilder.createDocument()) }; } else { // return new missing value cell (if incoming document cell is missing) return new DataCell[] { DataType.getMissingCell() }; } }
From source file:org.knime.ext.textprocessing.nodes.transformation.stringstodocument.StringsToDocumentCellFactory2.java
/** * {@inheritDoc}//from w w w .j a v a 2 s.com */ @Override public DataCell[] getCells(final DataRow row) { final DocumentBuilder docBuilder = new DocumentBuilder(m_tokenizerName); // Set title if (m_config.getUseTitleColumn()) { final DataCell titleCell = row.getCell(m_config.getTitleColumnIndex()); if (!titleCell.isMissing()) { docBuilder.addTitle(((StringValue) titleCell).getStringValue()); } } else if (m_config.getTitleMode().contentEquals(StringsToDocumentConfig2.TITLEMODE_ROWID)) { docBuilder.addTitle(row.getKey().toString()); } //Set fulltext final DataCell textCell = row.getCell(m_config.getFulltextColumnIndex()); if (!textCell.isMissing()) { docBuilder.addSection(((StringValue) textCell).getStringValue(), SectionAnnotation.UNKNOWN); } // Set authors if (m_config.getUseAuthorsColumn()) { final DataCell authorsCell = row.getCell(m_config.getAuthorsColumnIndex()); if (!authorsCell.isMissing()) { final String authors = ((StringValue) authorsCell).getStringValue(); final String[] authorsArr = authors.split(m_config.getAuthorsSplitChar()); for (String author : authorsArr) { String firstName = ""; String lastName = ""; final String[] names = author.split(" "); if (names.length > 1) { final StringBuilder sb = new StringBuilder(); for (int i = 0; i < names.length - 1; i++) { sb.append(names[i]); sb.append(" "); } firstName = sb.toString(); lastName = names[names.length - 1]; } else if (names.length == 1) { lastName = names[0]; } docBuilder.addAuthor(new Author(firstName.trim(), lastName.trim())); } } } else if (!m_config.getAuthorFirstName().isEmpty() || !m_config.getAuthorLastName().isEmpty()) { docBuilder.addAuthor(new Author(m_config.getAuthorFirstName(), m_config.getAuthorLastName())); } // set document source if (m_config.getUseSourceColumn()) { final DataCell sourceCell = row.getCell(m_config.getSourceColumnIndex()); if (!sourceCell.isMissing()) { docBuilder.addDocumentSource(new DocumentSource(((StringValue) sourceCell).getStringValue())); } } else if (m_config.getDocSource().length() > 0) { docBuilder.addDocumentSource(new DocumentSource(m_config.getDocSource())); } // set document category if (m_config.getUseCatColumn()) { final DataCell catCell = row.getCell(m_config.getCategoryColumnIndex()); if (!catCell.isMissing()) { docBuilder.addDocumentCategory(new DocumentCategory(((StringValue) catCell).getStringValue())); } } else if (m_config.getDocCat().length() > 0) { docBuilder.addDocumentCategory(new DocumentCategory(m_config.getDocCat())); } // set document type docBuilder.setDocumentType(DocumentType.stringToDocumentType(m_config.getDocType())); // set publication date if (m_config.getUsePubDateColumn()) { final DataCell pubDateCell = row.getCell(m_config.getPubDateColumnIndex()); if (!pubDateCell.isMissing()) { LocalDate date = ((LocalDateValue) pubDateCell).getLocalDate(); setPublicationDate(docBuilder, date.getYear(), date.getMonthValue(), date.getDayOfMonth()); } } else { LocalDate date = m_config.getPublicationDate(); setPublicationDate(docBuilder, date.getYear(), date.getMonthValue(), date.getDayOfMonth()); } // return datacells cells return new DataCell[] { getDataCellCache().getInstance(docBuilder.createDocument()) }; }
From source file:org.primeframework.mvc.parameter.convert.converters.LocalDateConverterTest.java
@Test public void fromStrings() { GlobalConverter converter = new LocalDateConverter(new MockConfiguration()); LocalDate value = (LocalDate) converter.convertFromStrings(LocalDate.class, null, "testExpr", ArrayUtils.toArray((String) null)); assertNull(value);/*from w w w .ja v a 2s . com*/ value = (LocalDate) converter.convertFromStrings(Locale.class, MapBuilder.asMap("dateTimeFormat", "MM-dd-yyyy"), "testExpr", ArrayUtils.toArray("07-08-2008")); assertEquals(value.getMonthValue(), 7); assertEquals(value.getDayOfMonth(), 8); assertEquals(value.getYear(), 2008); try { converter.convertFromStrings(Locale.class, MapBuilder.asMap("dateTimeFormat", "MM-dd-yyyy"), "testExpr", ArrayUtils.toArray("07/08/2008")); fail("Should have failed"); } catch (ConversionException e) { // Expected } }
From source file:org.knime.ext.textprocessing.nodes.transformation.stringstodocument.StringsToDocumentCellFactory.java
/** * {@inheritDoc}/*from w w w . j a v a 2 s . c o m*/ */ @Override public DataCell[] getCells(final DataRow row) { final DocumentBuilder docBuilder = new DocumentBuilder(m_tokenizerName); // Set title String title = m_config.getDocTitle(); if (m_config.getUseTitleColumn()) { if (m_config.getTitleStringIndex() >= 0) { final DataCell titleCell = row.getCell(m_config.getTitleStringIndex()); if (!titleCell.isMissing() && titleCell.getType().isCompatible(StringValue.class)) { title = ((StringValue) titleCell).getStringValue(); } else { title = ""; } docBuilder.addTitle(title); } } else { title = row.getKey().toString(); docBuilder.addTitle(title); } //Set fulltext if (m_config.getFulltextStringIndex() >= 0) { final DataCell textCell = row.getCell(m_config.getFulltextStringIndex()); String fulltext = ""; if (!textCell.isMissing() && textCell.getType().isCompatible(StringValue.class)) { fulltext = ((StringValue) textCell).getStringValue(); } docBuilder.addSection(fulltext, SectionAnnotation.UNKNOWN); } // Set authors if (m_config.getUseAuthorsColumn()) { if (m_config.getAuthorsStringIndex() >= 0) { final DataCell auhorsCell = row.getCell(m_config.getAuthorsStringIndex()); if (!auhorsCell.isMissing() && auhorsCell.getType().isCompatible(StringValue.class)) { final String authors = ((StringValue) auhorsCell).getStringValue(); final String[] authorsArr = authors.split(m_config.getAuthorsSplitChar()); for (String author : authorsArr) { String firstName = m_config.getAuthorFirstName(); String lastName = m_config.getAuthorLastName(); final String[] names = author.split(" "); if (names.length > 1) { final StringBuilder sb = new StringBuilder(); for (int i = 0; i < names.length - 1; i++) { sb.append(names[i]); sb.append(" "); } firstName = sb.toString(); lastName = names[names.length - 1]; } else if (names.length == 1) { lastName = names[0]; } docBuilder.addAuthor(new Author(firstName.trim(), lastName.trim())); } // If check box is set to use author names from column // if author first/last name is not specified and both first and last name in the node dialog // component are empty return an empty string. } else if (auhorsCell.isMissing() && (!m_config.getAuthorFirstName().isEmpty() || !m_config.getAuthorLastName().isEmpty())) { docBuilder.addAuthor(new Author(m_config.getAuthorFirstName(), m_config.getAuthorLastName())); } } } else if (!m_config.getAuthorFirstName().isEmpty() || !m_config.getAuthorLastName().isEmpty()) { // if no check box is set to use authors name from column, if both dialog components name are empty // return an empty string otherwise return "-" + the one specified. docBuilder.addAuthor(new Author(m_config.getAuthorFirstName(), m_config.getAuthorLastName())); } // set document source String docSource = m_config.getDocSource(); if (m_config.getUseSourceColumn()) { if (m_config.getSourceStringIndex() >= 0) { final DataCell sourceCell = row.getCell(m_config.getSourceStringIndex()); if (!sourceCell.isMissing() && sourceCell.getType().isCompatible(StringValue.class)) { docSource = ((StringValue) sourceCell).getStringValue(); } else { docSource = ""; } } } if (docSource.length() > 0) { docBuilder.addDocumentSource(new DocumentSource(docSource)); } // set document category String docCat = m_config.getDocCat(); if (m_config.getUseCatColumn()) { if (m_config.getCategoryStringIndex() >= 0) { final DataCell catCell = row.getCell(m_config.getCategoryStringIndex()); if (!catCell.isMissing() && catCell.getType().isCompatible(StringValue.class)) { docCat = ((StringValue) catCell).getStringValue(); } else { docCat = ""; } } } if (docCat.length() > 0) { docBuilder.addDocumentCategory(new DocumentCategory(docCat)); } // set document type docBuilder.setDocumentType(DocumentType.stringToDocumentType(m_config.getDocType())); // set publication date if (m_config.getUsePubDateColumn()) { if (m_config.getPubDateStringIndex() >= 0) { final DataCell pubDateCell = row.getCell(m_config.getPubDateStringIndex()); if (!pubDateCell.isMissing()) { // new LocalDate type if (pubDateCell.getType().isCompatible(LocalDateValue.class)) { LocalDate date = ((LocalDateValue) pubDateCell).getLocalDate(); setPublicationDate(docBuilder, date.getYear(), date.getMonthValue(), date.getDayOfMonth()); } else if (pubDateCell.getType().isCompatible(DateAndTimeValue.class)) { DateAndTimeValue dateTime = ((DateAndTimeValue) pubDateCell); setPublicationDate(docBuilder, dateTime.getYear(), dateTime.getMonth() + 1, dateTime.getDayOfMonth()); } else if (pubDateCell.getType().isCompatible(StringValue.class)) { extractAndSetPublicationDate(((StringValue) pubDateCell).getStringValue(), docBuilder); } } } } else { extractAndSetPublicationDate(m_config.getPublicationDate(), docBuilder); } DataCellCache dataCellCache = getDataCellCache(); return new DataCell[] { dataCellCache.getInstance(docBuilder.createDocument()) }; }
From source file:de.jfachwert.rechnung.Rechnungsmonat.java
/** * Erzeugt einen gueltigen Rechnungsmonat anhand des uebergebenen * {@link LocalDate}s. Will man ein Rechnungsmonat ueber ein * {@link java.util.Date} anlegen, muss man es vorher mit * {@link java.sql.Date#toLocalDate()} in ein {@link LocalDate} wandeln. * * @param date Datum//w w w .java 2 s . c om */ public Rechnungsmonat(LocalDate date) { this(date.getMonthValue(), date.getYear()); }
From source file:us.colloquy.sandbox.TestExtractor.java
@Test public void useJsoup() { String homeDir = System.getProperty("user.home"); System.out.println(homeDir);/*from w ww . jav a 2s . com*/ //JSOUP API allows to extract all elements of letters in files // File input = new File("samples/OEBPS/Text/0001_1006_2001.xhtml"); File input = new File("samples/pisma-1904/OEBPS/Text/single_doc.html"); try { Document doc = Jsoup.parse(input, "UTF-8"); List<Letter> letters = new ArrayList<>(); //our model contains only a subset of fields String previousYear = ""; for (Element element : doc.getElementsByClass("section")) { Letter letter = new Letter(); StringBuilder content = new StringBuilder(); for (Element child : element.children()) { for (Attribute att : child.attributes()) { System.out.println(att.getKey() + " " + att.getValue()); } if ("center".equalsIgnoreCase(child.className())) { String toWhom = child.getElementsByTag("strong").text(); if (StringUtils.isEmpty(toWhom)) { toWhom = child.text(); // System.out.println(toWhom); } String[] toWhomArray = toWhom.split("(\\s\\s)|(,)"); for (String to : toWhomArray) { RussianDate.parseToWhom(letter, to); //here we need to recognize a russian name and store that but for now we store the content } //check if there is anything else here and find date and place - it will be replaced if exists below String entireText = child.text(); String tail = entireText.replace(toWhom, ""); if (StringUtils.isNotEmpty(tail)) { RussianDate.parseDateAndPlace(letter, tail, previousYear); //a parser that figures out date and place if they are present } // System.out.println("two whom\t " + child.getElementsByTag("strong").text() ); } else if ("Data".equalsIgnoreCase(child.className())) { if (child.getElementsByTag("em") != null && StringUtils.isNotEmpty(child.getElementsByTag("em").text())) { RussianDate.parseDateAndPlace(letter, child.getElementsByTag("em").text(), previousYear); //most often date and place are enclosed in em tag if (letter.getDate() != null) { LocalDate localDate = letter.getDate().toInstant().atZone(ZoneId.systemDefault()) .toLocalDate(); int year = localDate.getYear(); previousYear = year + ""; } } // System.out.println("when and where\t " + child.getElementsByTag("em").text()); } else if ("petit".equalsIgnoreCase(child.className()) || "Textpetit_otstup".equalsIgnoreCase(child.className())) { letter.getNotes().add(child.text()); } else { //System.out.println(child.text() ); Elements elements = child.getElementsByTag("sup"); for (Element e : elements) { String value = e.text(); e.replaceWith(new TextNode("[" + value + "]", null)); } for (Element el : child.getAllElements()) { // System.out.println(el.tagName()); if ("sup".equalsIgnoreCase(el.tagName())) { content.append(" [" + el.text() + "] "); } else { content.append(el.text()); } } content.append("\n"); } // System.out.println(child.tag() + "\n" ); // System.out.println(child.outerHtml() + "\n" + child.text()); } letter.setContent(content.toString()); letters.add(letter); } ObjectWriter ow = new com.fasterxml.jackson.databind.ObjectMapper().writer().withDefaultPrettyPrinter(); for (Letter letter : letters) { // if (letter.getDate() == null) // { // if (StringUtils.isNotEmpty(person.getLastName())) // { String json = ow.writeValueAsString(letter); System.out.println(json); // } //} } } catch (IOException e) { e.printStackTrace(); } }
From source file:de.jfachwert.rechnung.Rechnungsmonat.java
/** * Erzeugt einen gueltigen Rechnungsmonat. Normalerweise sollte der * Monat als "7/2017" angegeben werden, es werden aber auch andere * Formate wie "Jul-2017" oder "2017-07-14" unterstuetzt. * <p>/*from ww w . ja va 2 s . c om*/ * Auch wenn "Jul-2017" und andere Formate als gueltiger Rechnungsmonat * erkannt werden, sollte man dies nur vorsichtig einsetzen, da hier mit * Brute-Force einfach nur geraten wird, welches Format es sein koennte. * </p> * * @param monat z.B. "7/2017" fuer Juli 2017 */ public Rechnungsmonat(String monat) { String[] parts = monat.split("/"); if ((parts.length == 2) && isDigit(parts[0]) && isDigit(parts[1])) { this.monate = asMonate(verify(MONTH, parts[0], VALID_MONTH_RANGE), verify(YEAR, parts[1], VALID_YEAR_RANGE)); } else { LocalDate date = toLocalDate(monat); this.monate = asMonate(date.getMonthValue(), date.getYear()); } }
From source file:com.bdb.weather.display.summary.HighLowPanel.java
private void loadData(OHLCSeries series, SeriesInfo<T> info, List<SummaryRecord> records, int seriesIndex) { ObservableList<SummaryRecord> dataModel = FXCollections.observableList(records); dataTable.setItems(dataModel);//from w w w . j av a2s .c om for (SummaryRecord record : records) { T avg = info.getAvgValue(record); T min = info.getMinValue(record); T max = info.getMaxValue(record); LocalDate date = record.getDate(); // TODO: Figure out how to create a time period based on the specified interval RegularTimePeriod period = null; switch (interval) { case DAY_INTERVAL: period = new Hour(seriesIndex * 4, date.getDayOfMonth(), date.getMonth().getValue(), date.getYear()); break; case MONTH_INTERVAL: period = new Day(seriesIndex * 4 + 1, date.getMonth().getValue(), date.getYear()); break; case YEAR_INTERVAL: period = new Year(date.getYear()); break; default: period = null; break; } if (avg != null && min != null && max != null) { series.add(period, avg.get(), max.get(), min.get(), min.get()); } } }