List of usage examples for java.util OptionalLong getAsLong
public long getAsLong()
From source file:org.talend.dataprep.schema.xls.XlsSchemaParser.java
/** * * * @param colId the column id./*from w ww . ja va 2s. co m*/ * @param columnRows all rows with previously guessed type: key=row number, value= guessed type * @param averageHeaderSize * @return */ private Type guessColumnType(Integer colId, SortedMap<Integer, String> columnRows, int averageHeaderSize) { // calculate number per type Map<String, Long> perTypeNumber = columnRows.tailMap(averageHeaderSize).values() // .stream() // .collect(Collectors.groupingBy(w -> w, Collectors.counting())); OptionalLong maxOccurrence = perTypeNumber.values().stream().mapToLong(Long::longValue).max(); if (!maxOccurrence.isPresent()) { return ANY; } List<String> duplicatedMax = new ArrayList<>(); perTypeNumber.forEach((type1, aLong) -> { if (aLong >= maxOccurrence.getAsLong()) { duplicatedMax.add(type1); } }); String guessedType; if (duplicatedMax.size() == 1) { guessedType = duplicatedMax.get(0); } else { // as we have more than one type we guess ANY guessedType = ANY.getName(); } LOGGER.debug("guessed type for column #{} is {}", colId, guessedType); return Type.get(guessedType); }
From source file:org.wso2.carbon.apimgt.hybrid.gateway.configurator.Configurator.java
/** * Gets the last WUM updated timestamp from the wum summary file in the 'wumDir' path * * @return last WUM updated timestamp//from w ww . ja v a2s . c o m */ private static String getLastWumUpdatedTimestamp() { String lastWumUpdateTimestamp = "-1"; Path wumDir = Paths.get(carbonHome, ConfigConstants.UPDATES_DIR, ConfigConstants.WUM_DIR); if (Files.exists(wumDir)) { OptionalLong max = OptionalLong.empty(); try { // List files in WUM directory, filter file names for numbers and get the // timestamps from file names, then get the maximum timestamp as the // the last wum updated timestamp. max = Files.list(wumDir).filter(path -> !Files.isDirectory(path)) .map(path -> path.getFileName().toString()).filter(StringUtils::isNumeric) .mapToLong(Long::parseLong).max(); } catch (IOException e) { log.error("An error occurred when retrieving last wum update time.", e); } if (max.isPresent()) { lastWumUpdateTimestamp = String.valueOf(max.getAsLong()); } else { log.warn("No WUM update information found in the file path: " + wumDir.toString()); } } else { log.warn("WUM directory not found in the file path: " + wumDir.toString()); } return lastWumUpdateTimestamp; }