<commit_before>package com.rho.rubyext;

import com.rho.RhoEmptyLogger;
import com.rho.RhoLogger;
import com.xruby.runtime.builtin.RubyArray;
import com.xruby.runtime.builtin.RubyString;
import com.xruby.runtime.builtin.RubyHash;
import com.xruby.runtime.builtin.ObjectFactory;
import com.xruby.runtime.lang.*;

import javax.microedition.pim.*;

//@RubyLevelClass(name="Calendar")
public class RhoCalendar extends RubyBasic {
	private static final RhoLogger LOG = RhoLogger.RHO_STRIP_LOG ? new RhoEmptyLogger() : 
		new RhoLogger("Calendar");

	private EventList m_eventList;

	static final RubyString RUBY_EV_ID  = ObjectFactory.createString("id");
	static final RubyString RUBY_EV_TITLE = ObjectFactory.createString("title");
	static final RubyString RUBY_EV_CANCELED = ObjectFactory.createString("canceled");
	static final RubyString RUBY_EV_ORGINIZER = ObjectFactory.createString("organizer");
	static final RubyString RUBY_EV_ATTENDEES = ObjectFactory.createString("attendees");
	static final RubyString RUBY_EV_START_DATE = ObjectFactory.createString("start_date");
	static final RubyString RUBY_EV_END_DATE = ObjectFactory.createString("end_date");
	static final RubyString RUBY_EV_LAST_MODIFIED = ObjectFactory.createString("last_modified");
	static final RubyString RUBY_EV_LOCATION  = ObjectFactory.createString( "location");
	static final RubyString RUBY_EV_NOTES  = ObjectFactory.createString( "notes");
	static final RubyString RUBY_EV_RECURRENCE  = ObjectFactory.createString( "recurrence");
	static final RubyString RUBY_EV_RECURRENCE_FREQUENCY  = ObjectFactory.createString( "frequency");
	static final RubyString RUBY_EV_RECURRENCE_FREQUENCY_DAILY  = ObjectFactory.createString( "daily");
	static final RubyString RUBY_EV_RECURRENCE_FREQUENCY_WEEKLY  = ObjectFactory.createString( "weekly");
	static final RubyString RUBY_EV_RECURRENCE_FREQUENCY_MONTHLY  = ObjectFactory.createString( "monthly");
	static final RubyString RUBY_EV_RECURRENCE_FREQUENCY_YEARLY  = ObjectFactory.createString( "yearly");
	static final RubyString RUBY_EV_RECURRENCE_INTERVAL  = ObjectFactory.createString( "interval");
	
	public static class EVRecord extends RubyBasic {

		Event m_event;
		public EVRecord(RubyClass arg0) {
			super(arg0);
		}

		public EVRecord(Event event) {
			super(RubyRuntime.PBRecordClass);
			
			m_event = event;
		}
		
	}
	
	public RhoCalendar(RubyClass arg0) 
	{
		super(arg0);
		
		try {
			m_eventList = (EventList) PIM.getInstance().openPIMList(
					PIM.EVENT_LIST, PIM.READ_WRITE);
		} catch (PIMException e) {
			new RubyException(e.getMessage());
		}
	}
    //@RubyAllocMethod
    public static RhoCalendar alloc(RubyValue receiver) {
    	return new RhoCalendar(RubyRuntime.CalendarClass);
    }

	public static RubyValue openCalendar() {
		RhoCalendar pb = alloc(null);
		return pb;
	}
	public static RubyValue closeCalendar(RubyValue arg0) {
		try {
			RhoCalendar pb = (RhoCalendar)arg0;
			pb.m_eventList.close();
			pb.m_eventList = null;
		} catch (PIMException e) {
			new RubyException(e.getMessage());
		}
		
		return RubyConstant.QNIL;
	}

