vendredi 15 octobre 2021

how to write complex if condition with File array in the lamba expression of stream API Android Java [closed]

I have the following code

private ArrayList<String> findPhotos(Date startTimestamp, Date endTimestamp, String keywords, String longitude, String latitude) {
     
     ArrayList<String> photos = new ArrayList<String>();
     File[] fList = file.listFiles();
        if (fList != null) {
            for (File f : fList) {
                if (((startTimestamp == null && endTimestamp == null) || (f.lastModified() >= startTimestamp.getTime()
                        && f.lastModified() <= endTimestamp.getTime())
                ) && (keywords == "" || f.getPath().contains(keywords))
                        && (longitude == "" || f.getPath().contains(longitude))
                        && (latitude == "" || f.getPath().contains(latitude)))
                    photos.add(f.getPath());
            }
        }
return photos
}

This function take five param. 1.Startime time 2.endtime 3.keywork 4.longitude 5.latitude and filter them out to get the only desired results. I want to transfer this file array into lamba array and then perform following code

Filter(startTimestamp == null && endTimestamp == null) \n
or 
Filter(f -> f.lastModified() >= startTimestamp.getTime())
and
FIlter(f -> f.getPath().contains(keywords) or (keywords == ""))
and
FIlter(keywords == "" || f -> f.getPath().contains(keywords))
and
FIlter(latitude== "" || f -> f.getPath().contains(latitude))

FIlter(keywords == "" || f -> f.getPath().contains(keywords))

and then get only paths 
then .collect(Collectors.toList());

Once I filter them out the File array and then add only file paths into arraylist can anyone help me to turn this one into lamba expression?

Aucun commentaire:

Enregistrer un commentaire