001/*
002 * ModeShape (http://www.modeshape.org)
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *       http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.modeshape.web.server.impl;
017
018import java.io.Serializable;
019import org.modeshape.jcr.api.monitor.Window;
020
021/**
022 * Local time units 
023 * 
024 * @author kulikov
025 */
026public class TimeUnit implements Serializable {
027    private static final TimeUnit UNITS[] = {
028        new TimeUnit(Window.PREVIOUS_60_SECONDS, "Previous 60 seconds"),
029        new TimeUnit(Window.PREVIOUS_60_MINUTES, "Previous 60 minutes"),
030        new TimeUnit(Window.PREVIOUS_24_HOURS, "Previous 24 hours"),
031        new TimeUnit(Window.PREVIOUS_7_DAYS, "Previous 7 days"),
032        new TimeUnit(Window.PREVIOUS_52_WEEKS, "Previous 52 weeks"),
033    }; 
034    
035    private Window window;
036    private String title;
037    
038    public TimeUnit() {
039    }
040    
041    public TimeUnit(Window window, String title) {
042        this.window = window;
043        this.title = title;
044    }
045    
046    public Window window() {
047        return window;
048    }
049    
050    public String title() {
051        return title;
052    }
053    
054    public static String[] names() {
055        String[] names = new String[UNITS.length];
056        for (int i = 0; i < names.length; i++) {
057            names[i] = UNITS[i].title();
058        }
059        return names;
060    }
061    
062    public static TimeUnit find( String name ) {
063        for (int i = 0; i < UNITS.length; i++) {
064            if (UNITS[i].title().equals(name)) {
065                return UNITS[i];
066            }
067        }
068        return null;
069    }
070    
071}