001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.scheduler;
016    
017    /**
018     * @author Brian Wing Shun Chan
019     */
020    public enum TimeUnit {
021    
022            DAY("day"), HOUR("hour"), MINUTE("minute"), SECOND("second"), WEEK("week");
023    
024            public static TimeUnit parse(String value) {
025                    if (DAY.getValue().equals(value)) {
026                            return DAY;
027                    }
028                    else if (HOUR.getValue().equals(value)) {
029                            return HOUR;
030                    }
031                    else if (MINUTE.getValue().equals(value)) {
032                            return MINUTE;
033                    }
034                    else if (SECOND.getValue().equals(value)) {
035                            return SECOND;
036                    }
037                    else if (WEEK.getValue().equals(value)) {
038                            return WEEK;
039                    }
040    
041                    throw new IllegalArgumentException("Invalid value " + value);
042            }
043    
044            public String getValue() {
045                    return _value;
046            }
047    
048            @Override
049            public String toString() {
050                    return _value;
051            }
052    
053            private TimeUnit(String value) {
054                    _value = value;
055            }
056    
057            private String _value;
058    
059    }