473,503 Members | 3,045 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Constrained ada type in Java

Have the following type that applies contraints. How could this be easily
coded in Java

type ET_ACTIVE_PORT_CONFIGURATION is
( HDX_TX1_RX1,
HDX_TX2_RX2,
HDX_TX1_RX2,
HDX_TX2_RX1,
FDX_TX1_RX2,
FDX_TX2_RX1);

for ET_ACTIVE_PORT_CONFIGURATION use
( HDX_TX1_RX1 => 62,
HDX_TX2_RX2 => 23,
HDX_TX1_RX2 => 34,
HDX_TX2_RX1 => 45,
FDX_TX1_RX2 => 54,
FDX_TX2_RX1 => 61);
Jul 17 '05 #1
1 1876
Ed Trubia wrote:
Have the following type that applies contraints. How could this be easily
coded in Java


There isn't really an elegant way of handling such things in Java as
you can in Ada.

For type constraining, you'll probably want to create a class which
manages these constraints. Thus, if you want an integer type that can
only hold the ranges -45..150 (say, for storing temperature data),
create a class to hold it and ensure that the value it holds doesn't
exceed on underceed that range. For example:

public class TemperatureData {
private int temp = 0;

public TemperatureData(int t) throws OutOfBoundsException {
setTemp(t);
}

public setTemp(int t) throws OutOfBoundsException {
if (t<-45 || t>150) throw new OutOfBoundsException;
else temp=t;
}

public getTemp() {
return temp;
}
}

(Note that you'd have to also define OutOfBoundsException, as it
doesn't already exist).

To handle method-level constraints, you'll have to test each variable
you want to constrain at the beginning of the method call, and then
throw an exception if it's out-of-bounds. The setTemp() method above
does just this.

As I said, there isn't any nice way to do this like there is in Ada. I
was never completely sold on Ada, but this is one of the things I miss
(along with being able to call functions with your parameters in
whatever order you want to provide them in).

Brad BARCLAY

--
=-=-=-=-=-=-=-=-=
From the OS/2 WARP v4.5 Desktop of Brad BARCLAY.
The jSyncManager Project: http://www.jsyncmanager.org
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
2306
by: Terje Slettebø | last post by:
Hi. I'm new here, and sorry if this has been discussed before; I didn't find it searching the PHP groups. (I've also read recommendations to cross-post to the other PHP groups, but if that is...
8
16580
by: deegs_ca | last post by:
So I had my jdbc db28.2 fix pack 9 client running because I had taken the jars from <DB2ROOT>/java folder from Enterprise Edition 8.2 fix pack 9, db2java.zip, db2jcc.zip, and the license jar. ...
7
1248
by: Leicester B. Ford Jr. | last post by:
I have this class: public class ItemType .... public class ProductType<T> where T: ItemType .... Now I want to add an IDisposable interface to ProductType...
19
1751
by: Fernando Cacciola | last post by:
I'm puzzled, Why and how _exactly_ is this: void Foo<T>(T v ) where T : Interface/Value/Class/class any better than this void Foo( Interface/Value/Class/object v )
4
1419
oll3i
by: oll3i | last post by:
cd u give me the example of constrained type parameters
3
22824
by: Anoop | last post by:
Is it true that there are no type 4 jdbc drivers to connect to a DB2 server v7.1? The DB2 server is hosted on ACF2 (OS/390). We would be connecting from windows and solaris boxes. If it is true,...
1
9675
by: Carmine [www.thetotalsite.it] | last post by:
Hi, I am using ASP.Net 2.0 with the MySQL Connector .Net 5.1.2.2. I added these lines to the web.config to make the connector.net able to handle the SqlConnection object (and so to bind it to a...
6
4239
by: Explore_Imagination | last post by:
The task is to solve a constrained optimization problem in C/C++. Computational Time is of high priority. One approach can be to use ready functions in a "free ware" Optimization Library (if...
2
2614
by: Explore_Imagination | last post by:
The task is to solve a constrained optimization problem in C. Computational Time is of high priority. One approach can be to use ready functions in a "free ware" Optimization Library (if...
0
7067
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6975
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5562
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4992
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.