@Test public void getSurveyIdFromFilePath_shouldReturnEmptyIfFolderMissing() { SurveyIdGenerator surveyIdGenerator = new SurveyIdGenerator(); String surveyId = surveyIdGenerator.getSurveyIdFromFilePath("file.xml"); assertEquals("", surveyId); }
@NonNull public String getSurveyIdFromFilePath(@NonNull String entryName) { int fileSeparatorPosition = entryName.lastIndexOf("/"); String folderPath = fileSeparatorPosition <= 0 ? "" : entryName.substring(0, fileSeparatorPosition); String folders[] = folderPath == null || folderPath.isEmpty()? null : folderPath.split("/"); if (folders == null || folders.length == 0) { return ""; } else { int lastItemIndex = folders.length - 1; for (int i = lastItemIndex; i >= 0; i--) { String folderName = folders[i]; if (TextUtils.isDigitsOnly(folderName)) { return folderName; } } return folders[lastItemIndex]; } }
SurveyIdGenerator { @NonNull public String getSurveyIdFromFilePath(@NonNull String entryName) { int fileSeparatorPosition = entryName.lastIndexOf("/"); String folderPath = fileSeparatorPosition <= 0 ? "" : entryName.substring(0, fileSeparatorPosition); String folders[] = folderPath == null || folderPath.isEmpty()? null : folderPath.split("/"); if (folders == null || folders.length == 0) { return ""; } else { int lastItemIndex = folders.length - 1; for (int i = lastItemIndex; i >= 0; i--) { String folderName = folders[i]; if (TextUtils.isDigitsOnly(folderName)) { return folderName; } } return folders[lastItemIndex]; } } }
SurveyIdGenerator { @NonNull public String getSurveyIdFromFilePath(@NonNull String entryName) { int fileSeparatorPosition = entryName.lastIndexOf("/"); String folderPath = fileSeparatorPosition <= 0 ? "" : entryName.substring(0, fileSeparatorPosition); String folders[] = folderPath == null || folderPath.isEmpty()? null : folderPath.split("/"); if (folders == null || folders.length == 0) { return ""; } else { int lastItemIndex = folders.length - 1; for (int i = lastItemIndex; i >= 0; i--) { String folderName = folders[i]; if (TextUtils.isDigitsOnly(folderName)) { return folderName; } } return folders[lastItemIndex]; } } SurveyIdGenerator(); }
SurveyIdGenerator { @NonNull public String getSurveyIdFromFilePath(@NonNull String entryName) { int fileSeparatorPosition = entryName.lastIndexOf("/"); String folderPath = fileSeparatorPosition <= 0 ? "" : entryName.substring(0, fileSeparatorPosition); String folders[] = folderPath == null || folderPath.isEmpty()? null : folderPath.split("/"); if (folders == null || folders.length == 0) { return ""; } else { int lastItemIndex = folders.length - 1; for (int i = lastItemIndex; i >= 0; i--) { String folderName = folders[i]; if (TextUtils.isDigitsOnly(folderName)) { return folderName; } } return folders[lastItemIndex]; } } SurveyIdGenerator(); @NonNull String getSurveyIdFromFilePath(@NonNull String entryName); }
SurveyIdGenerator { @NonNull public String getSurveyIdFromFilePath(@NonNull String entryName) { int fileSeparatorPosition = entryName.lastIndexOf("/"); String folderPath = fileSeparatorPosition <= 0 ? "" : entryName.substring(0, fileSeparatorPosition); String folders[] = folderPath == null || folderPath.isEmpty()? null : folderPath.split("/"); if (folders == null || folders.length == 0) { return ""; } else { int lastItemIndex = folders.length - 1; for (int i = lastItemIndex; i >= 0; i--) { String folderName = folders[i]; if (TextUtils.isDigitsOnly(folderName)) { return folderName; } } return folders[lastItemIndex]; } } SurveyIdGenerator(); @NonNull String getSurveyIdFromFilePath(@NonNull String entryName);  }