本文整理了Java中slash.common.io.Transfer.formatIntAsString()
方法的一些代码示例,展示了Transfer.formatIntAsString()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Transfer.formatIntAsString()
方法的具体详情如下:
包路径:slash.common.io.Transfer
类名称:Transfer
方法名:formatIntAsString
暂无
代码示例来源:origin: cpesch/RouteConverter
public static String formatDuration(long milliseconds) {
long seconds = milliseconds / 1000;
long minutes = seconds / 60;
long hours = minutes / 60;
return formatIntAsString((int) hours, 2) + ":" + formatIntAsString((int) minutes % 60, 2) + ":" + formatIntAsString((int) seconds % 60, 2);
}
代码示例来源:origin: cpesch/RouteConverter
public static String formatIntAsString(Integer anInteger, int exactDigitCount) {
StringBuilder buffer = new StringBuilder(formatIntAsString(anInteger));
while (buffer.length() < exactDigitCount)
buffer.insert(0, "0");
return buffer.toString();
}
代码示例来源:origin: cpesch/RouteConverter
public static String getNumberedPosition(NavigationPosition position, int index,
int digitCount, NumberPattern numberPattern) {
String number = formatIntAsString((index + 1), digitCount);
String comment = getPositionDescription(position, index);
Matcher matcher = NUMBER_PATTERN.matcher(comment);
String description = matcher.matches() ? matcher.group(2) : comment;
return formatNumberedPosition(numberPattern, number, trim(description));
}
代码示例来源:origin: cpesch/RouteConverter
Wgs84Position position = positions.get(i);
writer.println(START_STOP + NAME_VALUE_SEPARATOR + STOP + " " + i);
String longitude = formatIntAsString(position.getLongitude() != null ? (int) (position.getLongitude() * INTEGER_FACTOR) : null);
writer.println(LONGITUDE + NAME_VALUE_SEPARATOR + longitude);
String latitude = formatIntAsString(position.getLatitude() != null ? (int) (position.getLatitude() * INTEGER_FACTOR) : null);
writer.println(LATITUDE + NAME_VALUE_SEPARATOR + latitude);
代码示例来源:origin: cpesch/RouteConverter
@Test
public void testFormatIntAsString() {
assertEquals("1", formatIntAsString(1, 1));
assertEquals("01", formatIntAsString(1, 2));
assertEquals("001", formatIntAsString(1, 3));
assertEquals("100", formatIntAsString(100, 1));
assertEquals("100", formatIntAsString(100, 2));
assertEquals("100", formatIntAsString(100, 3));
assertEquals("0100", formatIntAsString(100, 4));
assertEquals("00100", formatIntAsString(100, 5));
}
代码示例来源:origin: cpesch/RouteConverter
public void write(List<MagicMapsIktRoute> routes, OutputStream target) throws IOException {
try {
XMLEventFactory eventFactory = XMLEventFactory.newInstance();
XMLOutputFactory output = XMLOutputFactory.newInstance();
XMLEventWriter writer = output.createXMLEventWriter(target, UTF8_ENCODING);
try {
writeHeader(getProjectName(routes), getDescription(routes), writer, eventFactory);
writer.add(eventFactory.createStartElement(new QName(COUNT_ELEMENT), null, null));
writer.add(eventFactory.createCharacters(formatIntAsString(routes.size())));
writer.add(eventFactory.createEndElement(new QName(COUNT_ELEMENT), null));
for (int i = 0; i < routes.size(); i++) {
writeRoute(routes.get(i), i, writer, eventFactory);
}
writeFooter(writer, eventFactory);
} finally {
writer.flush();
writer.close();
target.flush();
target.close();
}
} catch (XMLStreamException e) {
throw new IOException("Error while marshalling: " + e, e);
}
}
}
代码示例来源:origin: cpesch/RouteConverter
public void write(TomTomRoute route, PrintWriter writer, int startIndex, int endIndex) {
List<TomTomPosition> positions = route.getPositions();
for (int i = startIndex; i < endIndex; i++) {
TomTomPosition position = positions.get(i);
String longitude = formatIntAsString(position.getLongitudeAsInt());
String latitude = formatIntAsString(position.getLatitudeAsInt());
boolean first = i == startIndex;
boolean last = i == endIndex - 1;
int type = WAYPOINT;
if (first)
type = START_TYPE;
else if (last)
type = END_TYPE;
String description = position.getDescription();
if (route.getCharacteristics().equals(Track)) {
Double distance = route.getDistance(startIndex, i);
if (first)
description = formatFirstOrLastName(position, "Start", distance);
else if (last)
description = formatFirstOrLastName(position, "Finish", distance);
else
description = formatIntermediateName(position, distance);
}
description = escape(description);
writer.println(longitude + SEPARATOR + latitude + SEPARATOR + description + SEPARATOR + type + SEPARATOR);
}
}
}
代码示例来源:origin: cpesch/RouteConverter
protected void writePosition(Wgs84Position position, PrintWriter writer, int index, boolean firstPosition) {
String longitude = formatPositionAsString(position.getLongitude());
String latitude = formatPositionAsString(position.getLatitude());
String altitude = formatElevationAsString(position.getElevation());
String speed = formatSpeedAsString(position.getSpeed());
String time = formatTime(position.getTime());
String heading = position.getHeading() != null ? formatIntAsString(position.getHeading().intValue()) : "0";
writer.println(latitude + SEPARATOR + longitude + SEPARATOR + altitude + SEPARATOR +
speed + SEPARATOR + time + SEPARATOR + (firstPosition ? "1" : "0") + SEPARATOR + heading);
}
}
代码示例来源:origin: cpesch/RouteConverter
private void writeRoute(MagicMapsIktRoute route, int index, XMLEventWriter writer, XMLEventFactory eventFactory) throws XMLStreamException {
writer.add(eventFactory.createStartElement(new QName(GEO_OBJECT_ELEMENT + "_" + index), null, null));
writer.add(eventFactory.createStartElement(new QName(GEO_OBJECT_TYPE_ELEMENT), null, null));
writer.add(eventFactory.createCharacters("1"));
writer.add(eventFactory.createEndElement(new QName(GEO_OBJECT_TYPE_ELEMENT), null));
writer.add(eventFactory.createStartElement(new QName(NAME_ELEMENT), null, null));
writer.add(eventFactory.createCharacters(asRouteName(route.getName())));
writer.add(eventFactory.createEndElement(new QName(NAME_ELEMENT), null));
writer.add(eventFactory.createStartElement(new QName(PATH_DRAW_TYPE_ELEMENT), null, null));
writer.add(eventFactory.createCharacters("5"));
writer.add(eventFactory.createEndElement(new QName(PATH_DRAW_TYPE_ELEMENT), null));
writer.add(eventFactory.createStartElement(new QName(PATH_POINTS_ELEMENT), null, null));
List<Wgs84Position> positions = route.getPositions();
writer.add(eventFactory.createStartElement(new QName(COUNT_ELEMENT), null, null));
writer.add(eventFactory.createCharacters(formatIntAsString(positions.size())));
writer.add(eventFactory.createEndElement(new QName(COUNT_ELEMENT), null));
for (int i = 0; i < positions.size(); i++) {
writePosition(positions.get(i), i, writer, eventFactory);
}
writer.add(eventFactory.createEndElement(new QName(PATH_POINTS_ELEMENT), null));
writer.add(eventFactory.createEndElement(new QName(GEO_OBJECT_ELEMENT + "_" + index), null));
}
代码示例来源:origin: cpesch/RouteConverter
protected void writePosition(Wgs84Position position, PrintWriter writer, int index, boolean firstPosition) {
String date = fillWithZeros(formatDate(position.getTime()), 6);
String time = fillWithZeros(formatTime(position.getTime()), 6);
String latitude = formatDoubleAsString(abs(position.getLatitude()), 6);
String northOrSouth = position.getLatitude() != null && position.getLatitude() < 0.0 ? "S" : "N";
String longitude = formatDoubleAsString(abs(position.getLongitude()), 6);
String westOrEast = position.getLongitude() != null && position.getLongitude() < 0.0 ? "W" : "E";
String height = fillWithZeros(position.getElevation() != null ? formatIntAsString(position.getElevation().intValue()) : "0", 5);
String speed = position.getSpeed() != null ? formatDoubleAsString(position.getSpeed()) : "0";
String heading = fillWithZeros(position.getHeading() != null ? formatIntAsString(position.getHeading().intValue()) : "0", 3);
String pressure = position.getPressure() != null ? formatDoubleAsString(position.getPressure()) : "0";
String temperature = fillWithZeros(position.getTemperature() != null ? formatIntAsString(position.getTemperature().intValue()) : "0", 2);
String description = !isPositionDescription(position.getDescription()) ? position.getDescription() : "";
writer.println(fillWithZeros(Integer.toString(index + 1), 6) + SEPARATOR +
formatTag(position) + SEPARATOR +
date + SEPARATOR + time + SEPARATOR +
latitude + northOrSouth + SEPARATOR +
longitude + westOrEast + SEPARATOR +
height + SEPARATOR +
speed + SEPARATOR +
heading + SEPARATOR +
pressure + SEPARATOR +
temperature + SEPARATOR +
fillWithZeros(escape(description, SEPARATOR, ';'), 8));
}
}
代码示例来源:origin: cpesch/RouteConverter
String longitude = formatDoubleAsString(abs(position.getLongitude()), 6);
String westOrEast = position.getLongitude() != null && position.getLongitude() < 0.0 ? "W" : "E";
String height = fillWithZeros(position.getElevation() != null ? formatIntAsString(position.getElevation().intValue()) : "0", 5);
String speed = fillWithZeros(position.getSpeed() != null ? formatIntAsString(position.getSpeed().intValue()) : "0", 4);
String heading = fillWithZeros(position.getHeading() != null ? formatIntAsString(position.getHeading().intValue()) : "0", 3);
String pdop = fillWithZeros(position.getPdop() != null ? formatAccuracyAsString(position.getPdop()) : "", 5);
String hdop = fillWithZeros(position.getHdop() != null ? formatAccuracyAsString(position.getHdop()) : "", 5);
代码示例来源:origin: cpesch/RouteConverter
protected void writePosition(NmeaPosition position, PrintWriter writer) {
ValueAndOrientation longitudeAsValueAndOrientation = position.getLongitudeAsValueAndOrientation();
String longitude = formatLongitude(longitudeAsValueAndOrientation.getValue());
String westOrEast = longitudeAsValueAndOrientation.getOrientation().value();
ValueAndOrientation latitudeAsValueAndOrientation = position.getLatitudeAsValueAndOrientation();
String latitude = formatLatitude(latitudeAsValueAndOrientation.getValue());
String northOrSouth = latitudeAsValueAndOrientation.getOrientation().value();
String description = escape(position.getDescription(), SEPARATOR, ';');
String altitude = formatIntAsString(position.getElevation() != null ? position.getElevation().intValue() : null);
String wpl = "PMGNWPL" + SEPARATOR +
latitude + SEPARATOR + northOrSouth + SEPARATOR + longitude + SEPARATOR + westOrEast + SEPARATOR +
altitude + SEPARATOR + "M" + SEPARATOR + description + SEPARATOR + SEPARATOR + "a";
writeSentence(writer, wpl);
}
代码示例来源:origin: cpesch/RouteConverter
protected void writePosition(Wgs84Position position, PrintWriter writer, int index, boolean firstPosition) {
String date = formatDate(position.getTime());
String time = formatTime(position.getTime());
String latitude = formatDoubleAsString(abs(position.getLatitude()), 6);
String northOrSouth = position.getLatitude() != null && position.getLatitude() < 0.0 ? "S" : "N";
String longitude = formatDoubleAsString(abs(position.getLongitude()), 6);
String westOrEast = position.getLongitude() != null && position.getLongitude() < 0.0 ? "W" : "E";
String height = position.getElevation() != null ? formatElevationAsString(position.getElevation()) : "0.0";
String speed = position.getSpeed() != null ? formatSpeedAsString(position.getSpeed()) : "0.0";
String hdop = position.getHdop() != null ? formatAccuracyAsString(position.getHdop()) : "0.0";
String satellites = position.getSatellites() != null ? formatIntAsString(position.getSatellites()) : "0";
if (firstPosition)
previousPosition = null;
String distance = previousPosition != null ? formatElevationAsString(position.calculateDistance(previousPosition)) : "0.0";
previousPosition = position;
writer.println(Integer.toString(index + 1) + SEPARATOR + "T" + SEPARATOR +
date + SEPARATOR + time + SEPARATOR + "SPS" + SEPARATOR +
latitude + SEPARATOR + northOrSouth + SEPARATOR +
longitude + SEPARATOR + westOrEast + SEPARATOR +
height + " m" + SEPARATOR +
speed + " km/h" + SEPARATOR +
hdop + SEPARATOR +
satellites + "(" + satellites + ")" + SEPARATOR +
distance + " m" + SEPARATOR);
}
}
代码示例来源:origin: cpesch/RouteConverter
protected void writePosition(Wgs84Position position, PrintWriter writer, int index, boolean firstPosition) {
String longitude = formatPositionAsString(position.getLongitude());
String latitude = formatPositionAsString(position.getLatitude());
String time = formatTime(position.getTime());
String heading = formatHeadingAsString(position.getHeading());
String speed = formatSpeedAsString(position.getSpeed());
String hdop = formatAccuracyAsString(position.getHdop());
Integer satellites = position.getSatellites();
// since positions with zero satellites are ignored during reading
if (satellites == null || satellites == 0)
satellites = 1;
String satellitesStr = formatIntAsString(satellites);
writer.println("0" + SEPARATOR + " " +
time + SEPARATOR + " " +
longitude + SEPARATOR + " " +
latitude + SEPARATOR + " " +
heading + SEPARATOR + " " +
speed + SEPARATOR + " " +
"1" + SEPARATOR + " " +
hdop + SEPARATOR + " " +
satellitesStr);
}
}
代码示例来源:origin: cpesch/RouteConverter
String latitude = formatLatitude(latitudeAsValueAndOrientation.getValue());
String northOrSouth = latitudeAsValueAndOrientation.getOrientation().value();
String satellites = position.getSatellites() != null ? formatIntAsString(position.getSatellites()) : "";
String description = escape(position.getDescription(), SEPARATOR, ';');
String time = formatTime(position.getTime());
内容来源于网络,如有侵权,请联系作者删除!