Can this class run fast than Hotspot ?
My case in Sun hotspot is almost 2 times fast than jRockit. It's very strange.
package com.telegram;
public class byteutils {
public final static byte[] bytea = { 48, 49, 50, 51, 52, 53, 54, 56, 57,
58, 65, 66, 67, 68, 69, 70 };
public byteutils() {
super();
* convert length = 2L letters Hexadecimal String to length = L bytes
* Examples: [01][23][45][67][89][AB][CD][EF]
public static byte[] convertBytes(String hexStr) {
byte[] a = null;
try {
a = hexStr.getBytes("ASCII");
} catch (java.io.UnsupportedEncodingException e) {
e.printStackTrace();
final int len = a.length / 2;
byte[] b = new byte[len];
int idx = 0;
int h = 0;
int l = 0;
for (int i = 0; i < len; i++) {
h = a[idx++];
l = a[idx++];
h = (h < 65) ? (h - 48) : (h - 55);
l = (l < 65) ? (l - 48) : (l - 55);
// if ((h < 0) || (l < 0)) return null;
b[i] = (byte) ((h << 4) | l);
a = null;
return b;
public static String convertHex(byte[] arr_b) {
if (arr_b == null)
return null;
final int len = arr_b.length;
byte[] byteArray = new byte[len * 2];
int idx = 0;
int h = 0;
int l = 0;
int v = 0;
for (int i = 0; i < len; i++) {
v = arr_b[i] & 0xff;
l = v & 0xf;
h = v >> 4;
byteArray[idx++] = bytea[h];
byteArray[idx++] = bytea[l];
String r = null;
try {
r = new String(byteArray, "ASCII");
} catch (java.io.UnsupportedEncodingException e) {
e.printStackTrace();
} finally {
byteArray = null;
return r;
public static void main(String[] argv) {
byte[] a = new byte[0x10000];
for (int c = 0; c < 0x10000; c++) {
a[c] = (byte) (c % 256);
String s = "";
int LOOP = 10000;
long l = System.currentTimeMillis();
for (int i = 0; i < LOOP; i++) {
s = convertHex(a);
a = convertBytes(s);
l = System.currentTimeMillis() - l;
double d = l / (double) LOOP;
System.out.println("" + d + "ms.");
}
Thanks! Your code is essentially a microbenchmark testing the performance of sun.nio.cs.US_ASCII.Decoder.decodeLoop() and encodeLoop(), with ~35% and ~30% spent in those two methods respectively. I have verified the behavior (i.e. Sun is faster than JRockit). Due to the microbenchmark nature, it may not affect a larger running program, but it may merit a closer look regardless. I have forwarded to the JRockit perf team for analysis.
-- Henrik
Similar Messages
-
Can this script run faster?
Hello,
The User dictionary does not always seem to work properly. The workaround is a script that creates discretionary hyphens for certain words.
The following script first deletes all discretionary hyphens in a document being converted from PageMaker to InDesign. It then searches the document for 1900+ words and inserts discretionary hyphens in those words. The script has two arrays with that many elements, one for the words to be searched for, the other with the discretionary hyphens for those words. The script works fine but it takes about a minute to cycle through a 100 page document and 1900+ words.
Is there a way to re-write this script so that it goes faster? Just curious.
Thanks,
Tom
#target InDesign
app.scriptPreferences.version = 5.0;
var myDoc = app.activeDocument;
var discrecHyphen = theGrepChanger(myDoc,"~-","");
if(discrecHyphen.length > 0){
alert("I just deleted "+discrecHyphen.length+" discretionary hyphens.");
}//end if
else{
alert("There were no discretionary hyphens in this document.");
}//end else
var countWords = 0;
var numWords = "";
var wordsChanged = [];
var arrRawWords = ["humongous","array","of","thousand-plus","elements"];
var arrHyphenWords = ["hu~-mon~-gous","ar~-ray","of","thousand-~-plus","el~-e~-ments"];
for(var i =0; arrRawWords.length > i;i++){
var numWords = theGrepChanger(myDoc,arrRawWords[i],arrHyphenWords[i]);
if(numWords.length!=0){
wordsChanged.push(arrRawWords[i]);
}//end if
countWords +=numWords.length;
}//end for i
alert ("I just added discretionary hyphens for " +countWords+" words.\r\rSweet, huh?!");
//*****functions*******
function theGrepChanger(docRef,grepFindIt,grepChangeIt){
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
app.findGrepPreferences.findWhat = grepFindIt;
app.changeGrepPreferences.changeTo = grepChangeIt;
var arrGrepFindIt = myDoc.changeGrep();
return arrGrepFindIt;
}//end theGrepChangerOK, it's not the arrays. If you turn on the ESTK's profiler, you get this data:
Line
Time
Hits
1
1
1
4
6
1
5
1939
1
6
183
1
7
5
1
16
1
1
17
1
1
18
14
1
37
389785
1901
38
1981085
1901
39
2692741
1901
40
1197758
1901
41
1132369
1901
42
38969087
1901
43
2165
1901
44
1741
1901
45
9
2
I wrapped your script in a function() {} to see if it would report times in the array lookups, so it doesn't. Perhaps it's being optimized out. Anyhow, it spends all the time in line 42, which is the mydoc.changeGrep(). Oh, the document -- I placed Alice in Wonderland in 12pt Minion Pro Regular on 5.5"x8.5" pages, and then used as my raw words the first 1900 words in /usr/share/dict/words and as their hyphenation pairs inserted a ~ after every letter 'c'. Takes about 46 seconds to run.
You might also think it'd run faster if you opened the document with app.open(File("alice.indd",false) so it shows no window. This seems sort of true, but then ID crashes on the 872nd word ("accept", hyphed as "ac~c~ept"), probably one of the few words in my hyphenation list that actually shows up in Alice. Oh well... It also doesn't seem much faster -- takes about 20 seconds to get to 872, which seems about the same time as with the window open. -
Is this logging code faster than using a standard logging API like log4J
is this logging code faster than using a standard logging API like log4J or the logging API in java 1.4
As you can see my needs are extremely simple. write some stuff to text file and write some stuff to dos window.
I am thinking about using this with a multi threaded app. So all the threads ~ 200 will be using this simultaneously.
* Tracer.class logs items according to the following criteria:
* 2 = goes to text file Crawler_log.txt
* 1 = goes to console window because it is higher priority.
* @author Stephen
* @version 1.0
* @since June 2002
import java.io.*;
import java.net.*;
import java.util.*;
import java.text.*;
class Tracer{
public static void log(int traceLevel, String message, Object value)
if(traceLevel == 1){
System.out.println(getLogFileDate(new Date()) +" >" + message+ " value = " + value.toString()););
}else{
pout.write(getLogFileDate(new Date()) +" >" + message + " value = " + value.toString());
pout.flush();
public static void log(int traceLevel, String message )
if(traceLevel == 1){System.out.println(message);
}else{
pout.write(message ) ;
pout.flush();
//public static accessor method
public static Tracer getTracerInstance()
return tracerInstance;
private static String getLogFileDate(Date d )
String s = df.format(d);
String s1= s.replace(',','-');
String s2= s1.replace(' ','-');
String s3= s2.replace(':','.');
System.out.println("getLogFileDate() = " + s3 ) ;
return s3;
//private instance
private Tracer(){
System.out.println("Tracer constructor works");
df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
date = new java.util.Date();
try{
pout = new PrintWriter(new BufferedWriter(new FileWriter("Crawler_log"+getLogFileDate(new Date())+".txt", true)));
pout.write("**************** New Log File Created "+ getLogFileDate(new Date()) +"****************");
pout.flush();
}catch (IOException e){
System.out.println("**********THERE WAS A CRITICAL ERROR GETTING TRACER SINGLETON INITIALIZED. APPLICATION WILL STOP EXECUTION. ******* ");
public static void main(String[] argz){
System.out.println("main method starts ");
Tracer tt = Tracer.getTracerInstance();
System.out.println("main method successfully gets Tracer instance tt. "+ tt.toString());
//the next method is where it fails - on pout.write() of log method. Why ?
tt.log(1, "HIGH PRIORITY");
System.out.println("main method ends ");
//private static reference
private static Tracer tracerInstance = new Tracer();
private static Date date = null;
private static PrintWriter pout = null;
public static DateFormat df = null;
}In general I'd guess that a small, custom thing will be faster than a large, generic thing with a lot of options. That is, unless the writer of the small program have done something stupid, og the writer of the large program have done something very smart.
One problem with java in this respect is that it is next to impossible to judge exactly how much machine-level processing a single java statement takes. Things like JIT compilers makes it even harder.
In the end, there is really only one way to find out: Test it. -
Can a class implements more than one interface?
Hello
Can a class implements more than one interface?
ThanksOf course, this doesn't mean that it won't be a problem though. If the two interfaces have methods with the same signature, but different return types, you won't be able to implement them together. I.E.
interface InterfaceA {
public int doSomething(String myString);
interface InterfaceB {
public String doSomething(String myString);
// Now the classes
// Gives error "Duplicate method doSomething(String) in type ClassA"
public class ClassA implements InterfaceA, InterfaceB {
public int doSomething(String myString) {
System.out.println("A");
return 0;
public String doSomething(String myString) {
System.out.println("B");
return 0;
// Gives error "The return type is incompatible with InterfaceB.doSomething(String)"
public class ClassB implements InterfaceA, InterfaceB {
public int doSomething(String myString) {
System.out.println("A");
return 0;
// Gives error "The return type is incompatible with InterfaceA.doSomething(String)"
public class ClassC implements InterfaceA, InterfaceB {
public String doSomething(String myString) {
System.out.println("B");
return 0;
} -
Can anyone confirm Safari-4 runs "faster" than S4BETA?
Just like to know if my holding-out (want the blue progress bar) is costing me speed and features? That is-- is the Safari4 better/faster than Safari4-Beta?
Thanks!Hi again Steve
I have the beta running on my MacBook Pro and the final on my iMac. I don't see a difference, and I do like the blue progress bar.
I left the Beta on the MBP due to adverse Network issues specific to the Unibody machine when 10.5.7 was released. -
Performance Analysis: java classes run fast, but http response is delayed
Hello,
I´m analysing a performance issue on our application and I have the following symptons:
- A profile analysis with YourKit Java Profiler 7.5 told us that our java classes are running "fast" ( mostly less than 10s ).
- The access_log of the Oracle HTTP Server (httpd.conf LogFormat %T parameter) show us that the time taken to process the entire request is 130s
- The users told us that the application runs fast for a while, but after some minutes, the entire application runs slowly. After some minutes again, the entire application runs fast again.
- There are no overload of CPU, MEM, IO, Networking. All have been checked and are ok.
- At the same time the application A runs slowly, the application B on the same server ( but another instance ) runs normally.
- There is no database botleneck. All the application queries have been profiled and optimized for best run.
- A huge number of application threads exists on the java virtual machine. The peak was 187 threads ( mostly sleeping. Just one or two were running ). The threads average in the vm is 150.
- Our application has few EJB ( 4 ), few ejb-calls. All the EJB calls are cached with EhCache. The cache timeout is 2hours. When time-out occurs, the cache is invalidated, cleared and reloaded.
- We have only 10 users.
My hypothesis are:
1. Application server thread blocking. Some threads take until 13 minutes to finish, even when the java processing took only 23 seconds.
2. Some problem with the size of the AJP packages between HTTPServer and Application server.
I´m really desperate for help. Any help will be widely appreciated.
Oracle Application Server 9.0.3.3 running on
Sun Solaris 5.9
Sun Java Development Kit 1.4.1_05-b01
Is there any way to configure the max number of threads in the application server? Where?
Thanks in advance,
MuriloYou can tweak the application server threads as described here:
http://download.oracle.com/docs/cd/B31017_01/web.1013/b28950/threadpool.htm#BHBDGJBI
Oh just noticed you are on 9.0.3.3 -- that is a very, very, very* old release. I don't think we had a tunable thread-pool back then. The oldest doc I can find is for 10.1.2, which I think is where we first introduced the thread-pool manager:
http://download.oracle.com/docs/cd/B15904_01/web.1012/b14011/advanced.htm#i1014357
Is there any garbage collection occurring that could account for the slow-down in ART? I guess not if APP-B continues to run well over the same period.
-steve- -
Can a script run faster?
I've written a script that uses Adobe Soundbooth to compile and manipulate audio clips. Generating an 8 minute track via the script, however, takes about 5+ minutes. (Soundbooth must import and manipulate the files 1 by 1). Furthermore, during this time I must not touch the computer as to not interfere with the script's progress.
Adobe Soundbooth does not have Applescript support so there are many “tells” for “system events” etc. I’m wondering if I got Apple’s Soundtrack Pro, which does have an Applescript dictionary, the script could run faster? Or perhaps it could at least run in the background to free up the computer for other uses while it’s running?
I’m an Applescript newbie so I'm pretty clueless. I’m thrilled just to have written this first script!
Thank you so much for your help.Normally yes, although you can use use a " ignoring application responses" block to tell your script to not wait for a reply from an application.
e.g.
tell application "Finder"
ignoring application responses
duplicate theFile to folder Desktop
end ignoring
end tell
Normally the script would pause while it waits for the Finder to complete the duplication of the file, but in this script the script would just continue on without waiting.
Of course this can be risky. In the case of the above script, if I added a line to try to do something with the file on the desktop, that line will fail if the script executes it before the Finder has finished copying. Ignoring can be a nice way of having multiple applications working in parallel, but it's then up to the script to check that the tasks have completed. You should also bear in mind that errors may not be picked-up as they normally would if the script waited for confirmation. -
When will this thing run more than one app at the same time?
When will we be able to run more than one app at a time?
As has been suggested, we won't know about future features until they announce them, but by understanding the current situation we can guess.
The current limitations on third-party applications running in the background make sense. It's not a technical limitation. App store downloads, and the phone functionality run in the background while other applications are up front.
It's a resource limitation. Processor power and probably more importantly battery life are the key limiting factors. It's not that Apple doesn't want you to have more functionality. It's that it currently struggling to deliver a quality experience that satisfies as many customers as possible. As it is the battery life is only just acceptable enough for most current customers, many are unhappy with it.
So if more efficient chips or batteries become available, or some genius programmer manages to squeeze out a whole lot more out of less, then we'll see more background processes allowed. -
Why does audio run faster than video after burning my iMovie project in iDVD?
I created a project in iMovie HD and shared it to iDVD 6. When I played the finished disc, I noticed that the audio ran much faster than the video. I rechecked my movie and audio clips in iMovie to make sure they were matched correctly, and I saw no problem there. I burned the disc again through iDVD and got the same problem when I played it in a DVD player.
I have never had this problem before and I've been working on dvd projects all week. I think the only difference with this movie project is that I had movie clip audio and background audio playing at the same time at some parts of the movie, but I don't know if that's the issue.
Any suggestions?Hi
And just to add to OT-s brilliant suggestions - really - Do a Save as a DiskImage ! IMPORTANT !
• When free space goes down on the Start-Up hard disk to 5Gb or less - strange things occurs - Yes even audio out of sync - to not working DVD at all.
I secure a minimum of 25Gb free space when using SD-video to iDVD - if HD material I would guess 4-5 times more as it has to be re-calculated into SD and this needs space.
DVD - is as standard SD-Video (as old time CRT-TVs) - even if You use DVD-Studio Pro or iDVD or Roxio Toast™ - That's what it is and using HD material doesn't improve a bit (may be even give a lesser result)
Yours Bengt W -
Does the .rep report run faster than the same program in .rdf format
Hello,
We have some reports timing out because they take too
long to bring back results. If we used the .rep file instead of
the .rdf file, will the reports run faster? Does it take very
long to compile or is it most likely the SQL needs to be tuned
for better performance?
Thanks in Advance..
Pmoore31No, the report will not run faster. It is most likely that you
need to fine tune the SQL. -
HP dv7t CTO Corei7, Win7 . . . can this notebook run TRIM on SSD
I have a new HP dv7t CTO Notebook, Core-i7, 64bit Win7, 128GB Crucial SSD-SATA III. I also have a different, smaller SSD installed in the 2nd drive bay for data storage.
I have attempted to enable TRIM for the 128GB SSD with no success.
QUESTION: Can this notebook support TRIM ?
QUESTION: Could the trouble be that I have a 2nd SSD installed ?
Thanks for your help.
This question was solved.
View Solution.You are welcome
//Click on Kudos and Accept as Solution if my reply was helpful and answered your question//
I am an HP employee!! -
Is LabWindows​/CVI running faster than LabView?
A colleague told me that LabWindows/CVI is much faster than LabView. And I make a mistake if I would go on using LabView. So he tried to convince me of LabWindows/CVI. What are your experiences? Which program is faster: LabWindows/CVI or LabView?
maraIt all depends on what you're doing. I've used both (LabWindows since v1 and LabVIEW since v3), and in my instrument control and daq applications, I don't see any. I think LabVIEW is faster to develop in and that's the main advantage for me. NI has a benchmark here if that helps at all. Either LabVIEW or LabWindows is a good choice. If you're an experienced C programmer, you might be better off sticking with the more familar CVI but if you're not, LabVIEW should work just fine.
-
What can I do if script runs faster than network?
I've written an inter-application script that moves from InDesign, where it starts in AppleScript, to Photoshop, where the AppleScript runs a JavaScript to perform various tasks.
It runs beautifully on my laptop at home where I do my development. Yesterday, using myself as guinea pig, I tried it in the office.
On about the third run, I was horrified to see the ExtendScript Toolkit pop up with an error message (about as welcome as seeing an AppleScript inviting the user to open the Script Editor and fix a script).
The error message was that app.bringToFront(); was not a valid function.
This was true in InDesign, which has a different activation function, and I realised that even though my AppleScript had called for Photoshop to activate I was still in InDesign.
The JavaScript app.bringToFront had been called as well because I had enclosed my code in the Tranberry template.
So I pressed the stop button on ExtendScript, went back to InDesign and ran the script again. This time it worked as usual.
Occasionally on our network we spend some time beachball-watching as some communication goes on in the background. So I imagine that the time the error was thrown was on one of those network slowdowns.
The switch from InDesign to Photoshop did not happen fast enough, but the script ran on and issued a Photoshop JavaScript command while I was still in InDesign.
In AppleScript such unfortunate communication with users can be avoided using "try... on error" blocks.
Would there be any error-handling equivalent in JavaScript which would enable me to avoid them being thrown into ExtendScript Toolbox and would give them a friendly message apologising, explaining what had happened and inviting them to try again?Also AppleScript has a default timeout of 60 seconds before it wants to execute its next command. If in you case the opening and processing of the image in JavaScript takes any longer than this wrap your call out to Photoshop in a timeout block thus extending the alloted time to whatever you think may be suitable? Like so:
tell application "Adobe InDesign CS2"
activate
tell active document
set This_Image to image 1 of item 1 of rectangle 1
set Image_Path to file path of item link of (item 1 of This_Image) as alias
my Call_Photoshop(Image_Path)
delay 1 -- same as sleep(1000);
update item link of (item 1 of This_Image)
end tell
end tell
on Call_Photoshop(Image_Path)
with timeout of 180 seconds
tell application "Adobe Photoshop CS2"
activate
set display dialogs to never
open Image_Path
set ID_Image to the current document
tell ID_Image
-- do my stuff
close with saving
end tell
end tell
end timeout
end Call_Photoshop -
What can I do to make this query run faster
Hi All,
The below query is taking a long time. Is there any thing that I can do to shorten its time.
SELECT C.FOLIO_NO, C.CO_TRANS_NO TRANS_NO, to_char(C.CREATED_DATE, 'dd/mm/yyyy') DOC_DATE, DECODE(PP.NAME, NULL, D.EMP_NAME, PP.NAME) LODGED_BY, decode(sf_fetch_datechange(c.co_trans_no, C.CO_TRANS_ID), Null, '-', sf_fetch_datechange(c.co_trans_no, C.CO_TRANS_ID)) DATE_CHANGE, P.RECEIPT_NO, decode(c.co_trans_id,'A020',(select nvl(base_trans_id,co_trans_id) from co_form5a_trans f where f.co_trans_no=c.co_trans_no),c.co_trans_id) TRANS_ID,(case when decode(c.co_trans_id,'A020',(select nvl(base_trans_id,co_trans_id) from co_form5a_trans f where f.co_trans_no=c.co_trans_no),c.co_trans_id)='AR20' then 1 when decode(c.co_trans_id,'A020',(select nvl(base_trans_id,co_trans_id) from co_form5a_trans f where f.co_trans_no=c.co_trans_no),c.co_trans_id)='AR03' then 2 end) TRANS_TYPE FROM CO_TRANS_MASTER C, PAYMENT_DETAIL P, PEOPLE_PROFILE PP, SC_AGENT_EMP D, M_CAA_TRANS E where '1' <> TRIM(UPPER('S0750070Z')) and (C.CO_TRANS_ID in TRIM(UPPER('AR20')) OR C.CO_TRANS_ID in TRIM(UPPER('AR03'))OR c.co_trans_id IN TRIM (UPPER ('A020')))and C.CO_TRANS_NO = P.TRANS_NO and (C.VOID_IND = 'N' or C.VOID_IND is Null) and C.CREATED_BY = PP.PP_ID(+) and C.PROF_NO = D.PROF_NO(+) and C.CREATED_BY = D.EMP_ID (+) and TRIM(UPPER(C.CO_NO)) = TRIM(UPPER('200101586W')) and c.co_trans_id = e.trans_id (+) order by FOLIO_NO;
SQL>
SQL> show parameter user_dump_dest
NAME TYPE VALUE
user_dump_dest string /u01/app/oracle/diag/rdbms/ebi
zfile/EBIZFILE1/trace
SQL> show parameter optimizer
NAME TYPE VALUE
optimizer_capture_sql_plan_baselines boolean FALSE
optimizer_dynamic_sampling integer 2
optimizer_features_enable string 11.2.0.2
optimizer_index_caching integer 0
optimizer_index_cost_adj integer 100
optimizer_mode string ALL_ROWS
optimizer_secure_view_merging boolean TRUE
optimizer_use_invisible_indexes boolean FALSE
optimizer_use_pending_statistics boolean FALSE
optimizer_use_sql_plan_baselines boolean TRUE
SQL> show parameter db_file_multi
NAME TYPE VALUE
db_file_multiblock_read_count integer 128
SQL> show parameter db_block_size
NAME TYPE VALUE
db_block_size integer 8192
SQL> show parameter cursor_sharing
NAME TYPE VALUE
cursor_sharing string EXACT
SQL>
SQL> column sname format a20
SQL> column pname format a20
SQL> column pval2 format a20
SQL>
SQL> select
2 sname, pname, pval1, pval2
3 from
4 sys.aux_stats$;
SNAME PNAME PVAL1 PVAL2
SYSSTATS_INFO STATUS COMPLETED
SYSSTATS_INFO DSTART 09-11-2010 14:25
SYSSTATS_INFO DSTOP 09-11-2010 14:25
SYSSTATS_INFO FLAGS 1
SYSSTATS_MAIN CPUSPEEDNW 739.734748
SYSSTATS_MAIN IOSEEKTIM 10
SYSSTATS_MAIN IOTFRSPEED 4096
SYSSTATS_MAIN SREADTIM
SYSSTATS_MAIN MREADTIM
SYSSTATS_MAIN CPUSPEED
SYSSTATS_MAIN MBRC
SYSSTATS_MAIN MAXTHR
SYSSTATS_MAIN SLAVETHR
13 rows selected.
Elapsed: 00:00:00.06
SQL>
SQL> explain plan for
2 SELECT C.FOLIO_NO, C.CO_TRANS_NO TRANS_NO, to_char(C.CREATED_DATE, 'dd/mm/yyyy') DOC_DATE, DECODE(PP.NAME, NULL, D.EMP_NAME, PP.NAME) LODGED_BY, decode(sf_fetch_datechange(c.co_trans_no, C.CO_TRANS_ID), Null, '-', sf_fetch_datechange(c.co_trans_no, C.CO_TRANS_ID)) DATE_CHANGE, P.RECEIPT_NO, decode(c.co_trans_id,'A020',(select nvl(base_trans_id,co_trans_id) from co_form5a_trans f where f.co_trans_no=c.co_trans_no),c.co_trans_id) TRANS_ID,(case when decode(c.co_trans_id,'A020',(select nvl(base_trans_id,co_trans_id) from co_form5a_trans f where f.co_trans_no=c.co_trans_no),c.co_trans_id)='AR20' then 1 when decode(c.co_trans_id,'A020',(select nvl(base_trans_id,co_trans_id) from co_form5a_trans f where f.co_trans_no=c.co_trans_no),c.co_trans_id)='AR03' then 2 end) TRANS_TYPE FROM CO_TRANS_MASTER C, PAYMENT_DETAIL P, PEOPLE_PROFILE PP, SC_AGENT_EMP D, M_CAA_TRANS E where '1' <> TRIM(UPPER('S0750070Z')) and (C.CO_TRANS_ID in TRIM(UPPER('AR20')) OR C.CO_TRANS_ID in TRIM(UPPER('AR03'))OR c.co_trans_id IN TRIM (UPPER ('A020')))and C.CO_TRANS_NO = P.TRANS_NO and (C.VOID_IND = 'N' or C.VOID_IND is Null) and C.CREATED_BY = PP.PP_ID(+) and C.PROF_NO = D.PROF_NO(+) and C.CREATED_BY = D.EMP_ID (+) and TRIM(UPPER(C.CO_NO)) = TRIM(UPPER('200101586W')) and c.co_trans_id = e.trans_id (+) order by FOLIO_NO;
Explained.
Elapsed: 00:00:00.09
SQL>
SQL> set pagesize 1000;
SQL> set linesize 170;
SQL> @/u01/app/oracle/product/11.2.0/rdbms/admin/utlxpls.sql
SQL> Rem
SQL> Rem $Header: utlxpls.sql 26-feb-2002.19:49:37 bdagevil Exp $
SQL> Rem
SQL> Rem utlxpls.sql
SQL> Rem
SQL> Rem Copyright (c) 1998, 2002, Oracle Corporation. All rights reserved.
SQL> Rem
SQL> Rem NAME
SQL> Rem utlxpls.sql - UTiLity eXPLain Serial plans
SQL> Rem
SQL> Rem DESCRIPTION
SQL> Rem script utility to display the explain plan of the last explain plan
SQL> Rem command. Do not display information related to Parallel Query
SQL> Rem
SQL> Rem NOTES
SQL> Rem Assume that the PLAN_TABLE table has been created. The script
SQL> Rem utlxplan.sql should be used to create that table
SQL> Rem
SQL> Rem With SQL*plus, it is recomended to set linesize and pagesize before
SQL> Rem running this script. For example:
SQL> Rem set linesize 100
SQL> Rem set pagesize 0
SQL> Rem
SQL> Rem MODIFIED (MM/DD/YY)
SQL> Rem bdagevil 02/26/02 - cast arguments
SQL> Rem bdagevil 01/23/02 - rewrite with new dbms_xplan package
SQL> Rem bdagevil 04/05/01 - include CPU cost
SQL> Rem bdagevil 02/27/01 - increase Name column
SQL> Rem jihuang 06/14/00 - change order by to order siblings by.
SQL> Rem jihuang 05/10/00 - include plan info for recursive SQL in LE row source
SQL> Rem bdagevil 01/05/00 - add order-by to make it deterministic
SQL> Rem kquinn 06/28/99 - 901272: Add missing semicolon
SQL> Rem bdagevil 05/07/98 - Explain plan script for serial plans
SQL> Rem bdagevil 05/07/98 - Created
SQL> Rem
SQL>
SQL> set markup html preformat on
SQL>
SQL> Rem
SQL> Rem Use the display table function from the dbms_xplan package to display the last
SQL> Rem explain plan. Force serial option for backward compatibility
SQL> Rem
SQL> select plan_table_output from table(dbms_xplan.display('plan_table',null,'serial'));
PLAN_TABLE_OUTPUT
Plan hash value: 2520189693
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 592 | 85248 | 16573 (1)| 00:03:19 |
| 1 | TABLE ACCESS BY INDEX ROWID | CO_FORM5A_TRANS | 1 | 20 | 2 (0)| 00:00:01 |
|* 2 | INDEX UNIQUE SCAN | SYS_C0059692 | 1 | | 1 (0)| 00:00:01 |
| 3 | TABLE ACCESS BY INDEX ROWID | CO_FORM5A_TRANS | 1 | 20 | 2 (0)| 00:00:01 |
|* 4 | INDEX UNIQUE SCAN | SYS_C0059692 | 1 | | 1 (0)| 00:00:01 |
| 5 | TABLE ACCESS BY INDEX ROWID | CO_FORM5A_TRANS | 1 | 20 | 2 (0)| 00:00:01 |
|* 6 | INDEX UNIQUE SCAN | SYS_C0059692 | 1 | | 1 (0)| 00:00:01 |
| 7 | SORT ORDER BY | | 592 | 85248 | 16573 (1)| 00:03:19 |
| 8 | NESTED LOOPS | | | | | |
| 9 | NESTED LOOPS | | 592 | 85248 | 16572 (1)| 00:03:19 |
| 10 | NESTED LOOPS OUTER | | 477 | 54855 | 15329 (1)| 00:03:04 |
| 11 | NESTED LOOPS OUTER | | 477 | 41499 | 14374 (1)| 00:02:53 |
| 12 | INLIST ITERATOR | | | | | |
|* 13 | TABLE ACCESS BY INDEX ROWID| CO_TRANS_MASTER | 477 | 22896 | 14367 (1)| 00:02:53 |
|* 14 | INDEX RANGE SCAN | IDX_CO_TRANS_ID | 67751 | | 150 (1)| 00:00:02 |
| 15 | TABLE ACCESS BY INDEX ROWID | SC_AGENT_EMP | 1 | 39 | 1 (0)| 00:00:01 |
|* 16 | INDEX UNIQUE SCAN | PK_SC_AGENT_EMP | 1 | | 0 (0)| 00:00:01 |
| 17 | TABLE ACCESS BY INDEX ROWID | PEOPLE_PROFILE | 1 | 28 | 2 (0)| 00:00:01 |
|* 18 | INDEX UNIQUE SCAN | SYS_C0063100 | 1 | | 1 (0)| 00:00:01 |
|* 19 | INDEX RANGE SCAN | IDX_PAY_DETAIL_TRANS_NO | 1 | | 2 (0)| 00:00:01 |
| 20 | TABLE ACCESS BY INDEX ROWID | PAYMENT_DETAIL | 1 | 29 | 3 (0)| 00:00:01 |
Predicate Information (identified by operation id):
2 - access("F"."CO_TRANS_NO"=:B1)
4 - access("F"."CO_TRANS_NO"=:B1)
6 - access("F"."CO_TRANS_NO"=:B1)
13 - filter(TRIM(UPPER("SYS_ALIAS_3"."CO_NO"))='200101586W' AND ("SYS_ALIAS_3"."VOID_IND" IS NULL
OR "SYS_ALIAS_3"."VOID_IND"='N'))
14 - access("SYS_ALIAS_3"."CO_TRANS_ID"='A020' OR "SYS_ALIAS_3"."CO_TRANS_ID"='AR03' OR
"SYS_ALIAS_3"."CO_TRANS_ID"='AR20')
16 - access("SYS_ALIAS_3"."PROF_NO"="D"."PROF_NO"(+) AND
"SYS_ALIAS_3"."CREATED_BY"="D"."EMP_ID"(+))
18 - access("SYS_ALIAS_3"."CREATED_BY"="PP"."PP_ID"(+))
19 - access("SYS_ALIAS_3"."CO_TRANS_NO"="P"."TRANS_NO")
42 rows selected.
Elapsed: 00:00:00.53
SQL>
SQL>
SQL>
SQL> rollback;
Rollback complete.
Elapsed: 00:00:00.01
SQL>
SQL> rem Set the ARRAYSIZE according to your application
SQL> set autotrace traceonly arraysize 100
SQL>
SQL> alter session set tracefile_identifier = 'mytrace1';
Session altered.
Elapsed: 00:00:00.00
SQL>
SQL> rem if you're using bind variables
SQL> rem define them here
SQL>
SQL> rem variable b_var1 number
SQL> rem variable b_var2 varchar2(20)
SQL>
SQL> rem and initialize them
SQL>
SQL> rem exec :b_var1 := 1
SQL> rem exec :b_var2 := 'DIAG'
SQL> set pagesize 1000;
SQL> set linesize 170;
SQL> alter session set events '10046 trace name context forever, level 8';
Session altered.
Elapsed: 00:00:00.01
SQL> SELECT C.FOLIO_NO, C.CO_TRANS_NO TRANS_NO, to_char(C.CREATED_DATE, 'dd/mm/yyyy') DOC_DATE, DECODE(PP.NAME, NULL, D.EMP_NAME, PP.NAME) LODGED_BY, decode(sf_fetch_datechange(c.co_trans_no, C.CO_TRANS_ID), Null, '-', sf_fetch_datechange(c.co_trans_no, C.CO_TRANS_ID)) DATE_CHANGE, P.RECEIPT_NO, decode(c.co_trans_id,'A020',(select nvl(base_trans_id,co_trans_id) from co_form5a_trans f where f.co_trans_no=c.co_trans_no),c.co_trans_id) TRANS_ID,(case when decode(c.co_trans_id,'A020',(select nvl(base_trans_id,co_trans_id) from co_form5a_trans f where f.co_trans_no=c.co_trans_no),c.co_trans_id)='AR20' then 1 when decode(c.co_trans_id,'A020',(select nvl(base_trans_id,co_trans_id) from co_form5a_trans f where f.co_trans_no=c.co_trans_no),c.co_trans_id)='AR03' then 2 end) TRANS_TYPE FROM CO_TRANS_MASTER C, PAYMENT_DETAIL P, PEOPLE_PROFILE PP, SC_AGENT_EMP D, M_CAA_TRANS E where '1' <> TRIM(UPPER('S0750070Z')) and (C.CO_TRANS_ID in TRIM(UPPER('AR20')) OR C.CO_TRANS_ID in TRIM(UPPER('AR03'))OR c.co_trans_id IN TRIM (UPPER ('A020')))and C.CO_TRANS_NO = P.TRANS_NO and (C.VOID_IND = 'N' or C.VOID_IND is Null) and C.CREATED_BY = PP.PP_ID(+) and C.PROF_NO = D.PROF_NO(+) and C.CREATED_BY = D.EMP_ID (+) and TRIM(UPPER(C.CO_NO)) = TRIM(UPPER('200101586W')) and c.co_trans_id = e.trans_id (+) order by FOLIO_NO;
10 rows selected.
Elapsed: 00:03:42.27
Execution Plan
Plan hash value: 2520189693
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 592 | 85248 | 16573 (1)| 00:03:19 |
| 1 | TABLE ACCESS BY INDEX ROWID | CO_FORM5A_TRANS | 1 | 20 | 2 (0)| 00:00:01 |
|* 2 | INDEX UNIQUE SCAN | SYS_C0059692 | 1 | | 1 (0)| 00:00:01 |
| 3 | TABLE ACCESS BY INDEX ROWID | CO_FORM5A_TRANS | 1 | 20 | 2 (0)| 00:00:01 |
|* 4 | INDEX UNIQUE SCAN | SYS_C0059692 | 1 | | 1 (0)| 00:00:01 |
| 5 | TABLE ACCESS BY INDEX ROWID | CO_FORM5A_TRANS | 1 | 20 | 2 (0)| 00:00:01 |
|* 6 | INDEX UNIQUE SCAN | SYS_C0059692 | 1 | | 1 (0)| 00:00:01 |
| 7 | SORT ORDER BY | | 592 | 85248 | 16573 (1)| 00:03:19 |
| 8 | NESTED LOOPS | | | | | |
| 9 | NESTED LOOPS | | 592 | 85248 | 16572 (1)| 00:03:19 |
| 10 | NESTED LOOPS OUTER | | 477 | 54855 | 15329 (1)| 00:03:04 |
| 11 | NESTED LOOPS OUTER | | 477 | 41499 | 14374 (1)| 00:02:53 |
| 12 | INLIST ITERATOR | | | | | |
|* 13 | TABLE ACCESS BY INDEX ROWID| CO_TRANS_MASTER | 477 | 22896 | 14367 (1)| 00:02:53 |
|* 14 | INDEX RANGE SCAN | IDX_CO_TRANS_ID | 67751 | | 150 (1)| 00:00:02 |
| 15 | TABLE ACCESS BY INDEX ROWID | SC_AGENT_EMP | 1 | 39 | 1 (0)| 00:00:01 |
|* 16 | INDEX UNIQUE SCAN | PK_SC_AGENT_EMP | 1 | | 0 (0)| 00:00:01 |
| 17 | TABLE ACCESS BY INDEX ROWID | PEOPLE_PROFILE | 1 | 28 | 2 (0)| 00:00:01 |
|* 18 | INDEX UNIQUE SCAN | SYS_C0063100 | 1 | | 1 (0)| 00:00:01 |
|* 19 | INDEX RANGE SCAN | IDX_PAY_DETAIL_TRANS_NO | 1 | | 2 (0)| 00:00:01 |
| 20 | TABLE ACCESS BY INDEX ROWID | PAYMENT_DETAIL | 1 | 29 | 3 (0)| 00:00:01 |
Predicate Information (identified by operation id):
2 - access("F"."CO_TRANS_NO"=:B1)
4 - access("F"."CO_TRANS_NO"=:B1)
6 - access("F"."CO_TRANS_NO"=:B1)
13 - filter(TRIM(UPPER("SYS_ALIAS_3"."CO_NO"))='200101586W' AND ("SYS_ALIAS_3"."VOID_IND" IS NULL
OR "SYS_ALIAS_3"."VOID_IND"='N'))
14 - access("SYS_ALIAS_3"."CO_TRANS_ID"='A020' OR "SYS_ALIAS_3"."CO_TRANS_ID"='AR03' OR
"SYS_ALIAS_3"."CO_TRANS_ID"='AR20')
16 - access("SYS_ALIAS_3"."PROF_NO"="D"."PROF_NO"(+) AND
"SYS_ALIAS_3"."CREATED_BY"="D"."EMP_ID"(+))
18 - access("SYS_ALIAS_3"."CREATED_BY"="PP"."PP_ID"(+))
19 - access("SYS_ALIAS_3"."CO_TRANS_NO"="P"."TRANS_NO")
Statistics
51 recursive calls
0 db block gets
651812 consistent gets
92202 physical reads
0 redo size
1594 bytes sent via SQL*Net to client
524 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
10 rows processed
SQL>
SQL> disconnect
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
SQL> Thanks in advance!Hi Raj,
I have given the output below as you requested....
QL> select * from table(dbms_xplan.display_cursor(null, null, 'ALLSTATS LAST'));
PLAN_TABLE_OUTPUT
SQL_ID 0taz7ckjm41yv, child number 1
SELECT C.FOLIO_NO, C.CO_TRANS_NO TRANS_NO, to_char(C.CREATED_DATE,
'dd/mm/yyyy') DOC_DATE, DECODE(PP.NAME, NULL, D.EMP_NAME, PP.NAME)
LODGED_BY, decode(sf_fetch_datechange(c.co_trans_no, C.CO_TRANS_ID),
Null, '-', sf_fetch_datechange(c.co_trans_no, C.CO_TRANS_ID))
DATE_CHANGE, P.RECEIPT_NO, decode(c.co_trans_id,'A020',(select
nvl(base_trans_id,co_trans_id) from co_form5a_trans f where
f.co_trans_no=c.co_trans_no),c.co_trans_id) TRANS_ID,(case when
decode(c.co_trans_id,'A020',(select nvl(base_trans_id,co_trans_id) from
co_form5a_trans f where f.co_trans_no=c.co_trans_no),c.co_trans_id)='AR2
0' then 1 when decode(c.co_trans_id,'A020',(select
nvl(base_trans_id,co_trans_id) from co_form5a_trans f where
f.co_trans_no=c.co_trans_no),c.co_trans_id)='AR03' then 2 end)
TRANS_TYPE FROM CO_TRANS_MASTER C, PAYMENT_DETAIL P, PEOPLE_PROFILE PP,
SC_AGENT_EMP D, M_CAA_TRANS E where '1' <> TRIM(UPPER('S0750070Z')) and
(C.CO_TRANS_ID in TRIM(UPPER('AR20')) OR C.CO_TRANS_ID in
TRIM(UPPER('AR03'))OR c.co
Plan hash value: 4175354585
| Id | Operation | Name | E-Rows | OMem | 1Mem | Used-Mem |
| 0 | SELECT STATEMENT | | | | | |
| 1 | TABLE ACCESS BY INDEX ROWID | CO_FORM5A_TRANS | 1 | | | |
|* 2 | INDEX UNIQUE SCAN | SYS_C0059692 | 1 | | | |
| 3 | TABLE ACCESS BY INDEX ROWID | CO_FORM5A_TRANS | 1 | | | |
|* 4 | INDEX UNIQUE SCAN | SYS_C0059692 | 1 | | | |
| 5 | TABLE ACCESS BY INDEX ROWID | CO_FORM5A_TRANS | 1 | | | |
|* 6 | INDEX UNIQUE SCAN | SYS_C0059692 | 1 | | | |
| 7 | SORT ORDER BY | | 12 | 2048 | 2048 | 2048 (0)|
| 8 | NESTED LOOPS | | | | | |
| 9 | NESTED LOOPS | | 12 | | | |
| 10 | NESTED LOOPS OUTER | | 10 | | | |
| 11 | NESTED LOOPS OUTER | | 10 | | | |
|* 12 | TABLE ACCESS FULL | CO_TRANS_MASTER | 10 | | | |
| 13 | TABLE ACCESS BY INDEX ROWID| SC_AGENT_EMP | 1 | | | |
|* 14 | INDEX UNIQUE SCAN | PK_SC_AGENT_EMP | 1 | | | |
| 15 | TABLE ACCESS BY INDEX ROWID | PEOPLE_PROFILE | 1 | | | |
|* 16 | INDEX UNIQUE SCAN | SYS_C0063100 | 1 | | | |
|* 17 | INDEX RANGE SCAN | IDX_PAY_DETAIL_TRANS_NO | 1 | | | |
| 18 | TABLE ACCESS BY INDEX ROWID | PAYMENT_DETAIL | 1 | | | |
Predicate Information (identified by operation id):
2 - access("F"."CO_TRANS_NO"=:B1)
4 - access("F"."CO_TRANS_NO"=:B1)
6 - access("F"."CO_TRANS_NO"=:B1)
12 - filter((INTERNAL_FUNCTION("SYS_ALIAS_3"."CO_TRANS_ID") AND
TRIM(UPPER("SYS_ALIAS_3"."CO_NO"))='200101586W' AND ("SYS_ALIAS_3"."VOID_IND" IS NULL OR
"SYS_ALIAS_3"."VOID_IND"='N')))
14 - access("SYS_ALIAS_3"."PROF_NO"="D"."PROF_NO" AND "SYS_ALIAS_3"."CREATED_BY"="D"."EMP_ID")
16 - access("SYS_ALIAS_3"."CREATED_BY"="PP"."PP_ID")
17 - access("SYS_ALIAS_3"."CO_TRANS_NO"="P"."TRANS_NO")
Note
- cardinality feedback used for this statement
- Warning: basic plan statistics not available. These are only collected when:
* hint 'gather_plan_statistics' is used for the statement or
* parameter 'statistics_level' is set to 'ALL', at session or system level
65 rows selected. -
Can this train run any faster...?
Hello virtual suggestion givers!
Everything's working pretty ok when I enter small values while instantiating Train class, the thing is that when I enter large values about lets say
new Train(5,96,5,10) its giving me IndexOutOfbounds exception or acting weirdly.
I think there might be some problem in my Train class...
should ArrayList be used instead of LinkedList?
what's the flaw in the code?
Is there anything redundant in this code?
I had lot's of time this time in my hand, so I didn't have to come in here frequently.
==========================================
concepts? inheritance? homework? don't understand?
==========================================
import type.lang.*;
import java.util.*;
public class Train {
public Train(int numSaloonCars, int nSeats, int numSleepingCars,
int nBerths) {
if((numSaloonCars + numSleepingCars) <= 0
|| (nSeats + nBerths) <= 0) {
throw new IllegalArgumentException("input valid data!");
} else {
for(int i = 0; i < numSaloonCars; i++) {
atotal.add(new SaloonCar(nSeats));
for(int m = 0; m < numSleepingCars; m++) {
btotal.add(new SleepingCar(nBerths));
public String reserveSpace(String spaceType, int numP) {
StringBuffer buf = new StringBuffer();
if(( !spaceType.equals(BERTH) && !spaceType.equals(SEAT))
|| (numP <= 0)) {
throw new IllegalArgumentException("enter proper data!");
} else if(spaceType.equals(SEAT)) {
List train = new LinkedList(atotal);
for(int i = 0; i < train.size(); i++) {
if(numP == ((SaloonCar) train.get(i)).getAvailableSpace()) {
buf.append(
((SaloonCar) train.get(i)).addPassengers(numP));
} else if(numP
< ((SaloonCar) train.get(i)).getAvailableSpace()) {
buf.append(((RailCar) train.get(i)).addPassengers(numP));
} else {
throw new TrainFullException("Train's Full!");
} else if(spaceType.equals(BERTH)) {
List train2 = new LinkedList(btotal);
for(int m = 0; m < train2.size(); m++) {
if(numP == ((SleepingCar) train2.get(
m)).getAvailableSpace()) {
buf.append(
((SleepingCar) train2.get(m)).addPassengers(numP));
} else if(numP
< ((SleepingCar) train2.get(
m)).getAvailableSpace()) {
buf.append(
((SleepingCar) train2.get(m)).addPassengers(numP));
} else {
throw new TrainFullException("Train's Full!");
return buf.toString();
public String toString() {
StringBuffer buf = new StringBuffer("Train [");
List list = new LinkedList(atotal);
List list2 = new LinkedList(btotal);
for(int i = 0; i < list.size(); i++) {
buf.append(" SaloonCar[ ");
buf.append(((SaloonCar) list.get(i)).toString() + " ]");
for(int m = 0; m < list2.size(); m++) {
buf.append(" SleepingCar[ ");
buf.append(((SleepingCar) list2.get(m)).toString() + " ]");
return buf.toString();
private List atotal = new LinkedList();
private List btotal = new LinkedList();
public static final String BERTH = "berth";
public static final String SEAT = "seat";
import java.lang.*;
import java.util.*;
public abstract class RailCar {
public RailCar(Collection s) {
this.s = s;
public abstract String addPassengers(int p);
public String allocateAvailableSpace(int p) {
StringBuffer buf = new StringBuffer();
int inP = p;
int total = 0;
List list = new LinkedList(s);
for(int i = 0; i < list.size(); i++) {
if(inP > ((OccupiableSpace) list.get(i)).getMaximumOccupants())
//check maximumoccupants allowed
throw new IllegalArgumentException(
"shold be = or < MAXOccupants of seat");
} else if(isFull()) {
//check for total available space in the railcar
throw new CarFullException("Car is full!");
++number; // i replicator
((OccupiableSpace) list.get(number-1)).addOccupants(inP);
buf.append(((OccupiableSpace) list.get(number-1)).getId() + " ,");
return buf.toString();
public int getAvailableSpace() {
int total = 0;
List list = new LinkedList(s);
for(int i = 0; i < list.size(); i++) {
total += (((OccupiableSpace) list.get(i)).getVacantSpace());
return total;
public abstract int getMaximumOccupancy();
public boolean hasSpace() {
if(getAvailableSpace() == 0) {
return false;
} else {
return true;
public boolean isFull() {
if(getAvailableSpace() == 0) {
return true;
} else {
return false;
public String toString() {
StringBuffer buf = new StringBuffer();
String tostring = "";
List list = new ArrayList(s);
for(int i = 0; i < list.size(); i++) {
if(((OccupiableSpace) list.get(i)) instanceof Seat) {
tostring +=
"SaloonCar ["
+ buf.append(
"Seat" + "[ " + ((Seat) list.get(i)).getId() + " = "
+ ((Seat) list.get(i)).getOccupants() + "] ") + " ]";
} else if(((OccupiableSpace) list.get(i)) instanceof Berth) {
tostring +=
"SleepingCar"
+ buf.append(
"Berth" + "[ " + ((Berth) list.get(i)).getId()
+ " = " + ((Berth) list.get(i)).getOccupants()
+ "] ") + " ]";
return buf.toString();
public Collection s;
public static int number = 0;
import java.util.*;
public class SaloonCar extends RailCar {
public static final int MAX_SEATS = 96;
public SaloonCar(int numSeats) {
super(new LinkedList());
if( !((numSeats <= 0) || (numSeats > MAX_SEATS))) {
for(int i = 0; i <= numSeats - 1; i++) {
s.add(new Seat());
} else {
throw new IllegalArgumentException("should be >= 0 & < MAX");
public String addPassengers(int p) {
StringBuffer buf = new StringBuffer();
int total = 0;
List bag = new LinkedList(s);
if(p <= 0) {
throw new IllegalArgumentException("should be >= 0");
} else if(p > getAvailableSpace()) {
throw new CarFullException("car's full");
} else {
for(int i = 0; i < p; i++) {
buf.append(allocateAvailableSpace(Seat.MAX_OCCUPANTS));
return buf.toString();
public int getMaximumOccupancy() {
return MAX_SEATS;
import java.util.*;
public class SleepingCar extends RailCar {
public static final int MAX_BERTHS = 16;
public final int ONE = 1;
public SleepingCar(int numSeats) {
super(new LinkedList());
if( !((numSeats <= 0) || (numSeats > MAX_BERTHS))) {
for(int i = 0; i < numSeats; i++) {
s.add(new Berth());
} else {
throw new IllegalArgumentException("should be >= 0 & < MAX");
public String addPassengers(int p) {
StringBuffer buf = new StringBuffer();
int total = 0;
List bag = new LinkedList(s);
if(p <= 0) {
throw new IllegalArgumentException("should be >= 0");
} else if(p > getAvailableSpace()) {
throw new CarFullException("car's full");
} else {
int found = 0;
double check = p;
List list = new LinkedList(s);
for(int i = 0; i < list.size(); i++) {
if(list.get(i) instanceof Berth) {
if(check / 2 != 0) {
int num = ((Berth) list.get(i)).getOccupants();
if((num == 0) || (num == 1)) {
found = i;
if(check / 2 == 0) {
for(int m = 0; m < check / 2; m++) {
buf.append(allocateAvailableSpace(Berth.MAX_OCCUPANTS));
} else if(check / 2 != 0) {
((Berth) list.get(found)).addOccupants(ONE);
buf.append(((Berth) list.get(found)).getId() + " ,");
check--;
for(int z = 0; z < check / 2; z++) {
buf.append(allocateAvailableSpace(Berth.MAX_OCCUPANTS));
return buf.toString();
public int getMaximumOccupancy() {
return MAX_BERTHS;
import type.lang.* ;
import java.lang.* ;
public abstract class OccupiableSpace
public OccupiableSpace(String code)
idcode = code ;
public void addOccupants(int num)
if (num > getMaximumOccupants() || num < 0)
throw new IllegalArgumentException() ;
else
numOccupants += num ;
public boolean equals(Object o)
if (o ==null) return false;
if (getClass() != o.getClass()) return false;
OccupiableSpace oin = (OccupiableSpace) o;
return idcode.equals(oin.getId());
public String getId()
return idcode ;
public abstract int getMaximumOccupants() ;
public int getOccupants()
return numOccupants ;
public int getVacantSpace()
int left = getMaximumOccupants() - getOccupants() ;
return left ;
public boolean isOccupied()
if (getVacantSpace() == 0)
return true;
else
return false;
public void removeOccupants(int o)
if (o > getOccupants() || o <= 0)
throw new IllegalArgumentException() ;
else
numOccupants -= o ;
public String toString()
String ans = getClass().getName() + "[ id=" + idcode + ", occupants=" +
numOccupants + " ]" ;
return ans ;
public int numOccupants ;
public String idcode = "" ;
public class Berth
extends OccupiableSpace
public Berth()
super("B-"+number);
number++ ;
public int getMaximumOccupants()
return MAX_OCCUPANTS ;
public static final int MAX_OCCUPANTS = 2 ;
private static int number = 1 ;
public class Seat
extends OccupiableSpace
public Seat()
super("S-" + number) ;
number++ ;
public int getMaximumOccupants()
return MAX_OCCUPANTS ;
public static final int MAX_OCCUPANTS = 1 ;
private static int number = 1;
public class TrainFullException extends RuntimeException {
public TrainFullException() {
super();
public TrainFullException(String msg) {
super(msg);
public class CarFullException extends RuntimeException {
public CarFullException() {
super();
public CarFullException(String msg) {
super(msg);what could be wrong in this part?
using System.out ... in a class file !?
if(( !spaceType.equals(BERTH) && !spaceType.equals(SEAT))
|| (numP <= 0)) {
throw new IllegalArgumentException("enter proper data!");
} else if(spaceType.equals(SEAT)) {
List train = new LinkedList(atotal);
for(int i = 0; i < train.size(); i++) {
if(numP == ((SaloonCar) train.get(i)).getAvailableSpace()) {
buf.append(
((SaloonCar) train.get(i)).addPassengers(numP));
} else if(numP
< ((SaloonCar) train.get(i)).getAvailableSpace()) {
buf.append(((RailCar) train.get(i)).addPassengers(numP));
} else {
throw new TrainFullException("Train's Full!");
}ahh... may be i am exhaus...
Maybe you are looking for
-
Music App (iPad & iPod Touch)
Has anyone else who uses the Music App's Sort Artist to alphabetize artists by last name noticed this is no longer working? At least on my devices (iPod Touch & iPad 2) this function seems broken. Maybe it's just a setting I've neglected?
-
Best File Format to use for iTunes and MAC
I have always used the AAC Encoder set to 256 kbps to import my CDs to iTunes. In preparation for moving to a music server system in the future I want to re-import my CDs at the highest quality (uncompressed) format that I can. Is my understanding co
-
Hide certain steps in the execution view
I am trying to modify the TestStand 4.0 simple OI using C# 2005 for the OI and LabVIEW 8.2.1 for the test development. In many ways, there is more on this "simple" interface than an operator needs to see. The execution window is too verbose. I would
-
I have an iMac running 10.8. I recently installed windows 7 using boot camp. During the installation I got an error that installation had failed. Upon rebooting I now get bootmgr is missing. I have tried booting holding alt,cmd,t,c and eject. I can't
-
Why facetime can't open in os x mountain lion
why facetime can't open in os x mountain lion. and it always say can't find the facetime server!