Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /* ************************************************************************
  #
  #  DivConq
  #
  #  http://divconq.com/
  #
  #  Copyright:
  #    Copyright 2014 eTimeline, LLC. All rights reserved.
  #
 #  License:
 #    See the license.txt file in the project's top-level directory for details.
 #
 #  Authors:
 #    * Andy White
 #
 ************************************************************************ */
 package divconq.test;
 
 
 
 public class Schema1 {
 	/* 0 = Sunday */
 	static public int dayOfWeek(int yint mint d) {
 		int[] t = { 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 };
 		
 		y -= (m < 3) ? 1 : 0;
 		
 		return (y + y/4 - y/100 + y/400 + t[m-1] + d) % 7;
 	}
 	
 	public static void main(String[] args) {
 		try {
 			DateTime zyear3 = new DateTime(2012, 3, 15, 0, 0, 0, .);
 			
 			..println("1: " + zyear3.plusMonths(1));
 			..println("5: " + zyear3.plusMonths(5));
 			..println("8: " + zyear3.plusMonths(8));
 			..println("9: " + zyear3.plusMonths(9));
 			..println("10: " + zyear3.plusMonths(10));
 			..println("11: " + zyear3.plusMonths(11));
 			..println("12: " + zyear3.plusMonths(12));
 			..println("13: " + zyear3.plusMonths(13));
 			..println("20: " + zyear3.plusMonths(20));
 			..println("21: " + zyear3.plusMonths(21));
 			..println("22: " + zyear3.plusMonths(22));
 			..println("23: " + zyear3.plusMonths(23));
 			..println("24: " + zyear3.plusMonths(24));
 			..println("30: " + zyear3.plusMonths(30));
 			..println("31: " + zyear3.plusMonths(31));
 			..println("32: " + zyear3.plusMonths(32));
 			..println("33: " + zyear3.plusMonths(33));
 			..println("34: " + zyear3.plusMonths(34));
 			..println("40: " + zyear3.plusMonths(40));
 			..println("41: " + zyear3.plusMonths(41));
 			..println("42: " + zyear3.plusMonths(42));
 			..println("43: " + zyear3.plusMonths(43));
 			..println("200: " + zyear3.plusMonths(200));
 			..println("500: " + zyear3.plusMonths(500));
 			..println("1000: " + zyear3.plusMonths(1000));
 			..println("2000: " + zyear3.plusMonths(2000));
 			..println("5000: " + zyear3.plusMonths(5000));
 			..println("7000: " + zyear3.plusMonths(7000));
 			
 			/*
 			System.out.println("1: " + Schema1.dayOfWeek(0, 1, 1));
 			System.out.println("1: " + Schema1.dayOfWeek(1, 1, 1));
 			System.out.println("2: " + Schema1.dayOfWeek(500, 1, 1));
 			System.out.println("3: " + Schema1.dayOfWeek(900, 1, 1));
 			System.out.println("4: " + Schema1.dayOfWeek(1800, 1, 1));
 			System.out.println("5: " + Schema1.dayOfWeek(1900, 1, 1));
 			System.out.println("6: " + Schema1.dayOfWeek(2000, 1, 1));
 			
 			
 			DateTime zyeara = new DateTime(0, 1, 1, 0, 0, 0, DateTimeZone.UTC);
 			DateTime zyeara1 = new DateTime(1, 1, 1, 0, 0, 0, DateTimeZone.UTC);
 			DateTime zyearb = new DateTime(500, 1, 1, 0, 0, 0, DateTimeZone.UTC);
 			DateTime zyearc = new DateTime(900, 1, 1, 0, 0, 0, DateTimeZone.UTC);
 			DateTime zyear1 = new DateTime(1800, 1, 1, 0, 0, 0, DateTimeZone.UTC);
 			DateTime zyear2 = new DateTime(1900, 1, 1, 0, 0, 0, DateTimeZone.UTC);
 			DateTime zyear3 = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeZone.UTC);
 			
 			System.out.println("1: " + zyeara.getDayOfWeek());
 			System.out.println("1: " + zyeara1.getDayOfWeek());
 			System.out.println("2: " + zyearb.getDayOfWeek());
 			System.out.println("3: " + zyearc.getDayOfWeek());
 			System.out.println("4: " + zyear1.getDayOfWeek());
 			System.out.println("5: " + zyear2.getDayOfWeek());
			System.out.println("6: " + zyear3.getDayOfWeek());
			*/
			/*
			 DateTimeZone America_Los_Angeles = new DateTimeZoneBuilder()
			     .addCutover(-2147483648, 'w', 1, 1, 0, false, 0)
			     .setStandardOffset(-28378000)
			     .setFixedSavings("LMT", 0)
			     .addCutover(1883, 'w', 11, 18, 0, false, 43200000)
			     .setStandardOffset(-28800000)
			     .addRecurringSavings("PDT", 3600000, 1918, 1919, 'w',  3, -1, 7, false, 7200000)
			     .addRecurringSavings("PST",       0, 1918, 1919, 'w', 10, -1, 7, false, 7200000)
			     .addRecurringSavings("PWT", 3600000, 1942, 1942, 'w',  2,  9, 0, false, 7200000)
			     .addRecurringSavings("PPT", 3600000, 1945, 1945, 'u',  8, 14, 0, false, 82800000)
			     .addRecurringSavings("PST",       0, 1945, 1945, 'w',  9, 30, 0, false, 7200000)
			     .addRecurringSavings("PDT", 3600000, 1948, 1948, 'w',  3, 14, 0, false, 7200000)
			     .addRecurringSavings("PST",       0, 1949, 1949, 'w',  1,  1, 0, false, 7200000)
			     .addRecurringSavings("PDT", 3600000, 1950, 1966, 'w',  4, -1, 7, false, 7200000)
			     .addRecurringSavings("PST",       0, 1950, 1961, 'w',  9, -1, 7, false, 7200000)
			     .addRecurringSavings("PST",       0, 1962, 1966, 'w', 10, -1, 7, false, 7200000)
			     .addRecurringSavings("PST",       0, 1967, 2147483647, 'w', 10, -1, 7, false, 7200000)
			     .addRecurringSavings("PDT", 3600000, 1967, 1973, 'w', 4, -1,  7, false, 7200000)
			     .addRecurringSavings("PDT", 3600000, 1974, 1974, 'w', 1,  6,  0, false, 7200000)
			     .addRecurringSavings("PDT", 3600000, 1975, 1975, 'w', 2, 23,  0, false, 7200000)
			     .addRecurringSavings("PDT", 3600000, 1976, 1986, 'w', 4, -1,  7, false, 7200000)
			     .addRecurringSavings("PDT", 3600000, 1987, 2147483647, 'w', 4, 1, 7, true, 7200000)
			     .toDateTimeZone("America/Los_Angeles", true);			
			int year = 2012;
			//for (String id : DateTimeZone.getAvailableIDs()) {
				DateTimeZone z = DateTimeZone.forID("America/New_York");
				DateTime zyear = new DateTime(year, 1, 1, 0, 0, 0, z);
				System.out.println("Zone: " + z.getID());
				System.out.println("   " + zyear);
				//while (zyear.getYear() == year) {
					long lz = z.nextTransition(zyear.getMillis());				
					zyear = new DateTime(lz, z);
					System.out.println("   " + zyear);
				//}
			//}
			*/
			System.exit(0);
			HubResources resources = new HubResources();
			OperationResult or = resources.init();
			if (or.hasErrors()) {
				Logger.error("Unable to continue, hub resources not properly initialized");
				return;
			}
			..start(resources);
			{
				..println("Implicit Example");
				RecordStruct ex1 = new RecordStruct();
				ex1.setField("Code", 5);
				ex1.setField("Message""Problem with coolant system.");
				..println("Code: " + ex1.getFieldAsString("Code"));
				long code = ex1.getFieldAsInteger("Code");
				..println("Code Is Priority Level: " + (code < 3));
			}
			..println("----------------");
			{
				..println("Explicit Example");
				RecordStruct ex1 = new RecordStruct();
				ex1.setField("Code"new IntegerStruct(5));
				ex1.setField("Message"new StringStruct("Problem with coolant system."));
				..println("Code: " + ex1.getFieldAsString("Code"));
				long code = ex1.getFieldAsInteger("Code");
				..println("Code Is Priority Level: " + (code < 3));
			}
			..println("----------------");
			{
				..println("Alternative Type Example");
				RecordStruct ex1 = new RecordStruct();
				ex1.setField("Code""5");
				ex1.setField("Message""Problem with coolant system.");
				..println("Code: " + ex1.getFieldAsString("Code"));
				long code = ex1.getFieldAsInteger("Code");
				..println("Code Is Priority Level: " + (code < 3));
			}
			..println("----------------");
			{
				..println("List Example");
				ListStruct ex2 = new ListStruct();
				ex2.addItem(0);
				ex2.addItem(20);
				ex2.addItem(50);
				ex2.addItem(90);
				ex2.addItem(140);
				for (int i = 0; i < ex2.getSize(); i++) {
					long code = ex2.getItemAsInteger(i);
					..println("Code " + code + " is priority level: " + (code < 73));
				}
			}
			..println("----------------");
			{
				..println("Record List Example");
				ListStruct ex3 = new ListStruct();
				RecordStruct m1 = new RecordStruct();
				m1.setField("Code", 5);
				m1.setField("Message""Problem with coolant system.");
				ex3.addItem(m1);
				RecordStruct m2 = new RecordStruct();
				m2.setField("Code", 53);
				m2.setField("Message""Fan blade nicked.");
				ex3.addItem(m2);
				for (int i = 0; i < ex3.getSize(); i++) {
					..println("Message #" + i);
					..println("   Code: " + msg.getFieldAsString("Code"));
					..println("   Text: " + msg.getFieldAsString("Message"));
				}
			}
			..println("----------------");
			{
				..println("Record List Example 2");
				ListStruct ex3 = new ListStruct(
								new FieldStruct("Code", 5),
								new FieldStruct("Message""Problem with coolant system.")
						),
								new FieldStruct("Code", 53),
								new FieldStruct("Message""Fan blade nicked.")
						)
				);
				for (int i = 0; i < ex3.getSize(); i++) {
					..println("Message #" + i);
					..println("   Code: " + msg.getFieldAsString("Code"));
					..println("   Text: " + msg.getFieldAsString("Message"));
				}
			}
			..println("----------------");
			{
				..println("Schema Example 1-A");
				RecordStruct ex1 = new RecordStruct();
				ex1.setField("Code", 5);
				ex1.setField("Message""Problem with coolant system.");
				..println(ex1.validate("Schema1Ex1").toString());
			}
			..println("----------------");
			{
				..println("Schema Example 1-B");
				RecordStruct ex1 = new RecordStruct();
				ex1.setField("Code""5");
				ex1.setField("Message""Problem with coolant system.");
				..println(ex1.validate("Schema1Ex1").toString());
			}
			..println("----------------");
			{
				..println("Schema Example 1-C");
				RecordStruct ex1 = new RecordStruct();
				ex1.setField("Code""abc");
				ex1.setField("Message""Problem with coolant system.");
				..println(ex1.validate("Schema1Ex1").toString());
			}
			..println("----------------");
			{
				..println("Schema Example 2-A");
				RecordStruct ex1 = new RecordStruct();
				ex1.setField("Message""Problem with coolant system.");
				..println(ex1.validate("Schema1Ex1").toString());
			}
			..println("----------------");
			{
				..println("Schema Example 2-B");
				RecordStruct ex1 = new RecordStruct();
				ex1.setField("Message""Problem with coolant system.");
				..println(ex1.validate("Schema1Ex2").toString());
			}
			..println("----------------");
			{
				..println("Schema Example 2-C");
				RecordStruct ex1 = new RecordStruct();
				ex1.setField("Code", 5);
				ex1.setField("Message""Problem with coolant system.");
				..println(ex1.validate("Schema1Ex2").toString());
			}
			..println("----------------");
			{
				..println("Schema Example 3A");
				ListStruct ex3 = new ListStruct(
								new FieldStruct("Code", 5),
								new FieldStruct("Message""Problem with coolant system.")
						),
								new FieldStruct("Message""Fan belt cracked.")
						),
								new FieldStruct("Code", 53),
								new FieldStruct("Message""Fan blade nicked.")
						),
								new FieldStruct("Code""abc"),
								new FieldStruct("Message""Fan bearing worn.")
						)
				);
				..println(ex3.validate("Schema1Ex3").toString());
			}
			..println("----------------");
			{
				..println("Schema Example 3B");
				ListStruct ex3 = new ListStruct(
								new FieldStruct("Code", 5),
								new FieldStruct("Message""Problem with coolant system.")
						),
								new FieldStruct("Code", 52),
								new FieldStruct("Message""Fan belt cracked.")
						),
								new FieldStruct("Code", 53),
								new FieldStruct("Message""Fan blade nicked.")
						),
								new FieldStruct("Code", 54),
								new FieldStruct("Message""Fan bearing worn.")
						)
				);
				..println(ex3.validate("Schema1Ex3").toString());
			}
			..println("----------------");
			{
				..println("Schema Example 7A");
				RecordStruct ex1 = new RecordStruct();
				ex1.setField("Code", 5);
				ex1.setField("Message""Problem with coolant system.");
				..println(ex1.validate("Schema1Ex7").toString());
			}
			..println("----------------");
			{
				..println("Schema Example 7B");
				RecordStruct ex1 = new RecordStruct();
				ex1.setField("Code", 200);
				ex1.setField("Message""Problem with coolant system.");
				..println(ex1.validate("Schema1Ex7").toString());
			}
			..println("----------------");
			{
				..println("Schema Example 7C");
				RecordStruct ex1 = new RecordStruct();
				ex1.setField("Code", 201);
				ex1.setField("Message""Problem with coolant system.");
				..println(ex1.validate("Schema1Ex7").toString());
			}
			//System.out.println("----------------");
			//System.out.println(ex1.validate("Schema1Ex1").toString());
			/*
			// typed ResultMessage record
			RecordStruct msg1 = dcschema.newRecord("ResultMessage");
			System.out.println("----------------");
			System.out.println(msg1.validate().toString());
			msg1.setField("Level", "Info");
			msg1.setField("Code", 3);
			msg1.setField("Message", "Howday partner!");
			System.out.println("----------------");
			System.out.println(msg1.toString());
			System.out.println("----------------");
			System.out.println(msg1.validate().toString());
			//rec.setField("Level", "What!!");
			//rec.removeField("Code");
			//System.out.println("----------------");
			//System.out.println(rec.validate().toString());
			System.out.println("-------------------------------------------------------");
			// typed ResponseMessage record
			RecordStruct resp = dcschema.newRecord("ResponseMessage");
			System.out.println(resp.validate().toString());
			resp.setField("Service", "Reply");
			resp.setField("Result", 6);
			System.out.println("----------------");
			System.out.println(resp.toString());
			System.out.println("----------------");
			System.out.println(resp.validate().toString());
			System.out.println("-------------------------------------------------------");
			FuncResult<Struct> msgs = resp.getOrAllocateField("Messages"); 
			((ListStruct) msgs.getResult()).addItem(msg1);
			System.out.println("----------------");
			System.out.println(resp.toString());
			System.out.println("----------------");
			System.out.println(resp.validate().toString());
			System.out.println("-------------------------------------------------------");
			// untyped record attempting to merge with typed
			RecordStruct msg2 = new RecordStruct();
			msg2.setField("Level", "Exit");
			msg2.setField("Code", 5);
			msg2.setField("Message", "Goodday partner!");
			((ListStruct) msgs.getResult()).addItem(msg2);
			System.out.println("----------------");
			System.out.println(resp.toString());
			System.out.println("----------------");
			System.out.println(resp.validate().toString());
			System.out.println("-------------------------------------------------------");
			*/
		catch (Exception x) {
			..println("Error in test: " + x);
		}
	}
New to GrepCode? Check out our FAQ X