All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.elephantdrummer.parser.ParserDayOfWeekToCalendarDay Maven / Gradle / Ivy

There is a newer version: 1.2.5
Show newest version
package com.elephantdrummer.parser;

import java.util.Calendar;

import com.elephantdrummer.annotation.DayOfWeek;
import com.elephantdrummer.exception.DictError;
import com.elephantdrummer.exception.DrummerException;

/**
 * Copyright 2018 Elephant Software Klaudiusz Wojtkowiak e-mail: [email protected]
 * 
 * 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. 
 */
public interface ParserDayOfWeekToCalendarDay {

	
	/**
	 * Convert Drummer DayOfWeek to java Calendar Day of Week
	 */
	public static Integer toCalendarDayOfWeek(DayOfWeek from) {
		if (from==null||from.equals(DayOfWeek.ANY)) return null;
		
		switch (from){
		case MONDAY: return Calendar.MONDAY;
		case TUESDAY: return Calendar.TUESDAY;
		case WEDNESDAY: return Calendar.WEDNESDAY;
		case THURSDAY: return Calendar.THURSDAY;
		case FRIDAY: return Calendar.FRIDAY;
		case SATURDAY: return Calendar.SATURDAY;
		case SUNDAY: return Calendar.SUNDAY;
		case ANY:
			break;
		default:
			break;
		}
    	
		return null;
	}
	
	/**
	 * Convert java Calendar Day of Week to Drummer DayOfWeek
	 */
	public static DayOfWeek toDrummerDayOfWeek(Integer from) {
		if (from==null) return null;
		
		switch (from){
		case Calendar.MONDAY: return DayOfWeek.MONDAY;
		case Calendar.TUESDAY: return DayOfWeek.TUESDAY;
		case Calendar.WEDNESDAY: return DayOfWeek.WEDNESDAY;
		case Calendar.THURSDAY: return DayOfWeek.THURSDAY;
		case Calendar.FRIDAY: return DayOfWeek.FRIDAY;
		case Calendar.SATURDAY: return DayOfWeek.SATURDAY;
		case Calendar.SUNDAY: return DayOfWeek.SUNDAY;
		}
		return DayOfWeek.ANY;
	}
	
	
	public static DayOfWeek getNextDayOfWeek(DayOfWeek from) {
		if (from==null||from.equals(DayOfWeek.ANY)) return null;
		
		switch (from){
		case MONDAY: return DayOfWeek.TUESDAY;
		case TUESDAY: return DayOfWeek.WEDNESDAY;
		case WEDNESDAY: return DayOfWeek.THURSDAY;
		case THURSDAY: return DayOfWeek.FRIDAY;
		case FRIDAY: return DayOfWeek.SATURDAY;
		case SATURDAY: return DayOfWeek.SUNDAY;
		case SUNDAY: return DayOfWeek.MONDAY;
		case ANY:
			break;
		default:
			break;
		}
    	
		return null;
	}
	
	public static DayOfWeek toDrummerDayOfWeek(String from) {
		if (from==null) return null;
		
		switch (from.toUpperCase()){
		case "MONDAY": return DayOfWeek.MONDAY;
		case "TUESDAY": return DayOfWeek.TUESDAY;
		case "WEDNESDAY": return DayOfWeek.WEDNESDAY;
		case "THURSDAY": return DayOfWeek.THURSDAY;
		case "FRIDAY": return DayOfWeek.FRIDAY;
		case "SATURDAY": return DayOfWeek.SATURDAY;
		case "SUNDAY": return DayOfWeek.SUNDAY;
		case "ANY": return DayOfWeek.ANY;
		}
		throw new DrummerException(DictError.DRUM_VALIDATION_ERROR,"String: "+from+" can not be converted to Drummer DayOfWeek enum.");
	}
	
	public static DayOfWeek[] toDrummerDayOfWeekArray(String from) {
		if (from==null||from.isEmpty()) return null;
		String[] days=from.split(",");
		DayOfWeek[] rv=new DayOfWeek[days.length];
		for (int i=0;i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy