001/*
002 * (C) Copyright 2010-2015 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl-2.1.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Nuxeo - initial API and implementation
016 */
017
018package org.nuxeo.connect.client.we;
019
020import java.util.ArrayList;
021import java.util.List;
022
023import org.nuxeo.connect.data.DownloadablePackage;
024
025public class StudioSnapshotHelper {
026
027    public static final String SNAPSHOT_SUFFIX = "0.0.0-SNAPSHOT";
028
029    private StudioSnapshotHelper() {
030    }
031
032    public static boolean isSnapshot(DownloadablePackage pkg) {
033        return pkg.getVersion() != null && pkg.getVersion().toString().endsWith(SNAPSHOT_SUFFIX);
034    }
035
036    public static List<DownloadablePackage> removeSnapshot(List<DownloadablePackage> pkgs) {
037        List<DownloadablePackage> result = new ArrayList<>();
038        for (DownloadablePackage pkg : pkgs) {
039            if (!isSnapshot(pkg)) {
040                result.add(pkg);
041            }
042        }
043        return result;
044    }
045
046    public static DownloadablePackage getSnapshot(List<DownloadablePackage> pkgs) {
047        for (DownloadablePackage pkg : pkgs) {
048            if (isSnapshot(pkg)) {
049                return pkg;
050            }
051        }
052        return null;
053    }
054
055}