de.msg.repository.RouteRepositoryImpl.java Source code

Java tutorial

Introduction

Here is the source code for de.msg.repository.RouteRepositoryImpl.java

Source

/*
 * Copyright (C) 2016 msg-systems ag
 *
 * 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.
 *
 *
 * @author Rafael Kansy
 * @author Michael Schaefer
 */

package de.msg.repository;

import de.msg.domain.route.Route;
import de.msg.repository.driver.RouteRepositoryDriver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

@Repository
public class RouteRepositoryImpl implements RouteRepository {

    @Autowired
    private RouteRepositoryDriver driver;

    @Override
    public Iterable<Route> findByDeparture(String departure) {
        return StreamSupport.stream(driver.getRouteList().spliterator(), false).filter(new Predicate<Route>() {
            @Override
            public boolean test(Route route) {
                return route.getDeparture().equals(departure);
            }
        }).collect(Collectors.toList());
    }

    @Override
    public Iterable<Route> findAll() {
        return driver.getRouteList();
    }
}