	RubyHash getEVRecord( Event event )
	{
		RubyHash record = ObjectFactory.createHash();
		
		if ( m_eventList.isSupportedField(Event.UID) &&
			 event.countValues(Event.UID) > 0 ){
			String strValue = "{" + event.getString(Event.UID, 0) + "}";
			record.add(RUBY_EV_ID, ObjectFactory.createString(strValue));			
		}
		
		if ( m_eventList.isSupportedField(Event.SUMMARY) && event.countValues(Event.SUMMARY) > 0 )
		{
			String strValue = event.getString(Event.SUMMARY, 0);
			if ( strValue.length() > 0 )
				record.add(RUBY_EV_TITLE, ObjectFactory.createString(strValue));			
		}
		
		return record;
	}
	
	public static RubyValue getallCalendarEvents(RubyValue arg0) {
		RhoCalendar pb = (RhoCalendar)arg0;
		RubyHash res = ObjectFactory.createHash();
		
		try {
			java.util.Enumeration events = pb.m_eventList.items();
			while (events.hasMoreElements()) {
				Event event = (Event) events.nextElement();
				RubyHash record = pb.getEVRecord( event );
				res.add(record.get(RUBY_EV_ID), record);
			}<commit_msg>add start_date\end_date to Calendar Events<commit_after>package com.rho.rubyext;

import com.rho.RhoEmptyLogger;
import com.rho.RhoLogger;
import com.xruby.runtime.builtin.RubyArray;
import com.xruby.runtime.builtin.RubyString;
import com.xruby.runtime.builtin.RubyHash;
import com.xruby.runtime.builtin.ObjectFactory;
import com.xruby.runtime.lang.*;

import javax.microedition.pim.*;

//@RubyLevelClass(name="Calendar")
public class RhoCalendar extends RubyBasic {
	private static final RhoLogger LOG = RhoLogger.RHO_STRIP_LOG ? new RhoEmptyLogger() : 
		new RhoLogger("Calendar");

	private EventList m_eventList;

	static final RubyString RUBY_EV_ID  = ObjectFactory.createString("id");
	static final RubyString RUBY_EV_TITLE = ObjectFactory.createString("title");
	static final RubyString RUBY_EV_CANCELED = ObjectFactory.createString("canceled");
	static final RubyString RUBY_EV_ORGINIZER = ObjectFactory.createString("organizer");
	static final RubyString RUBY_EV_ATTENDEES = ObjectFactory.createString("attendees");
	static final RubyString RUBY_EV_START_DATE = ObjectFactory.createString("start_date");
	static final RubyString RUBY_EV_END_DATE = ObjectFactory.createString("end_date");
	static final RubyString RUBY_EV_LAST_MODIFIED = ObjectFactory.createString("last_modified");
	static final RubyString RUBY_EV_LOCATION  = ObjectFactory.createString( "location");
	static final RubyString RUBY_EV_NOTES  = ObjectFactory.createString( "notes");
	static final RubyString RUBY_EV_REMINDER  = ObjectFactory.createString( "reminder");
	static final RubyString RUBY_EV_PRIVACY  = ObjectFactory.createString( "privacy");	
	static final RubyString RUBY_EV_RECURRENCE  = ObjectFactory.createString( "recurrence");
	static final RubyString RUBY_EV_RECURRENCE_FREQUENCY  = ObjectFactory.createString( "frequency");
	static final RubyString RUBY_EV_RECURRENCE_FREQUENCY_DAILY  = ObjectFactory.createString( "daily");
	static final RubyString RUBY_EV_RECURRENCE_FREQUENCY_WEEKLY  = ObjectFactory.createString( "weekly");
	static final RubyString RUBY_EV_RECURRENCE_FREQUENCY_MONTHLY  = ObjectFactory.createString( "monthly");
	static final RubyString RUBY_EV_RECURRENCE_FREQUENCY_YEARLY  = ObjectFactory.createString( "yearly");
	static final RubyString RUBY_EV_RECURRENCE_INTERVAL  = ObjectFactory.createString( "interval");
	
	public static class EVRecord extends RubyBasic {

		Event m_event;
		public EVRecord(RubyClass arg0) {
			super(arg0);
		}

		public EVRecord(Event event) {
			super(RubyRuntime.PBRecordClass);
			
			m_event = event;
		}
		
	}
	
	public RhoCalendar(RubyClass arg0) 
	{
		super(arg0);
		
		try {
			m_eventList = (EventList) PIM.getInstance().openPIMList(
					PIM.EVENT_LIST, PIM.READ_WRITE);
		} catch (PIMException e) {
			new RubyException(e.getMessage());
		}
	}
    //@RubyAllocMethod
    public static RhoCalendar alloc(RubyValue receiver) {
    	return new RhoCalendar(RubyRuntime.CalendarClass);
    }

	public static RubyValue openCalendar() {
		RhoCalendar pb = alloc(null);
		return pb;
	}
	public static RubyValue closeCalendar(RubyValue arg0) {
		try {
			RhoCalendar pb = (RhoCalendar)arg0;
			pb.m_eventList.close();
			pb.m_eventList = null;
		} catch (PIMException e) {
			new RubyException(e.getMessage());
		}
		
		return RubyConstant.QNIL;
	}

	RubyHash getEVRecord( Event event )
	{
		RubyHash record = ObjectFactory.createHash();
		int[] arFields = event.getFields();
		for ( int i = 0; i < arFields.length; i++)
		{
			switch(arFields[i])
			{
			case Event.UID:
				record.add(RUBY_EV_ID, ObjectFactory.createString(
						"{" + event.getString(Event.UID, 0) + "}" ));
				break;
			
			case Event.SUMMARY:
				record.add(RUBY_EV_TITLE, ObjectFactory.createString(event.getString(Event.SUMMARY, 0)));
				break;
			
			case Event.NOTE:
				record.add(RUBY_EV_NOTES, ObjectFactory.createString(event.getString(Event.NOTE, 0)));
				break;
				
			case Event.ALARM:
				record.add(RUBY_EV_REMINDER, ObjectFactory.createInteger(event.getInt(Event.ALARM, 0)));
				break;

			case Event.CLASS:
			{
				int nClass = event.getInt(Event.CLASS, 0);
				String strValue = "public";
				if ( nClass == Event.CLASS_CONFIDENTIAL )
					strValue = "confidential";
				else if ( nClass == Event.CLASS_PRIVATE )
					strValue = "private";
				
				record.add(RUBY_EV_PRIVACY, ObjectFactory.createString(strValue));
				break;
			}
		
			case Event.END:
				record.add(RUBY_EV_END_DATE, ObjectFactory.createTime(event.getDate(Event.END, 0)));	
				break;
			case Event.START:
				record.add(RUBY_EV_START_DATE, ObjectFactory.createTime(event.getDate(Event.START, 0)));	
				break;
			case Event.REVISION:
				record.add(RUBY_EV_LAST_MODIFIED, ObjectFactory.createTime(event.getDate(Event.REVISION, 0)));
				break;
				
			case Event.LOCATION:
				record.add(RUBY_EV_LOCATION, ObjectFactory.createString(event.getString(Event.LOCATION, 0)));
				break;

			}
		}
		
		return record;
	}
	
	public static RubyValue getallCalendarEvents(RubyValue arg0) {
		RhoCalendar pb = (RhoCalendar)arg0;
		RubyHash res = ObjectFactory.createHash();
		
		try {
			java.util.Enumeration events = pb.m_eventList.items();
			while (events.hasMoreElements()) {
				Event event = (Event) events.nextElement();
				RubyHash record = pb.getEVRecord( event );
				res.add(record.get(RUBY_EV_ID), record);
			}
{'fraction_non_alphanumeric': 0.10368247904064523, 'fraction_numerical': 0.0032898227740634617, 'mean_word_length': 4.912170639899624, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5827773', 'n_tokens_mistral': 3594, 'n_tokens_neox': 3085, 'n_words': 596}