Java tutorial
/* * Copyright 2013- Yan Bonnel * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package fr.ybonnel.model; import twitter4j.Status; import java.util.Arrays; import java.util.stream.Stream; public class TweetPhoto { private final String user; private final String avatar; private final String photo; private final String text; public TweetPhoto(String user, String avatar, String photo, String text) { System.err.println("New Tweet"); this.user = user; this.avatar = avatar; this.photo = photo; this.text = text; } public static Stream<TweetPhoto> fromStatus(Status status) { String user = status.getUser().getScreenName(); String avatar = status.getUser().getBiggerProfileImageURL(); String text = status.getText(); /*if (status.getMediaEntities().length == 0) { return Stream.of(new TweetPhoto(user, avatar, "http://placehold.it/400x300", text)); }*/ return Arrays.stream(status.getMediaEntities()) .map(media -> new TweetPhoto(user, avatar, media.getMediaURL(), text)); } }