-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
521 additions
and
160 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/core/evaluables/method/nativemethods/NativeMethodOsNow.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package core.evaluables.method.nativemethods; | ||
|
||
import core.Evaluable; | ||
import core.ObjectBag; | ||
import core.Runtime; | ||
import core.evaluables.method.NativeMethod; | ||
import core.exceps.InterpretError; | ||
import core.objs.ObjectDateTime; | ||
|
||
import java.util.Calendar; | ||
|
||
/** | ||
* A method that extracts the time and stores it in a DateTime object. | ||
* Created by Baltasar on 30/01/2016. | ||
*/ | ||
public class NativeMethodOsNow extends NativeMethod { | ||
public static final String EtqMthOsNow = "now"; | ||
|
||
public NativeMethodOsNow() { | ||
super( EtqMthOsNow ); | ||
} | ||
|
||
@Override | ||
public ObjectBag doIt(ObjectBag ref, Evaluable[] params, StringBuilder msg) | ||
throws InterpretError | ||
{ | ||
final Calendar now = Calendar.getInstance(); | ||
final Runtime rt = Runtime.getRuntime(); | ||
|
||
chkParametersNumber( 0, params ); | ||
|
||
// Create date-time object | ||
final ObjectDateTime toret = rt.createDateTime( | ||
now.get( Calendar.DAY_OF_MONTH ), | ||
now.get( Calendar.MONTH ) + 1, | ||
now.get( Calendar.YEAR ), | ||
now.get( Calendar.HOUR ), | ||
now.get( Calendar.MINUTE ), | ||
now.get( Calendar.SECOND ) | ||
); | ||
|
||
msg.append( "Obtained current date and time" ); | ||
return toret; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package core.objs; | ||
|
||
import core.ObjectBag; | ||
import core.evaluables.method.InterpretedMethod; | ||
import core.exceps.InterpretError; | ||
|
||
/** | ||
* Represents a time instant (date and time) | ||
* Created by Baltasar on 29/01/2016. | ||
*/ | ||
public class ObjectDateTime extends ValueObject { | ||
public static final String EtqSecond = "second"; | ||
public static final String EtqMinute = "minute"; | ||
public static final String EtqHour = "hour"; | ||
public static final String EtqYear = "year"; | ||
public static final String EtqMonth = "month"; | ||
public static final String EtqDay = "day"; | ||
public static final String EtqDateAsStr = "dateAsStr"; | ||
public static final String EtqTimeAsStr = "timeAsStr"; | ||
public static final String EtqStr = "str"; | ||
|
||
public ObjectDateTime(String n, ObjectBag parent, ObjectBag container) throws InterpretError { | ||
super( n, parent, container ); | ||
|
||
this.set( EtqDateAsStr, new InterpretedMethod( EtqDateAsStr, | ||
"( ( ( ( self." + EtqDay + " str ) + \"-\" ) + ( self." | ||
+ EtqMonth + " str ) ) + \"-\" ) + ( self." | ||
+ EtqYear + " str )" ) ); | ||
|
||
this.set( EtqTimeAsStr, new InterpretedMethod( EtqTimeAsStr, | ||
"( ( ( ( self." + EtqHour + " str ) + \":\" ) + ( self." | ||
+ EtqMinute + " str ) ) + \":\" ) + ( self." | ||
+ EtqSecond + " str )" ) ); | ||
|
||
this.set( EtqStr, new InterpretedMethod( EtqStr, | ||
"( ( self dateAsStr ) + \" \" ) + ( self timeAsStr )" ) ); | ||
} | ||
|
||
@Override | ||
public Object getValueObject() { | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package core.objs; | ||
|
||
import core.evaluables.method.InterpretedMethod; | ||
import core.evaluables.method.nativemethods.NativeMethodOsNow; | ||
import core.exceps.InterpretError; | ||
|
||
/** | ||
* The OS (Operating System) object which will provide services from the underlying | ||
* system software layer. | ||
* Created by Baltasar on 29/01/2016. | ||
*/ | ||
public class ObjectOs extends SysObject { | ||
public static final String Name = "os"; | ||
|
||
/** | ||
* Creates the object representing the system | ||
* When an empty name is passed, an automatic name is created. | ||
* | ||
* @param absParent The parent object in which to register it. | ||
* @param container The object this is contained into. | ||
*/ | ||
public ObjectOs(ObjectParent absParent, SysObject container) throws InterpretError { | ||
super( Name, absParent, container ); | ||
|
||
this.set( NativeMethodOsNow.EtqMthOsNow, new NativeMethodOsNow() ); | ||
} | ||
} |