Merge pull request 'Fix #95' (#111) from fix96 into master
flavien's git/Projet_JAVA_P2P_STRI2A/pipeline/head This commit looks good
Details
flavien's git/Projet_JAVA_P2P_STRI2A/pipeline/head This commit looks good
Details
commit
cd7d83fb0d
@ -0,0 +1,60 @@
|
||||
package tools;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/** Helper to search for files.
|
||||
* @author Louis Royer
|
||||
* @author Flavien Haas
|
||||
* @author JS Auge
|
||||
* @version 1.0
|
||||
*/
|
||||
public class SearchFile {
|
||||
|
||||
/** search correspondance of a String in a String array.
|
||||
* @param filesArray is the array containing all the names of files.
|
||||
* @param searchInput contain the search request.
|
||||
*/
|
||||
public String[] searchByName(String[] filesArray, String searchInput) {
|
||||
List<String> resultList = new ArrayList<>(Arrays.asList(filesArray));
|
||||
|
||||
for(String listItem: filesArray) {
|
||||
if(!listItem.contains(searchInput)){
|
||||
resultList.remove(listItem);
|
||||
}
|
||||
}
|
||||
String[] resultArray = new String[resultList.size()];
|
||||
if(resultList.isEmpty()) {
|
||||
return resultArray;
|
||||
}
|
||||
else {
|
||||
resultArray = resultList.toArray(resultArray);
|
||||
return resultArray;
|
||||
}
|
||||
}
|
||||
|
||||
/** search correspondance of a String in a the end of String in an array.
|
||||
* @param filesArray is the array containing all the names of files.
|
||||
* @param searchInput contain the search request.
|
||||
*/
|
||||
public String[] searchByExtention(String[] filesArray, String searchInput) {
|
||||
List<String> resultList = new ArrayList<>(Arrays.asList(filesArray));
|
||||
|
||||
int i = 0;
|
||||
|
||||
for(String listItem: filesArray) {
|
||||
if(!listItem.endsWith(searchInput)){
|
||||
resultList.remove(listItem);
|
||||
}
|
||||
}
|
||||
String[] resultArray = new String[resultList.size()];
|
||||
if(resultList.isEmpty()) {
|
||||
return resultArray;
|
||||
}
|
||||
else {
|
||||
resultArray = resultList.toArray(resultArray);
|
||||
return resultArray;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue