Example usage for java.time.temporal TemporalAccessor get

List of usage examples for java.time.temporal TemporalAccessor get

Introduction

In this page you can find the example usage for java.time.temporal TemporalAccessor get.

Prototype

default int get(TemporalField field) 

Source Link

Document

Gets the value of the specified field as an int .

Usage

From source file:Main.java

public static Boolean isFamilyBirthday(TemporalAccessor date) {
    int month = date.get(ChronoField.MONTH_OF_YEAR);
    int day = date.get(ChronoField.DAY_OF_MONTH);

    // Angie's birthday is on April 3.
    if ((month == Month.APRIL.getValue()) && (day == 3))
        return Boolean.TRUE;

    // Sue's birthday is on June 18.
    if ((month == Month.JUNE.getValue()) && (day == 18))
        return Boolean.TRUE;

    // Joe's birthday is on May 29.
    if ((month == Month.MAY.getValue()) && (day == 29))
        return Boolean.TRUE;

    return Boolean.FALSE;
}

From source file:Main.java

public static Boolean queryFrom(TemporalAccessor temporal) {
    if (temporal.isSupported(ChronoField.DAY_OF_MONTH) && temporal.isSupported(ChronoField.DAY_OF_WEEK)) {
        int dayOfMonth = temporal.get(ChronoField.DAY_OF_MONTH);
        int weekDay = temporal.get(ChronoField.DAY_OF_WEEK);
        DayOfWeek dayOfWeek = DayOfWeek.of(weekDay);
        if (dayOfMonth == 1 && dayOfWeek == DayOfWeek.MONDAY) {
            return Boolean.TRUE;
        }/*  w  w  w .  j  a v a 2s. co  m*/
    }
    return Boolean.FALSE;
}

From source file:Main.java

@Override
public Boolean queryFrom(TemporalAccessor date) {
    int month = date.get(ChronoField.MONTH_OF_YEAR);
    if (month == Month.JULY.getValue() || month == Month.AUGUST.getValue()) {
        return true;
    }/*from  w  w  w.j a v a2s. c  o  m*/
    return false;
}

From source file:FridayThirteenQuery.java

public Boolean queryFrom(TemporalAccessor date) {

    return ((date.get(ChronoField.DAY_OF_MONTH) == 13) && (date.get(ChronoField.DAY_OF_WEEK) == 5));
}

From source file:Main.java

public Boolean queryFrom(TemporalAccessor date) {
    int month = date.get(ChronoField.MONTH_OF_YEAR);
    int day = date.get(ChronoField.DAY_OF_MONTH);

    // Disneyland over Spring Break
    if ((month == Month.APRIL.getValue()) && ((day >= 3) && (day <= 8)))
        return Boolean.TRUE;

    // Smith family reunion on Lake Saugatuck
    if ((month == Month.AUGUST.getValue()) && ((day >= 8) && (day <= 14)))
        return Boolean.TRUE;

    return Boolean.FALSE;
}

From source file:Main.java

@Override
public Boolean queryFrom(TemporalAccessor temporal) {
    if (temporal.isSupported(ChronoField.DAY_OF_MONTH) && temporal.isSupported(ChronoField.DAY_OF_WEEK)) {
        int dayOfMonth = temporal.get(ChronoField.DAY_OF_MONTH);
        int weekDay = temporal.get(ChronoField.DAY_OF_WEEK);
        DayOfWeek dayOfWeek = DayOfWeek.of(weekDay);
        if (dayOfMonth == 1 && dayOfWeek == DayOfWeek.MONDAY) {
            return Boolean.TRUE;
        }//from w  w  w  .  j  a v a  2  s.  co  m
    }
    return Boolean.FALSE;
}

From source file:ch.algotrader.service.ib.IBNativeReferenceDataServiceImpl.java

private LocalDate parseYearMonth(final CharSequence s) {
    if (s == null || s.length() == 0) {
        return null;
    }/*from   ww w.  j  av a 2  s  .  c om*/
    try {
        TemporalAccessor parsed = YEAR_MONTH_FORMAT.parse(s);
        int year = parsed.get(ChronoField.YEAR);
        int month = parsed.get(ChronoField.MONTH_OF_YEAR);
        return LocalDate.of(year, month, 1);
    } catch (DateTimeParseException ex) {
        throw new ServiceException("Invalid year/month format: " + s);
    }
}

From source file:ch.algotrader.service.tt.TTFixReferenceDataServiceImpl.java

