List of usage examples for java.text DecimalFormat setMaximumFractionDigits
@Override public void setMaximumFractionDigits(int newValue)
From source file:com.att.aro.core.util.Util.java
/** * Formats a number so that the number of digits in the fraction * portion of it is bound by a maximum value and a minimum value. * <br>/* ww w. ja va2 s. c o m*/ * <br> * Examples with maxFractionDigits being 3 and * minFractionDigits being 0: * <br>2.4535 -> 2.454 * <br>20 -> 20 * <br>24535 -> 24535 * <br>2.5 -> 2.5 * <br>2.460 -> 2.46 * <br>2.40 -> 2.4 * <br>3.12 -> 3.12 * <br>9.888 -> 9.888 * * @param number * @param maxFractionDigits maximum number of fraction digits, * replaced by 0 if it is a negative value * @param minFractionDigits minimum number of fraction digits, * replaced by 0 if it is a negative value * @return */ public static String formatDecimal(BigDecimal number, int maxFractionDigits, int minFractionDigits) { DecimalFormat df = new DecimalFormat(); df.setGroupingUsed(false); df.setMaximumFractionDigits(maxFractionDigits); df.setMinimumFractionDigits(minFractionDigits); return df.format(number); }
From source file:com.itude.mobile.android.util.StringUtil.java
/** * Set the formatter./*from ww w.java 2 s .c o m*/ * * @param formatter {@link DecimalFormat} * @param locale {@link Locale} * @param minimalDecimalNumbers minimal number of decimals * @param maximumDecimalNumbers maximum number of decimals */ private static void setupFormatter(DecimalFormat formatter, Locale locale, int minimalDecimalNumbers, int maximumDecimalNumbers) { formatter.setDecimalFormatSymbols(new DecimalFormatSymbols(locale)); formatter.setMinimumIntegerDigits(1); formatter.setMinimumFractionDigits(minimalDecimalNumbers); formatter.setMaximumFractionDigits(maximumDecimalNumbers); formatter.setGroupingUsed(true); formatter.setGroupingSize(3); }
From source file:org.onebusaway.presentation.impl.realtime.SiriSupport.java
/** * NOTE: The tripDetails bean here may not be for the trip the vehicle is currently on * in the case of A-D for stop!// w w w.j a v a2 s . co m */ @SuppressWarnings("unused") public static void fillMonitoredVehicleJourney(MonitoredVehicleJourneyStructure monitoredVehicleJourney, TripBean framedJourneyTripBean, TripStatusBean currentVehicleTripStatus, StopBean monitoredCallStopBean, OnwardCallsMode onwardCallsMode, PresentationService presentationService, TransitDataService transitDataService, int maximumOnwardCalls, List<TimepointPredictionRecord> stopLevelPredictions, boolean hasRealtimeData, long responseTimestamp) { BlockInstanceBean blockInstance = transitDataService.getBlockInstance( currentVehicleTripStatus.getActiveTrip().getBlockId(), currentVehicleTripStatus.getServiceDate()); List<BlockTripBean> blockTrips = blockInstance.getBlockConfiguration().getTrips(); if (monitoredCallStopBean == null) { monitoredCallStopBean = currentVehicleTripStatus.getNextStop(); } ///////////// LineRefStructure lineRef = new LineRefStructure(); lineRef.setValue(framedJourneyTripBean.getRoute().getId()); monitoredVehicleJourney.setLineRef(lineRef); OperatorRefStructure operatorRef = new OperatorRefStructure(); operatorRef.setValue(framedJourneyTripBean.getRoute().getId().split("_")[0]); monitoredVehicleJourney.setOperatorRef(operatorRef); DirectionRefStructure directionRef = new DirectionRefStructure(); directionRef.setValue(framedJourneyTripBean.getDirectionId()); monitoredVehicleJourney.setDirectionRef(directionRef); NaturalLanguageStringStructure routeShortName = new NaturalLanguageStringStructure(); String shortName = framedJourneyTripBean.getRoute().getShortName(); if (shortName == null) { shortName = framedJourneyTripBean.getRoute().getId().split("_")[1]; } if (!isBlank(currentVehicleTripStatus.getActiveTrip().getRouteShortName())) { // look for an override like an express desginator routeShortName.setValue(currentVehicleTripStatus.getActiveTrip().getRouteShortName()); } else { routeShortName.setValue(shortName); } monitoredVehicleJourney.setPublishedLineName(routeShortName); JourneyPatternRefStructure journeyPattern = new JourneyPatternRefStructure(); journeyPattern.setValue(framedJourneyTripBean.getShapeId()); monitoredVehicleJourney.setJourneyPatternRef(journeyPattern); NaturalLanguageStringStructure headsign = new NaturalLanguageStringStructure(); headsign.setValue(framedJourneyTripBean.getTripHeadsign()); monitoredVehicleJourney.setDestinationName(headsign); VehicleRefStructure vehicleRef = new VehicleRefStructure(); if (currentVehicleTripStatus.getVehicleId() == null) { String tripId = framedJourneyTripBean.getId(); String blockId = framedJourneyTripBean.getBlockId(); String directionId = framedJourneyTripBean.getDirectionId(); String vehicleIdHash = Integer.toString((tripId + blockId + directionId).hashCode()); String agencyName = tripId.split("_")[0]; String vehicleId = agencyName + "_" + vehicleIdHash; vehicleRef.setValue(vehicleId); } else { vehicleRef.setValue(currentVehicleTripStatus.getVehicleId()); } monitoredVehicleJourney.setVehicleRef(vehicleRef); monitoredVehicleJourney.getVehicleMode().add(toVehicleMode(currentVehicleTripStatus.getVehicleType())); monitoredVehicleJourney.setMonitored(currentVehicleTripStatus.isPredicted()); monitoredVehicleJourney.setBearing((float) currentVehicleTripStatus.getOrientation()); monitoredVehicleJourney.setProgressRate(getProgressRateForPhaseAndStatus( currentVehicleTripStatus.getStatus(), currentVehicleTripStatus.getPhase())); // origin-destination for (int i = 0; i < blockTrips.size(); i++) { BlockTripBean blockTrip = blockTrips.get(i); if (blockTrip.getTrip().getId().equals(framedJourneyTripBean.getId())) { List<BlockStopTimeBean> stops = blockTrip.getBlockStopTimes(); JourneyPlaceRefStructure origin = new JourneyPlaceRefStructure(); origin.setValue(stops.get(0).getStopTime().getStop().getId()); monitoredVehicleJourney.setOriginRef(origin); StopBean lastStop = stops.get(stops.size() - 1).getStopTime().getStop(); DestinationRefStructure dest = new DestinationRefStructure(); dest.setValue(lastStop.getId()); monitoredVehicleJourney.setDestinationRef(dest); break; } } // framed journey FramedVehicleJourneyRefStructure framedJourney = new FramedVehicleJourneyRefStructure(); DataFrameRefStructure dataFrame = new DataFrameRefStructure(); dataFrame.setValue(String.format("%1$tY-%1$tm-%1$td", currentVehicleTripStatus.getServiceDate())); framedJourney.setDataFrameRef(dataFrame); framedJourney.setDatedVehicleJourneyRef(framedJourneyTripBean.getId()); monitoredVehicleJourney.setFramedVehicleJourneyRef(framedJourney); // location // if vehicle is detected to be on detour, use actual lat/lon, not snapped location. LocationStructure location = new LocationStructure(); DecimalFormat df = new DecimalFormat(); df.setMaximumFractionDigits(6); if (presentationService.isOnDetour(currentVehicleTripStatus)) { location.setLatitude( new BigDecimal(df.format(currentVehicleTripStatus.getLastKnownLocation().getLat()))); location.setLongitude( new BigDecimal(df.format(currentVehicleTripStatus.getLastKnownLocation().getLon()))); } else { if (currentVehicleTripStatus.getLocation() != null) { location.setLatitude(new BigDecimal(df.format(currentVehicleTripStatus.getLocation().getLat()))); location.setLongitude(new BigDecimal(df.format(currentVehicleTripStatus.getLocation().getLon()))); } } monitoredVehicleJourney.setVehicleLocation(location); // progress status List<String> progressStatuses = new ArrayList<String>(); if (presentationService.isInLayover(currentVehicleTripStatus)) { progressStatuses.add("layover"); } // "prevTrip" really means not on the framedvehiclejourney trip if (!framedJourneyTripBean.getId().equals(currentVehicleTripStatus.getActiveTrip().getId())) { progressStatuses.add("prevTrip"); } if (!progressStatuses.isEmpty()) { NaturalLanguageStringStructure progressStatus = new NaturalLanguageStringStructure(); progressStatus.setValue(StringUtils.join(progressStatuses, ",")); monitoredVehicleJourney.setProgressStatus(progressStatus); } // block ref if (presentationService.isBlockLevelInference(currentVehicleTripStatus)) { BlockRefStructure blockRef = new BlockRefStructure(); blockRef.setValue(framedJourneyTripBean.getBlockId()); monitoredVehicleJourney.setBlockRef(blockRef); } // scheduled depature time if (presentationService.isBlockLevelInference(currentVehicleTripStatus) && (presentationService .isInLayover(currentVehicleTripStatus) || !framedJourneyTripBean.getId().equals(currentVehicleTripStatus.getActiveTrip().getId()))) { BlockStopTimeBean originDepartureStopTime = null; for (int t = 0; t < blockTrips.size(); t++) { BlockTripBean thisTrip = blockTrips.get(t); BlockTripBean nextTrip = null; if (t + 1 < blockTrips.size()) { nextTrip = blockTrips.get(t + 1); } if (thisTrip.getTrip().getId().equals(currentVehicleTripStatus.getActiveTrip().getId())) { // just started new trip if (currentVehicleTripStatus.getDistanceAlongTrip() < (0.5 * currentVehicleTripStatus.getTotalDistanceAlongTrip())) { originDepartureStopTime = thisTrip.getBlockStopTimes().get(0); // at end of previous trip } else { if (nextTrip != null) { originDepartureStopTime = nextTrip.getBlockStopTimes().get(0); } } break; } } if (originDepartureStopTime != null) { Date departureTime = new Date(currentVehicleTripStatus.getServiceDate() + (originDepartureStopTime.getStopTime().getDepartureTime() * 1000)); monitoredVehicleJourney.setOriginAimedDepartureTime(departureTime); } } Map<String, TimepointPredictionRecord> stopIdToPredictionRecordMap = new HashMap<String, TimepointPredictionRecord>(); // (build map of vehicle IDs to TPRs) if (stopLevelPredictions != null) { for (TimepointPredictionRecord tpr : stopLevelPredictions) { stopIdToPredictionRecordMap.put(AgencyAndId.convertToString(tpr.getTimepointId()), tpr); } } // monitored call if (!presentationService.isOnDetour(currentVehicleTripStatus)) fillMonitoredCall(monitoredVehicleJourney, blockInstance, currentVehicleTripStatus, monitoredCallStopBean, presentationService, transitDataService, stopIdToPredictionRecordMap, hasRealtimeData, responseTimestamp); // onward calls if (!presentationService.isOnDetour(currentVehicleTripStatus)) fillOnwardCalls(monitoredVehicleJourney, blockInstance, framedJourneyTripBean, currentVehicleTripStatus, onwardCallsMode, presentationService, transitDataService, stopIdToPredictionRecordMap, maximumOnwardCalls, hasRealtimeData, responseTimestamp); // situations fillSituations(monitoredVehicleJourney, currentVehicleTripStatus); return; }
From source file:net.sf.webissues.core.WebIssuesTaskDataHandler.java
public static Set<TaskAttribute> updateTaskData(Set<TaskAttribute> changedAttributes, WebIssuesClient client, TaskRepository repository, TaskData data, IssueDetails issue, IProgressMonitor monitor) throws HttpException, ProtocolException, IOException { doDateAttribute(TaskAttribute.DATE_CREATION, data, changedAttributes, issue.getIssue().getCreatedDate()); doDateAttribute(TaskAttribute.DATE_MODIFICATION, data, changedAttributes, issue.getIssue().getModifiedDate()); IEnvironment environment = WebIssuesCorePlugin.getDefault().getConnector().getClientManager() .getClient(repository, monitor).getEnvironment(); Folder folder = issue.getIssue().getFolder(); IssueType type = folder.getType();/*from w ww . jav a 2 s. c om*/ // Set the project and folder attributes TaskAttribute projectAttribute = data.getRoot().getAttribute(WebIssuesAttribute.PROJECT.getTaskKey()); TaskAttribute folderAttribute = data.getRoot().getAttribute(WebIssuesAttribute.FOLDER.getTaskKey()); projectAttribute.setValue(String.valueOf(folder.getProject().getId())); rebuildFolders(environment, projectAttribute, data, folderAttribute, issue.getIssue().getFolder().getType()); folderAttribute.setValue(String.valueOf(folder.getId())); // Remove all webissues attributes exception project and folder for (Iterator<TaskAttribute> attributeIterator = data.getRoot().getAttributes().values() .iterator(); attributeIterator.hasNext();) { TaskAttribute attr = attributeIterator.next(); if (attr.getId().startsWith(WEBISSUES_ATTRIBUTE_KEY_PREFIX)) { attributeIterator.remove(); } } // We might already have a priority attribute TaskAttribute priorityAttribute = data.getRoot().getAttribute(TaskAttribute.PRIORITY); for (Attribute attr : type.values()) { if (!attr.isBuiltIn() && (priorityAttribute == null || !attr.getName().equals("Priority"))) { String defaultValue = attr.getDefaultValue(); String attributeId = WEBISSUES_ATTRIBUTE_KEY_PREFIX + attr.getId(); // Set as default if nothing set String value = issue.getIssue().get(attr); if (Util.isNullOrBlank(value)) { value = defaultValue; } // Set up the task attribute TaskAttribute taskAttr = data.getRoot().createAttribute(attributeId); TaskAttributeMetaData metaData = taskAttr.getMetaData(); metaData.setKind(TaskAttribute.KIND_DEFAULT); switch (attr.getAttributeType()) { case DATETIME: if (attr.isDateOnly()) { metaData.setType(TaskAttribute.TYPE_DATE); } else { metaData.setType(TaskAttribute.TYPE_DATETIME); } break; case TEXT: metaData.setType(TaskAttribute.TYPE_SHORT_TEXT); break; case NUMERIC: metaData.setType(TaskAttribute.TYPE_SHORT_TEXT); break; case USER: metaData.setType(TaskAttribute.TYPE_PERSON); metaData.setKind(TaskAttribute.KIND_PEOPLE); metaData.putValue("membersOnly", String.valueOf(attr.isMembersOnly())); if ("[Me]".equals(value)) { value = type.getTypes().getEnvironment().getOwnerUser().getName(); } break; case ENUM: metaData.setType(TaskAttribute.TYPE_SINGLE_SELECT); taskAttr.clearOptions(); if (!attr.isRequired()) { taskAttr.putOption("", ""); } for (String option : attr.getOptions()) { taskAttr.putOption(option, option); } break; } // Format the value if it is numeric if (attr.getType().equals(Attribute.AttributeType.NUMERIC) && attr.getDecimalPlaces() > 0) { DecimalFormat fmt = new DecimalFormat(); fmt.setMinimumFractionDigits(attr.getDecimalPlaces()); fmt.setMaximumFractionDigits(attr.getDecimalPlaces()); taskAttr.setValue(fmt.format(Util.isNullOrBlank(value) ? 0d : Double.parseDouble(value))); } else if (attr.getType().equals(Attribute.AttributeType.DATETIME)) { DateFormat fmt = new SimpleDateFormat( attr.isDateOnly() ? Client.DATEONLY_FORMAT : Client.DATETIME_FORMAT); try { taskAttr.setValue(value == null ? "" : String.valueOf(fmt.parse(value).getTime())); } catch (ParseException e) { taskAttr.setValue(""); } } else { taskAttr.setValue(Util.nonNull(value)); } metaData.setLabel(attr.getName()); } } // Comments Collection<Comment> comments = issue.getComments(); if (comments != null) { int count = 1; for (Comment comment : comments) { String plainText = comment.getText(); if (Util.isNullOrBlank(plainText)) { continue; } TaskCommentMapper mapper = new TaskCommentMapper(); User owner = comment.getCreatedUser(); if (owner != null) { mapper.setAuthor(repository.createPerson(owner.getName())); } mapper.setCreationDate(comment.getCreatedDate().getTime()); mapper.setText(plainText); mapper.setNumber(count); TaskAttribute attribute = data.getRoot().createAttribute(TaskAttribute.PREFIX_COMMENT + count); mapper.applyTo(attribute); count++; } } Collection<Attachment> attachments = issue.getAttachments(); int count = 1; for (Attachment attachment : attachments) { TaskAttachmentMapper mapper = new TaskAttachmentMapper(); mapper.setAuthor(repository.createPerson(attachment.getCreatedUser().getName())); mapper.setDescription(attachment.getDescription()); mapper.setCreationDate(attachment.getCreatedDate().getTime()); mapper.setAttachmentId(String.valueOf(attachment.getId())); mapper.setFileName(attachment.getName()); mapper.setUrl(Util.concatenateUri(repository.getRepositoryUrl(), "attachments", String.valueOf(attachment.getId()))); mapper.setLength(Long.valueOf(attachment.getSize())); TaskAttribute attribute = data.getRoot().createAttribute(TaskAttribute.PREFIX_ATTACHMENT + count); mapper.applyTo(attribute); count++; } count = 1; for (Change change : issue.getChanges()) { WebIssuesChangeMapper mapper = new WebIssuesChangeMapper(); mapper.setChangeId(String.valueOf(count)); mapper.setUser(repository.createPerson(change.getModifiedUser().getName())); mapper.setAttributeName(change.getAttribute() == null ? "Name" : change.getAttribute().getName()); mapper.setType(change.getType()); mapper.setOldValue(change.getOldValue()); mapper.setNewValue(change.getNewValue()); mapper.setDate(change.getModifiedDate()); TaskAttribute attribute = data.getRoot() .createAttribute(WebIssuesChangeMapper.PREFIX_CHANGE + String.valueOf(count)); mapper.applyTo(attribute); count++; } return changedAttributes; }
From source file:org.eclairjs.nashorn.Utils.java
public static String formatDouble(Double v) { try {//from ww w .j a v a2 s.c om DecimalFormat df = new DecimalFormat(); df.setGroupingUsed(false); df.setMaximumFractionDigits(12); return df.format(v); } catch (java.lang.IllegalArgumentException e) { return v.toString(); } }
From source file:whitelabel.cloud.adapter.CurrencyFormatterExt.java
public NumberFormat getNumberFormat(Locale locale, String pattern) { NumberFormat df = NumberFormat.getNumberInstance(locale); DecimalFormat dec = (DecimalFormat) df; dec.applyPattern(pattern);// www . j a va 2 s. c o m dec.setMaximumFractionDigits(2); dec.setGroupingUsed(false); return dec; }
From source file:com.eu.evaluation.server.eva.EvaluateExcutorTest.java
@Test public void test() { double d = 0.987; logger.info("String.format = " + String.format("%.2f", d)); DecimalFormat df = new DecimalFormat("*.00"); logger.info("DecimalFormat = " + df.format(d)); NumberFormat nf = NumberFormat.getNumberInstance(); nf.setMaximumFractionDigits(2);//from w w w. j av a 2 s . c om logger.info("NumberFormat = " + nf.format(d)); DecimalFormat formater = new DecimalFormat(); formater.setMaximumFractionDigits(2); formater.setGroupingSize(0); formater.setRoundingMode(RoundingMode.FLOOR); logger.info("DecimalFormat = " + (formater.format(d))); }
From source file:edu.byu.nlp.util.Matrices.java
public static String toString(double[][] mat, int maxRows, int maxCols, int numFractionDigits) { // how many digits are in the biggest number in each column? int[] maxColNumWidths = Matrices.argMaxesInColumns(mat); for (int c = 0; c < maxColNumWidths.length; c++) { maxColNumWidths[c] = strWidthOf(mat[maxColNumWidths[c]][c], numFractionDigits); }//from ww w . j av a 2s . co m DecimalFormat df = new DecimalFormat(); df.setMaximumFractionDigits(numFractionDigits); df.setMinimumFractionDigits(numFractionDigits); df.setGroupingUsed(false); StringBuilder str = new StringBuilder(); str.append('['); int numrows = Math.min(mat.length, maxRows); for (int r = 0; r < numrows; r++) { if (r > 0) { str.append("\n "); } str.append('['); for (int c = 0; c < Math.min(mat[r].length, maxCols); c++) { if (c > 0) { str.append(", "); } int strWidth = strWidthOf(mat[r][c], numFractionDigits); for (int fill = strWidth; fill < maxColNumWidths[c]; fill++) { str.append(' '); } str.append(df.format(mat[r][c])); } if (mat[r].length > maxCols) { str.append(", ..."); } str.append("]"); if (r < numrows - 1) { str.append(","); } } if (mat.length > maxRows) { str.append(",\n ...\n"); } str.append("]"); return str.toString(); }
From source file:org.cleansvg.Formatter.java
String formatFloat(final float number, final boolean space, final int precision) { final long longNumber = (long) number; final String prefix = (space && number >= 0f) ? " " : ""; if (longNumber == number) { return formatLong(longNumber, prefix); }// ww w . ja v a 2 s . co m if (Math.abs(number) < Math.pow(10.0, -precision)) { return space ? " 0" : "0"; } final String formatString = (Math.abs(number) > 0.001f) ? "." : "#.#E0"; final DecimalFormat format = new DecimalFormat(formatString); format.setMaximumFractionDigits(precision); return prefix + StringUtils.stripEnd(format.format(number), "."); }
From source file:org.onebusaway.nyc.webapp.actions.api.siri.impl.SiriSupportV2.java
/** * NOTE: The tripDetails bean here may not be for the trip the vehicle is * currently on in the case of A-D for stop! * @param filters //from w w w. jav a 2 s.c om */ public static void fillMonitoredVehicleJourney(MonitoredVehicleJourneyStructure monitoredVehicleJourney, TripBean framedJourneyTripBean, TripStatusBean currentVehicleTripStatus, StopBean monitoredCallStopBean, OnwardCallsMode onwardCallsMode, PresentationService presentationService, NycTransitDataService nycTransitDataService, int maximumOnwardCalls, List<TimepointPredictionRecord> stopLevelPredictions, DetailLevel detailLevel, long responseTimestamp, Map<Filters, String> filters) { BlockInstanceBean blockInstance = nycTransitDataService.getBlockInstance( currentVehicleTripStatus.getActiveTrip().getBlockId(), currentVehicleTripStatus.getServiceDate()); List<BlockTripBean> blockTrips = blockInstance.getBlockConfiguration().getTrips(); if (monitoredCallStopBean == null) { monitoredCallStopBean = currentVehicleTripStatus.getNextStop(); } /**********************************************/ //Route ID LineRefStructure lineRef = new LineRefStructure(); lineRef.setValue(framedJourneyTripBean.getRoute().getId()); DirectionRefStructure directionRef = new DirectionRefStructure(); directionRef.setValue(framedJourneyTripBean.getDirectionId()); //Route Short Name NaturalLanguageStringStructure routeShortName = new NaturalLanguageStringStructure(); routeShortName.setValue(framedJourneyTripBean.getRoute().getShortName()); //Agency Id OperatorRefStructure operatorRef = new OperatorRefStructure(); operatorRef.setValue(AgencySupportLibrary.getAgencyForId(framedJourneyTripBean.getRoute().getId())); //Framed Journey FramedVehicleJourneyRefStructure framedJourney = new FramedVehicleJourneyRefStructure(); DataFrameRefStructure dataFrame = new DataFrameRefStructure(); dataFrame.setValue(String.format("%1$tY-%1$tm-%1$td", currentVehicleTripStatus.getServiceDate())); framedJourney.setDataFrameRef(dataFrame); framedJourney.setDatedVehicleJourneyRef(framedJourneyTripBean.getId()); //Shape Id JourneyPatternRefStructure journeyPattern = new JourneyPatternRefStructure(); journeyPattern.setValue(framedJourneyTripBean.getShapeId()); //Destination NaturalLanguageStringStructure headsign = new NaturalLanguageStringStructure(); headsign.setValue(framedJourneyTripBean.getTripHeadsign()); // Vehicle Id VehicleRefStructure vehicleRef = new VehicleRefStructure(); vehicleRef.setValue(currentVehicleTripStatus.getVehicleId()); // Set Origin and Destination stops from Block trips. StopBean lastStop = new StopBean(); JourneyPlaceRefStructure origin = new JourneyPlaceRefStructure(); for (int i = 0; i < blockTrips.size(); i++) { BlockTripBean blockTrip = blockTrips.get(i); if (blockTrip.getTrip().getId().equals(framedJourneyTripBean.getId())) { List<BlockStopTimeBean> stops = blockTrip.getBlockStopTimes(); origin.setValue(stops.get(0).getStopTime().getStop().getId()); lastStop = stops.get(stops.size() - 1).getStopTime().getStop(); break; } } // location // if vehicle is detected to be on detour, use actual lat/lon, not // snapped location. LocationStructure location = new LocationStructure(); DecimalFormat df = new DecimalFormat(); df.setMaximumFractionDigits(6); if (presentationService.isOnDetour(currentVehicleTripStatus)) { location.setLatitude( new BigDecimal(df.format(currentVehicleTripStatus.getLastKnownLocation().getLat()))); location.setLongitude( new BigDecimal(df.format(currentVehicleTripStatus.getLastKnownLocation().getLon()))); } else { location.setLatitude(new BigDecimal(df.format(currentVehicleTripStatus.getLocation().getLat()))); location.setLongitude(new BigDecimal(df.format(currentVehicleTripStatus.getLocation().getLon()))); } // progress status List<String> progressStatuses = new ArrayList<String>(); if (presentationService.isInLayover(currentVehicleTripStatus)) { progressStatuses.add("layover"); } // "prevTrip" really means not on the framedvehiclejourney trip if (!framedJourneyTripBean.getId().equals(currentVehicleTripStatus.getActiveTrip().getId())) { progressStatuses.add("prevTrip"); } if (!progressStatuses.isEmpty()) { NaturalLanguageStringStructure progressStatus = new NaturalLanguageStringStructure(); progressStatus.setValue(StringUtils.join(progressStatuses, ",")); monitoredVehicleJourney.getProgressStatus().add(progressStatus); } // scheduled depature time if (presentationService.isBlockLevelInference(currentVehicleTripStatus) && (presentationService .isInLayover(currentVehicleTripStatus) || !framedJourneyTripBean.getId().equals(currentVehicleTripStatus.getActiveTrip().getId()))) { BlockStopTimeBean originDepartureStopTime = null; for (int t = 0; t < blockTrips.size(); t++) { BlockTripBean thisTrip = blockTrips.get(t); BlockTripBean nextTrip = null; if (t + 1 < blockTrips.size()) { nextTrip = blockTrips.get(t + 1); } if (thisTrip.getTrip().getId().equals(currentVehicleTripStatus.getActiveTrip().getId())) { // just started new trip if (currentVehicleTripStatus.getDistanceAlongTrip() < (0.5 * currentVehicleTripStatus.getTotalDistanceAlongTrip())) { originDepartureStopTime = thisTrip.getBlockStopTimes().get(0); // at end of previous trip } else { if (nextTrip != null) { originDepartureStopTime = nextTrip.getBlockStopTimes().get(0); } } break; } } if (originDepartureStopTime != null) { long departureTime = currentVehicleTripStatus.getServiceDate() + (originDepartureStopTime.getStopTime().getDepartureTime() * 1000); monitoredVehicleJourney.setOriginAimedDepartureTime(DateUtil.toXmlGregorianCalendar(departureTime)); } } Map<String, TimepointPredictionRecord> stopIdToPredictionRecordMap = new HashMap<String, TimepointPredictionRecord>(); // (build map of stop IDs to TPRs) if (stopLevelPredictions != null) { for (TimepointPredictionRecord tpr : stopLevelPredictions) { stopIdToPredictionRecordMap.put(AgencyAndId.convertToString(tpr.getTimepointId()), tpr); } } // monitored call if (!presentationService.isOnDetour(currentVehicleTripStatus)) fillMonitoredCall(monitoredVehicleJourney, blockInstance, currentVehicleTripStatus, monitoredCallStopBean, presentationService, nycTransitDataService, stopIdToPredictionRecordMap, detailLevel, responseTimestamp); // detail level - minimal monitoredVehicleJourney.getPublishedLineName().add(routeShortName); monitoredVehicleJourney.getDestinationName().add(headsign); monitoredVehicleJourney.setMonitored(currentVehicleTripStatus.isPredicted()); monitoredVehicleJourney.setVehicleRef(vehicleRef); monitoredVehicleJourney.setBearing((float) currentVehicleTripStatus.getOrientation()); monitoredVehicleJourney.setVehicleLocation(location); // detail level - basic if (detailLevel.equals(DetailLevel.BASIC) || detailLevel.equals(DetailLevel.NORMAL) || detailLevel.equals(DetailLevel.CALLS)) { monitoredVehicleJourney.setFramedVehicleJourneyRef(framedJourney); monitoredVehicleJourney.setDirectionRef(directionRef); // since LineRef is fully qualified with operatorref, moving OperatorRef to normal detail //monitoredVehicleJourney.setOperatorRef(operatorRef); DestinationRefStructure dest = new DestinationRefStructure(); dest.setValue(lastStop.getId()); monitoredVehicleJourney.setDestinationRef(dest); monitoredVehicleJourney.setLineRef(lineRef); monitoredVehicleJourney.setProgressRate(getProgressRateForPhaseAndStatus( currentVehicleTripStatus.getStatus(), currentVehicleTripStatus.getPhase())); } // detail level - normal if (detailLevel.equals(DetailLevel.NORMAL) || detailLevel.equals(DetailLevel.CALLS)) { monitoredVehicleJourney.setOperatorRef(operatorRef); // block ref if (presentationService.isBlockLevelInference(currentVehicleTripStatus)) { BlockRefStructure blockRef = new BlockRefStructure(); blockRef.setValue(framedJourneyTripBean.getBlockId()); monitoredVehicleJourney.setBlockRef(blockRef); } monitoredVehicleJourney.setOriginRef(origin); monitoredVehicleJourney.setJourneyPatternRef(journeyPattern); } // onward calls if (detailLevel.equals(DetailLevel.CALLS)) { if (!presentationService.isOnDetour(currentVehicleTripStatus)) fillOnwardCalls(monitoredVehicleJourney, blockInstance, framedJourneyTripBean, currentVehicleTripStatus, onwardCallsMode, presentationService, nycTransitDataService, stopIdToPredictionRecordMap, maximumOnwardCalls, responseTimestamp); } // situations fillSituations(monitoredVehicleJourney, currentVehicleTripStatus); return; }