/** * Splits a string at the specified delimiter into multiple substrings. This * method is similar to <code>String.split()</code>, but does only take a * single char as a delimiter and not a regular expression, making this * method a lot faster than <code>String.split()</code> if no regular * expressions are required. * * @param str The string to be splitted. * @param delimiter A single character where <code>str</code> should be splitted. * @return Returns an array of strings, each being a substring of * <code>str</code>, that were connected by <code>delimiter</code> in the * original string <code>str</code>. * @author mrieser */ public static String[] explode(final String str, final char delimiter) { return explode(str, delimiter, 0); } }
private static String[] toArray( final String modes ) { String[] parts = StringUtils.explode(modes, ','); for (int i = 0, n = parts.length; i < n; i++) { parts[i] = parts[i].trim().intern(); } return parts; }
private static String[] toArray( final String modes ) { String[] parts = StringUtils.explode(modes, ','); for (int i = 0, n = parts.length; i < n; i++) { parts[i] = parts[i].trim().intern(); } return parts; }
public void setParameters(String parameter) { if (!parameter.equalsIgnoreCase("")) { String[] parts = StringUtils.explode(parameter, ','); this.parameters = new String[parts.length]; for (int i = 0, n = parts.length; i < n; i++) { this.parameters[i] = parts[i].trim().intern(); } } }
@StringSetter( SNAPSHOT_FORMAT ) private void setSnapshotFormats( final String value ) { String[] parts = StringUtils.explode(value, ','); Set<String> formats = new HashSet<>(); for (String part : parts) { String trimmed = part.trim(); if (trimmed.length() > 0) { formats.add(trimmed); } } this.snapshotFormat = formats; }
public static final Set<String> stringToSet(final String values) { if (values == null) { return Collections.emptySet(); } String[] parts = StringUtils.explode(values, ','); Set<String> tmp = new LinkedHashSet<String>(); for (String part : parts) { String trimmed = part.trim(); if (trimmed.length() > 0) { tmp.add(trimmed.intern()); } } return tmp; }
@StringSetter( EVENTS_FILE_FORMAT ) private void setEventFileFormats( final String value ) { String[] parts = StringUtils.explode(value, ','); Set<EventsFileFormat> formats = EnumSet.noneOf(EventsFileFormat.class); for (String part : parts) { String trimmed = part.trim(); if (trimmed.length() > 0) { formats.add(EventsFileFormat.valueOf(trimmed)); } } this.eventsFileFormats = formats; }
private Set<Id<Link>> stringToLinkIdSet(String linkIds) { if (linkIds == null) { return Collections.emptySet(); } String[] parts = StringUtils.explode(linkIds, ','); Set<Id<Link>> tmp = new LinkedHashSet<Id<Link>>(); for (String part : parts) { String trimmed = part.trim(); if (trimmed.length() > 0) { tmp.add(Id.createLinkId(trimmed.intern())); } } return tmp; }
private void readVersion(final String tableAttributes, final BufferedReader reader) throws IOException { final String[] attributes = StringUtils.explode(tableAttributes.substring("$VERSION:".length()), ';'); final int idxLanguage = getAttributeIndex("LANGUAGE", attributes); String line = reader.readLine(); if (line == null) { throw new RuntimeException("Language definition cannot be found."); } final String[] parts = StringUtils.explode(line, ';'); if (parts[idxLanguage].equals("ENG")) { this.language = 0; } else if (parts[idxLanguage].equals("DEU")) { this.language = 1; } else { throw new RuntimeException("Unknown language: " + parts[idxLanguage]); } // proceed to next line, assumed to be empty reader.readLine(); }
private void readDepartureSections(final String tableAttributes, final BufferedReader reader) throws IOException { final String[] attributes = StringUtils.explode(tableAttributes.substring(this.TABLE_VEHJOURNEYSECTION[this.language].length()), ';'); final int idxVehicleJourneyNo = getAttributeIndex(this.ATTRIBUTE_VJS_VEHJOURNEYNO[this.language], attributes); final int idxVehCombinationNo = getAttributeIndex(this.ATTRIBUTE_VJS_VEHCOMBNO[this.language], attributes); String line = reader.readLine(); while (line != null && line.length() > 0) { final String[] parts = StringUtils.explode(line, ';'); String vehJourneyNo = parts[idxVehicleJourneyNo]; String vehCombNo = parts[idxVehCombinationNo]; VisumNetwork.Departure d = this.network.departuresByNo.get(vehJourneyNo); d.vehCombinationNo = vehCombNo; // proceed to next line line = reader.readLine(); } }
private void readVehicleUnitToVehicleCombination(final String tableAttributes, final BufferedReader reader) throws IOException { final String[] attributes = StringUtils.explode(tableAttributes.substring(this.TABLE_VEHUNITTOVEHCOMB[this.language].length()), ';'); final int idxVehicleUnit = getAttributeIndex(this.ATTRIBUTE_VEHUNITTOVEHCOMB_VEHUNITNO[this.language], attributes); final int idxVehicleComb = getAttributeIndex(this.ATTRIBUTE_VEHUNITTOVEHCOMB_VEHCOMBNO[this.language], attributes); final int idxVehicleNumber = getAttributeIndex(this.ATTRIBUTE_VEHUNITTOVEHCOMB_NUMVEHUNITS[this.language], attributes); String line = reader.readLine(); while (line != null && line.length() > 0) { final String[] parts = StringUtils.explode(line, ';'); VisumNetwork.VehicleCombination vehicleComb = this.network.vehicleCombinations.get(parts[idxVehicleComb]); vehicleComb.vehUnitId = parts[idxVehicleUnit]; vehicleComb.numOfVehicles = Integer.parseInt(parts[idxVehicleNumber]); // proceed to next line line = reader.readLine(); } }
private void readVehicleCombinations(final String tableAttributes, final BufferedReader reader) throws IOException { final String[] attributes = StringUtils.explode(tableAttributes.substring(this.TABLE_VEHCOMB[this.language].length()), ';'); final int idxId = getAttributeIndex(this.ATTRIBUTE_VEHCOMB_NO[this.language], attributes); final int idxName = getAttributeIndex(this.ATTRIBUTE_VEHCOMB_NAME[this.language], attributes); String line = reader.readLine(); while (line != null && line.length() > 0) { final String[] parts = StringUtils.explode(line, ';'); VisumNetwork.VehicleCombination vehicleComb = new VisumNetwork.VehicleCombination(parts[idxId], parts[idxName]); this.network.addVehicleCombination(vehicleComb); // proceed to next line line = reader.readLine(); } }
private void scanZIPFile(ZipFile zipFile) { this.nextTime = -1; Enumeration<? extends ZipEntry> zipFileEntries = zipFile.entries(); System.out.println("Scanning timesteps:"); Gbl.startMeasurement(); while (zipFileEntries.hasMoreElements()) { ZipEntry entry = zipFileEntries.nextElement(); String currentEntry = entry.getName(); if (currentEntry.contains("step")) { String[] spliti = StringUtils.explode(currentEntry, '.', 10); double time_s = Double.parseDouble(spliti[1]); if (this.nextTime == -1) { this.nextTime = time_s; } this.timesteps.put(time_s, entry.getSize()); System.out.print(time_s); System.out.print(", "); } } System.out.println(""); System.out.println("Nr of timesteps: " + this.timesteps.size()); }
private void readVehicleUnits(final String tableAttributes, final BufferedReader reader) throws IOException { final String[] attributes = StringUtils.explode(tableAttributes.substring(this.TABLE_VEHUNIT[this.language].length()), ';'); final int idxId = getAttributeIndex(this.ATTRIBUTE_VEHUNIT_ID[this.language], attributes); final int idxCode = getAttributeIndex(this.ATTRIBUTE_VEHUNIT_CODE[this.language], attributes); final int idxSeatCap = getAttributeIndex(this.ATTRIBUTE_VEHUNIT_SEATCAP[this.language], attributes); final int idxTotalCap = getAttributeIndex(this.ATTRIBUTE_VEHUNIT_TOTALCAP[this.language], attributes); String line = reader.readLine(); while (line != null && line.length() > 0) { final String[] parts = StringUtils.explode(line, ';'); VisumNetwork.VehicleUnit vehicleUnit = new VisumNetwork.VehicleUnit(parts[idxId], parts[idxCode], Integer.parseInt(parts[idxSeatCap]), Integer.parseInt(parts[idxTotalCap])); this.network.addVehicleUnit(vehicleUnit); // proceed to next line line = reader.readLine(); } }
private void readStopAreas(final String tableAttributes, final BufferedReader reader) throws IOException { final String[] attributes = StringUtils.explode(tableAttributes.substring(this.TABLE_STOPAREA[this.language].length()), ';'); final int idxNo = getAttributeIndex(this.ATTRIBUTE_STOPAREA_NO[this.language], attributes); final int idxStopId = getAttributeIndex(this.ATTRIBUTE_STOPAREA_STOPNO[this.language], attributes); String line = reader.readLine(); while (line != null && line.length() > 0) { final String[] parts = StringUtils.explode(line, ';'); VisumNetwork.StopArea stopAr = new VisumNetwork.StopArea(Id.create(parts[idxNo], VisumNetwork.StopArea.class), Id.create(parts[idxStopId], VisumNetwork.Stop.class)); this.network.addStopArea(stopAr); // proceed to next line line = reader.readLine(); } } private void readStopPoints(final String tableAttributes, final BufferedReader reader) throws IOException {
private void readLines(final String tableAttributes, final BufferedReader reader) throws IOException { final String[] attributes = StringUtils.explode(tableAttributes.substring(this.TABLE_LINE[this.language].length()), ';'); final int idxName = getAttributeIndex(this.ATTRIBUTE_L_NAME[this.language], attributes); final int idxTCode = getAttributeIndex(this.ATTRIBUTE_L_TCODE[this.language], attributes); final int idxVehCombNo = getAttributeIndex(this.ATTRIBUTE_L_VEHCOMBNO[this.language], attributes); String line = reader.readLine(); while (line != null && line.length() > 0) { final String[] parts = StringUtils.explode(line, ';'); VisumNetwork.TransitLine tLine = new VisumNetwork.TransitLine( Id.create(parts[idxName], TransitLine.class), parts[idxTCode], parts[idxVehCombNo]); this.network.addline(tLine); // proceed to next line line = reader.readLine(); } } private void readLineRouteItems(final String tableAttributes, final BufferedReader reader) throws IOException {
private void readEdgeTypes(String tableAttributes, BufferedReader reader) throws IOException { final String[] attributes = StringUtils.explode(tableAttributes.substring(this.TABLE_LINKTYPE[this.language].length()), ';'); final int idxNo = getAttributeIndex(this.ATTRIBUTE_LINKTYPE_NO[this.language], attributes); final int idxKapIV = getAttributeIndex(this.ATTRIBUTE_LINKTYPE_KAPIV[this.language], attributes); final int idxV0IV = getAttributeIndex(this.ATTRIBUTE_LINKTYPE_V0IV[this.language], attributes); final int idxNoOfLanes = getAttributeIndex(this.ATTRIBUTE_LINKTYPE_NOLANES[this.language], attributes); String line = reader.readLine(); while (line != null && line.length() > 0) { final String[] parts = StringUtils.explode(line, ';'); VisumNetwork.EdgeType edgeType = new VisumNetwork.EdgeType(Id.create(parts[idxNo], VisumNetwork.EdgeType.class), parts[idxKapIV], parts[idxV0IV], parts[idxNoOfLanes]); this.network.addEdgeType(edgeType); // proceed to next line line = reader.readLine(); } }
private void readStops(final String tableAttributes, final BufferedReader reader) throws IOException { final String[] attributes = StringUtils.explode(tableAttributes.substring(this.TABLE_STOP[this.language].length()), ';'); final int idxNo = getAttributeIndex(this.ATTRIBUTE_STOP_NO[this.language], attributes); final int idxName = getAttributeIndex(this.ATTRIBUTE_STOP_NAME[this.language], attributes); final int idxXcoord = getAttributeIndex(this.ATTRIBUTE_STOP_XCOORD[this.language], attributes); final int idxYcoord = getAttributeIndex(this.ATTRIBUTE_STOP_YCOORD[this.language], attributes); String line = reader.readLine(); while (line != null && line.length() > 0) { final String[] parts = StringUtils.explode(line, ';'); VisumNetwork.Stop stop = new VisumNetwork.Stop(Id.create(parts[idxNo], VisumNetwork.Stop.class), parts[idxName], new Coord(Double.parseDouble(parts[idxXcoord].replace(',', '.')), Double.parseDouble(parts[idxYcoord].replace(',', '.')))); this.network.addStop(stop); // proceed to next line line = reader.readLine(); } }
private void readDepartures(final String tableAttributes, final BufferedReader reader) throws IOException { final String[] attributes = StringUtils.explode(tableAttributes.substring(this.TABLE_VEHJOURNEY[this.language].length()), ';'); final int idxLineRouteName = getAttributeIndex(this.ATTRIBUTE_D_LRNAME[this.language], attributes); final int idxLineName = getAttributeIndex(this.ATTRIBUTE_D_LNAME[this.language], attributes); final int idxNo = getAttributeIndex(this.ATTRIBUTE_D_ID[this.language], attributes); final int idxTRI = getAttributeIndex(this.ATTRIBUTE_D_TPNAME[this.language], attributes); final int idxDep = getAttributeIndex(this.ATTRIBUTE_D_DEP[this.language], attributes); final int idxDCode = getAttributeIndex(this.ATTRIBUTE_D_DCODE[this.language], attributes); String line = reader.readLine(); while (line != null && line.length() > 0) { final String[] parts = StringUtils.explode(line, ';'); VisumNetwork.Departure d = new VisumNetwork.Departure(parts[idxLineName], parts[idxLineRouteName], parts[idxNo], parts[idxTRI], parts[idxDep], parts[idxDCode]); this.network.addDeparture(d); // proceed to next line line = reader.readLine(); } }