private void retrieveFutures(final FutureFamily securityFamily, final List<TTSecurityDefVO> securityDefs) {

    // get all current futures
    List<Future> allFutures = this.futureDao.findBySecurityFamily(securityFamily.getId());
    Map<String, Future> mapByTtid = allFutures.stream().filter(e -> e.getTtid() != null)
            .collect(Collectors.toMap(e -> e.getTtid(), e -> e));
    Map<String, Future> mapBySymbol = allFutures.stream().collect(Collectors.toMap(e -> e.getSymbol(), e -> e));

    for (TTSecurityDefVO securityDef : securityDefs) {

        String type = securityDef.getType();
        if (!type.equalsIgnoreCase("FUT")) {
            throw new ServiceException("Unexpected security definition type for future: " + type);
        }/*from  w ww.  j  av a  2  s  . co  m*/
        String id = securityDef.getId();
        if (!mapByTtid.containsKey(id)) {

            LocalDate maturityDate = securityDef.getMaturityDate();
            LocalDate expiration = maturityDate.withDayOfMonth(1);

            // IPE e-Brent has to be handled as a special case as it happens to have multiple contracts
            // with the same expiration month
            String symbol;
            if ("ICE_IPE".equalsIgnoreCase(securityDef.getExchange()) && securityDef.getAltSymbol() != null) {
                String altSymbol = securityDef.getAltSymbol();
                if (altSymbol.startsWith("Q") || altSymbol.startsWith("Cal")) {
                    continue;
                } else {
                    try {
                        TemporalAccessor parsed = ICE_IPE_SYMBOL.parse(altSymbol);
                        int year = parsed.get(ChronoField.YEAR);
                        int month = parsed.get(ChronoField.MONTH_OF_YEAR);
                        expiration = LocalDate.of(year, month, 1);
                        symbol = FutureSymbol.getSymbol(securityFamily, expiration,
                                this.commonConfig.getFutureSymbolPattern());
                    } catch (DateTimeParseException ex) {
                        throw new ServiceException(
                                "Unable to parse IPE e-Brent expiration month / year: " + altSymbol, ex);
                    }
                }
            } else {
                symbol = FutureSymbol.getSymbol(securityFamily, maturityDate,
                        this.commonConfig.getFutureSymbolPattern());
            }
            if (!mapBySymbol.containsKey(symbol)) {
                Future future = Future.Factory.newInstance();
                String isin = securityFamily.getIsinRoot() != null
                        ? FutureSymbol.getIsin(securityFamily, maturityDate)
                        : null;
                String ric = securityFamily.getRicRoot() != null
                        ? FutureSymbol.getRic(securityFamily, maturityDate)
                        : null;

                future.setSymbol(symbol);
                future.setIsin(isin);
                future.setRic(ric);
                future.setTtid(id);
                future.setExpiration(DateTimeLegacy.toLocalDate(expiration));
                future.setMonthYear(DateTimePatterns.MONTH_YEAR.format(maturityDate));
                future.setSecurityFamily(securityFamily);
                future.setUnderlying(securityFamily.getUnderlying());

                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Creating future based on TT definition: {} {}", securityDef.getSymbol(),
                            securityDef.getMaturityDate());
                }
                this.futureDao.save(future);
            } else {
                Future future = mapBySymbol.get(symbol);
                future.setTtid(id);

                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Updating future based on TT definition: {} {}", securityDef.getSymbol(),
                            securityDef.getMaturityDate());
                }
            }
        }
    }
}

From source file:org.talend.dataprep.transformation.actions.date.ExtractDateTokens.java

@Override
public void applyOnColumn(DataSetRow row, ActionContext context) {
    final RowMetadata rowMetadata = context.getRowMetadata();
    final String columnId = context.getColumnId();
    final Map<String, String> parameters = context.getParameters();
    final ColumnMetadata column = rowMetadata.getById(columnId);

    // Create new columns for date tokens
    final Map<String, String> dateFieldColumns = new HashMap<>();
    for (DateFieldMappingBean date_field : DATE_FIELDS) {
        if (Boolean.valueOf(parameters.get(date_field.key))) {
            final String newColumn = context.column(column.getName() + SEPARATOR + date_field.key);
            dateFieldColumns.put(date_field.key, newColumn);
        }/*  ww  w  .  ja v a 2  s  . com*/
    }

    // Get the most used pattern formatter and parse the date
    final String value = row.get(columnId);
    if (value == null) {
        return;
    }
    TemporalAccessor temporalAccessor = null;
    try {
        temporalAccessor = Providers.get().parse(value, context.getRowMetadata().getById(columnId));
    } catch (DateTimeException e) {
        // temporalAccessor is left null, this will be used bellow to set empty new value for all fields
        LOGGER.debug("Unable to parse date {}.", value, e);
    }

    // insert new extracted values
    for (final DateFieldMappingBean date_field : DATE_FIELDS) {
        if (Boolean.valueOf(parameters.get(date_field.key))) {
            String newValue = StringUtils.EMPTY;
            if (temporalAccessor != null && // may occurs if date can not be parsed with pattern
                    temporalAccessor.isSupported(date_field.field)) {
                newValue = String.valueOf(temporalAccessor.get(date_field.field));
            }
            row.set(dateFieldColumns.get(date_field.key), newValue);
        }
    }
}