Offload int[] to byte[].
[SquirrelJME.git] / modules / meep-swm / src / main / java / javax / microedition / swm / Task.java
blobb345cc5334a39e57f9f3d71b6c3f54b77c68bca1
1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // SquirrelJME
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
10 package javax.microedition.swm;
12 import cc.squirreljme.runtime.cldc.annotation.Api;
13 import cc.squirreljme.runtime.cldc.debug.Debugging;
14 import java.util.Objects;
16 /**
17 * This describes a task which is currently running on the system. Each task
18 * has a starting point which is a {@link javax.microedition.midlet.MIDlet}.
20 * System tasks cannot be started or stopped.
22 * @since 2016/06/24
24 @Api
25 public final class Task
27 /** The ID of the task. */
28 final int _tid;
30 /** The suite of this task. */
31 final Suite _suite;
33 /** The entry class of the task. */
34 final String _entry;
36 /**
37 * Initializes the task.
39 * @param __tid The task ID, zero is the system task.
40 * @param __s The suite used.
41 * @param __e The entry name of the task.
42 * @throws NullPointerException On null arguments.
43 * @since 2016/06/24
45 Task(int __tid, Suite __s, String __e)
46 throws NullPointerException
48 if (__s == null || __e == null)
49 throw new NullPointerException("NARG");
51 this._tid = __tid;
52 this._suite = __s;
53 this._entry = __e;
56 /**
57 * Checks if this task is the same as another task, tasks are equal if
58 * they share the same name.
60 * @param __o The other object.
61 * @return {@code true} if this is the same task.
62 * @since 2016/06/24
64 @Override
65 public boolean equals(Object __o)
67 if (this == __o)
68 return true;
70 // Must be another task
71 if (!(__o instanceof Task))
72 return false;
74 // Check
75 Task o = (Task)__o;
76 return Objects.equals(this.getSuite(), o.getSuite()) &&
77 Objects.equals(this.getName(), o.getName());
80 /**
81 * Returns the estimated number of bytes that a task is using.
83 * @return The number of bytes the task is estimated to be using.
84 * @since 2016/06/24
86 @Api
87 public int getHeapUse()
89 throw Debugging.todo();
91 // Make sure the amount of memory used does not overflow ever
92 long rv = this._task.metric(SystemTaskMetric.MEMORY_USED);
93 if (rv < 0L)
94 return 0;
95 else if (rv > Integer.MAX_VALUE)
96 return Integer.MAX_VALUE;
97 return (int)rv;
102 * Returns the name of the current task.
104 * @return The name of the task, system tasks always return {@code null}.
105 * @since 2016/06/24
107 @Api
108 public String getName()
110 // System tasks have no name
111 if (this.isSystemTask())
112 return null;
114 return this._entry;
118 * Returns the priority of this task.
120 * @return The task priority.
121 * @since 2016/06/24
123 @Api
124 public TaskPriority getPriority()
126 throw Debugging.todo();
128 long rv = this._task.metric(SystemTaskMetric.PRIORITY);
129 if (rv < 0L)
130 return TaskPriority.MAX;
131 else if (rv > 0L)
132 return TaskPriority.MIN;
133 return TaskPriority.NORM;
138 * Returns the status of this task.
140 * @return The task status.
141 * @since 2016/06/24
143 @Api
144 public TaskStatus getStatus()
146 // If the TID is negative then it failed to start
147 int tid = this._tid;
148 if (tid < 0)
149 return TaskStatus.START_FAILED;
151 return TaskStatus.__of(Debugging.<Integer>todoObject(tid));
155 * Returns the suite that this task belongs to.
157 * @return The owning suite.
158 * @since 2016/06/24
160 @Api
161 public Suite getSuite()
163 // All system tasks are hidden behind the system suite
164 if (this.isSystemTask())
165 return Suite.SYSTEM_SUITE;
167 return this._suite;
171 * Returns the hash code of this task, the hashcode is derived from the
172 * suite and the name.
174 * @return The hash code.
175 * @since 2016/06/24
177 @Override
178 public int hashCode()
180 return Objects.hashCode(this.getSuite()) ^
181 Objects.hashCode(this.getName());
185 * Returns {@code true} if this is a system task.
187 * @return {@code true} if a system task.
188 * @since 2016/06/24
190 @Api
191 public boolean isSystemTask()
193 // System task is always zero
194 return this._tid == 0;