Created
February 7, 2018 10:31
-
-
Save jelinski/764da776a4ee20188ca38e2f9b223e11 to your computer and use it in GitHub Desktop.
Iterable from regex processing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private <T> Iterable<List<T>> iteratePoints(String dataPointsString, final Transformer<String, T> parser) { | |
final Matcher matcherPoints = PATTERN_POINTS.matcher(dataPointsString); | |
return new Iterable<List<T>>() { | |
@Override | |
public Iterator<List<T>> iterator() { | |
return new Iterator<List<T>>() { | |
@Override | |
public boolean hasNext() { | |
return matcherPoints.find(); | |
} | |
@Override | |
public List<T> next() { | |
String point = matcherPoints.group(); | |
List<T> results = new ArrayList<>(); | |
Matcher matcherPoint = PATTERN_POINT.matcher(point); | |
while (matcherPoint.find()) { | |
String pointValue = matcherPoint.group(); | |
T transformedValue = parser.transform(pointValue); | |
results.add(transformedValue); | |
} | |
return results; | |
} | |
@Override | |
public void remove() { | |
throw new UnsupportedOperationException("remove"); | |
} | |
}; | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment