Traversing an array - start with i=1 or i =

dupe thread, delete please
Edited by: ohshititsaliongetinthecar on Apr 30, 2008 7:12 PM

Yep, 0 or 1 depending on the circumstances... but yeah, 0 is ALLWAYS the first element in a java array, definately definately.
<aside>VB's Option Base was THE worste idea in the history of programming languages (barring regex's of course ;-).</aside>
<warning>This code hasn't even been compiled, let alone tested.</warning>
  public String join(String... array) {
    int n = array.length;
    if (array==null || n==0) return "";
    StringBuffer result = new StringBuffer(""+array[0]);
    for(int i=1; i<n; i++) {
      result.append(", "+array);
return result.toString();
Cheers. Keith.
Edited by: corlettk on 1/05/2008 12:54 - Oops!

Similar Messages

  • How to traverse an array with a for-loop in this certain way...

    so I need to traverse an array starting from the first element, then from the last element, then the second element, then the second last element, then third element and so on... in a for loop
    how would that look in code?
    Any help would be appreciated, thanks!
    Edited by: inspiredone on Apr 4, 2008 6:34 AM

    Wow, that's a really clever and elegant way to do it promethuzz. I actually came up with something already before I read your post so yeah don't worry about me copying or anything. Mine is not as elegant/efficient and I definitely like yours a lot more but I will just share it anyway...it looks pretty similar to the second algorithm The_Matrix has provided. I figured this out from thinking how quicksort compares its pivot with the two indexes...
        int front=0;
        int back = a.length - 1;
        int counter =0;
        boolean switchflag = true;
        while(front<=back)
          System.out.println(a[counter]);
          if(switchflag)
            counter = back;
            front++;
            switchflag = false;
          else
            counter = front;
            back--;
            switchflag = true;
        } Anyways, thanks a lot for you guys help, promethuzz, The_Matrix, and newark.
    Edited by: inspiredone on Apr 4, 2008 11:25 AM
    Edited by: inspiredone on Apr 4, 2008 11:27 AM

  • Property List error: Unexpected character b at line 1 / JSON error: JSON text did not start with array or object and option to allow fragments not set.

    Hi,
    I have a MBP 13' Late 2011 and Yosemite 10.10.2 (14C1514).
    Until yesterday, I was using Garmin ConnectIQ SDK and all was working fine.
    Yesterday, I've updated my system with latest security updates and Xcode updates too (Version 6.2 (6C131e)).
    Since, I can't launch the ConnectIQ simulator app, I have this message in console :
    8/04/2015 15:19:04,103 mds[38]: There was an error parsing the Info.plist for the bundle at URL Info.plist -- file:///Volumes/Leto/connectiq-sdk-mac-1.1.0_2/ios/ConnectIQ.bundle/
    The data couldn’t be read because it isn’t in the correct format.
    <CFBasicHash 0x7fa64f44e9a0 [0x7fff7dfc7cf0]>{type = immutable dict, count = 2,
    entries =>
      0 : <CFString 0x7fff7df92580 [0x7fff7dfc7cf0]>{contents = "NSDebugDescription"} = <CFString 0x7fa64f44f0a0 [0x7fff7dfc7cf0]>{contents = "Unexpected character b at line 1"}
      1 : <CFString 0x7fff7df9f5e0 [0x7fff7dfc7cf0]>{contents = "kCFPropertyListOldStyleParsingError"} = Error Domain=NSCocoaErrorDomain Code=3840 "The data couldn’t be read because it isn’t in the correct format." (Conversion of string failed.) UserInfo=0x7fa64f44eda0 {NSDebugDescription=Conversion of string failed.}
    I have looked at this file and it looks like a binary plist
    bplist00ß^P^V^A^B^C^D^E^F^G^H
    ^K^L^M^N^O^P^Q^R^S^T^U^V^W^X^Y^Z^[^\^]^^^_ !"$%&'()'+,^[\CFBundleNameWDTXcodeYDTSDKName_^P^XNSHumanReadableCopyrightZDTSDKBuild_^P^YCFBundleDevelopmentRegion_^P^OCFBundleVersi    on_^P^SBuildMachineOSBuild^DTPlatformName_^P^SCFBundlePackageType_^P^ZCFBundleShortVersionString_^P^ZCFBundleSupportedPlatforms_^P^]CFBundleInfoDictionaryVersion_^P^RCFBundleE    xecutableZDTCompiler_^P^PMinimumOSVersion_^P^RCFBundleIdentifier^UIDeviceFamily_^P^QDTPlatformVersion\DTXcodeBuild_^P^QCFBundleSignature_^P^ODTPlatformBuildYConnectIQT0611[iph    oneos8.1o^P-^@C^@o^@p^@y^@r^@i^@g^@h^@t^@ ^@©^@ ^@2^@0^@1^@5^@ ^@G^@a^@r^@m^@i^@n^@.^@ ^@A^@l^@l^@ ^@r^@i^@g^@h^@t^@s^@ ^@r^@e^@s^@e^@r^@v^@e^@d^@.V12B411RenQ1V14C109Xiphoneos    TBNDLS1.0¡#XiPhoneOSS6.0YConnectIQ_^P"com.apple.compilers.llvm.clang.1_0S8.1_^P^Tcom.garmin.ConnectIQ¡*^P^AW6A2008aT????^@^H^@7^@D^@L^@V^@q^@|^@<98>^@ª^@À^@Ï^@å^A^B^A^_^A?^AT^    A_^Ar^A<87>^A<96>^Aª^A·^AË^AÝ^Aç^Aì^Aø^BU^B\^B_^Ba^Bh^Bq^Bv^Bz^B|^B<85>^B<89>^B<93>^B¸^B¼^BÓ^BÕ^B×^Bß^@^@^@^@^@^@^B^A^@^@^@^@^@^@^@-^@^@^@^@^@^@^@^@^@^@^@^@^@^@^Bä
    I guess it is a normal format but my system seems to be unable to read binary plist ?
    I tried some stuff with plutil
    plutil -lint Info.plist
    Info.plist: Unexpected character b at line 1
    Same for convert
    plutil -convert xml1 Info.plist
    Info.plist: Property List error: Unexpected character b at line 1 / JSON error: JSON text did not start with array or object and option to allow fragments not set.
    I also try to download a fresh version of the connectIQ SDK and no changes.
    Any idea ?
    Thanks

    Step by step, how did you arrive at seeing this agreement?

  • Traversing BOM Model in configurator to search nodes starting with MULT_

    Hi,
    I have arequirement in the project where in I have to traverse through the entire BOM Model and search for the nodes starting with "MULT_".
    Can anyone please let me know the logic for this iteration
    Thanks
    Ramya

    I just received a similar error on a refresh - were you able to resolve this?
    2.     ORA-06512: at "APPS.CZ_UIOA_PVT", line 17185 ORA-06512: at "APPS.CZ_UIOA_PVT", line 17204 ORA-06512: at "APPS.CZ_UIOA_PVT", line 17295 ORA-06512: at "APPS.CZ_UIOA_PVT", line 17459 in Package CZ_UIOA_PVT Procedure refresh_UI
    Thanks--
    Kate

  • Any way to Initialize Java Array to start with 1

    Hi Friends,
    Is there anyway to initialize the java array with starting with 1 instead of normal 0.
    Thanks and Regards.
    JG

    JamesGeorge wrote:
    Hi Jacob,
    Thanks for you time..
    Coding like 1 - n will make everything uneasy, I find in other languages like vbscript,lotusscript it can be done..so just a thought to check in Java too..
    Is there any valid reason for Java/Sun guys to start the arrays,vectors and other collections with 0
    Thanks
    JJShort answer: Java is a C-based language, and C arrays are zero-based so the rest are also zero-based for consistency.
    Long answer: Arrays are implemented as contiguous areas of memory starting from a certain memory address, and loading from a zero-based array implies one less CPU instruction than loading from a one-based array.
    Zero-based:
    - LOAD A, ArrayAddress
    - LOAD B, Index
    - MUL B, ElementSize
    - ADD A, B
    - LOAD (A)
    One-based:
    - LOAD A, ArrayAddress
    - LOAD B, Index
    - ADD B, -1
    - MUL B, ElementSize
    - ADD A, B
    - LOAD (A)

  • How to access a JSON structure key that starts with a number

    I've got an odd issue here.  I'm accessing someone else's JSON structure so I am not able to change it.  The JSON structure keys are named with both characters and numbers like this:
    0
    198456
    product_id
    198456
    1
    Rashaan Houston feat Tony Loreto
    artist
    Rashaan Houston feat Tony Loreto
    So, in other words, there's a key named "0" and a key named "product_id", both of which contain the same key.  Why they did that, I don't know, but they did.
    In one of the instances, the data stored under the text-named key isn't the same as the numerical-named key.  I tried to output the data in the numerical key like this (it's an array of structures):
    #strStompyJSON.data[1].0#
    but I get the following error:
    Invalid CFML construct found on line 41 at column 31.
    ColdFusion was looking at the following text:
    .0
    When I do the following, it works fine:
    #strStompyJSON.data[1].product_id#
    So it looks as though CF doesn't like accessing a variable that starts with a number.  I am able to loop through the structure using a collection loop, and it outputs all of the keys (including the numerical ones) and their values using the following code:
    <cfloop collection="#strStompyJSON.data[1]#" item="key">
    #key#: #strStompyJSON.data[1][key]#<br />
    </cfloop>
    However, that doesn't allow me a way to access specific keys named with a number.  Is there a way that I can specifically access a key that is named with a number?
    thanks!
    Mike

    No problem--glad it worked out.
    As a follow-up to this, I'd encourage you to keep the bracket notation in mind during future development.  It is EXTREMELY useful in a lot of situations.
    For example, if you're building a structure on the fly with dynamic keys, bracket notation is extremely helpful:
         <cfset authors = structnew()>
         <cfloop list="authorlist" index="name">
              <cfset authors[name] = getbooklist(name)>
         </cfloop>
    Also, bracket notation is really nice when creating json from ColdFusion structures.  Consider this:
         <cfset author = structnew()>
         <cfset author.name = "Neil Gaiman">
         <cfset author.genre = "Fantasy">
         <cfset author.awesome = true>
         <cfset authorjson = serializejson(author)>
    By default, the serialized json produced will have all UPPER CASE keys.  Not a big deal in most cases, but if you're returning the json to something (like a JS library) that is expecting keys in a certain case, it can be a problem.  Fortunately, bracket notation allows you to specify exactly what case you want the structure's keys to be in:
         <cfset author = structnew()>
         <cfset author['name'] = "Neil Gaiman">
         <cfset author['Genre'] = "Fantasy">
         <cfset author['AWESOME'] = true>
         <cfset authorjson = serializejson(author)>

  • Error: response does not start with HTTP

    hi,
    i am using a MIDP class to send a string to a java servlet which then returns a .gif image. the string is being successfully to the servlet, but an exception is being thrown when the image is being sent back.
    java.io.IOException: response does not start with HTTP it starts with: GIF89aï4
    at com.sun.midp.io.j2me.http.Protocol.readResponseMessage(Protocol.java:2166)
    at com.sun.midp.io.j2me.http.Protocol.finishRequestGetResponseHeader(Protocol.java:1934)
    at com.sun.midp.io.j2me.http.Protocol.sendRequest(Protocol.java:1598)
    at com.sun.midp.io.j2me.http.Protocol.sendRequest(Protocol.java:1517)
    at com.sun.midp.io.j2me.http.Protocol.openInputStream(Protocol.java:484)
    my code is as follows in the midp class :
    HttpConnection c = null;
    InputStream is = null;
    StringBuffer sb = new StringBuffer();
    String url="http://localhost:8090/ProjectServer/createMap";
    url=url+"?Source="+src+"&Destination="+dest;
    try {
    c = (HttpConnection)Connector.open(url,Connector.READ_WRITE, true);
    c.setRequestMethod(HttpConnection.GET); //default
    //is = c.openDataInputStream();
    is = new DataInputStream(c.openInputStream()); //openInputStream(); // transition to connected!
    Image im=null;
    try
    ByteArrayOutputStream bStrm = new ByteArrayOutputStream();
    int ch;
    while ((ch = is.read()) != -1)
    bStrm.write(ch);
    // Place into image array
    byte imageData[] = bStrm.toByteArray();
    // Create the image from the byte array
    im = Image.createImage(imageData, 0, imageData.length);
    finally
    // Clean up
    if (is != null)
    is.close();
    the code in the servlet is as follows :_
    ServletContext sc = getServletContext();
    // Get the MIME type of the image
    String mimeType = sc.getMimeType("route.gif");
    if (mimeType == null) {
    sc.log("Could not get MIME type ");
    response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    return;
    // Set content type
    response.setContentType(mimeType);
    // Set content size
    response.setContentLength((int)file.length());
    // Open the file and output streams
    FileInputStream in = new FileInputStream(file);
    OutputStream outstream = response.getOutputStream();
    // Copy the contents of the file to the output stream
    byte[] buf = new byte[1024];
    int count = 0;
    while ((count = in.read(buf)) >= 0) {
    outstream.write(buf, 0, count);
    in.close();
    outstream.close();
    il be immensely grateful if some1 cud tell me whre i am gng wrong.
    thnx,
    nev

    Hi, I�m trying to do the same as above, get MP3 from a Shoutcast server.
    I got the same fault ("response does not start with HTTP it starts with: ICY") when I tried to open an HttpConnection as bellow:
    ============================================
    HttpConnection conn = (HttpConnection) Connector.open("http://64.236.34.196/stream/1074");
    Then I tried to open a socket connection as bellow:
    ======================================
    SocketConnection conn = (SocketConnection) Connector.open("socket://64.236.34.196:80");
    String get = "GET /stream/1074 HTTP/1.1";
    DataOutputStream os = conn.openDataOutputStream();
    os.writeUTF(get);
    InputStream is = conn.openInputStream();
    But then I got the following error:
    =========================
    java.lang.SecurityException: Target port denied to untrusted applications
    Could someone help me to find out what is going on?
    Thanks a lot!

  • How to replace a substring that starts with and end with another substring?

    Hi,
    I am trying to parse data from HTML tables. First I want to remove all useless tags like <font>. Now, how can I remove substrings like-
    *<font face="Verdana, Arial, Helvetica, sans-serif" size="1">My_Data_to_parse</font>*
    I was searching for any method which replaces a substring what starts with a substring (in this case "<font") and ends with another substring (in this case ">") . Is there any method like that? Or any better solution?
    Another situation like the following-
    *<td align="left" height="30" width="100%">*
    In this case I want to remove all the height, align , width etc and make it as simple as "<td>". How can I do that?
    Finally, all I am trying to do just to parse data from the tables in a html file. Is there any parser API or library to help me do that? Or to bring the data down to array from the tables based on table structure? Please suggest me.
    Thanks in advance.

    probably the best place to start is to search for the "<keyword" of all of the html keywords, then search for the location of the next ">" - this will indicate the end of the <keyword> opening tag.

  • RSA decryption Error: Data must start with zero

    Because of some reasons, I tried to use RSA as a block cipher to encrypt/decrypt a large file. When I debug my program, there some errors are shown as below:
    javax.crypto.BadPaddingException: Data must start with zero
         at sun.security.rsa.RSAPadding.unpadV15(Unknown Source)
         at sun.security.rsa.RSAPadding.unpad(Unknown Source)
         at com.sun.crypto.provider.RSACipher.doFinal(RSACipher.java:356)
         at com.sun.crypto.provider.RSACipher.engineDoFinal(RSACipher.java:394)
         at javax.crypto.Cipher.doFinal(Cipher.java:2299)
         at RSA.RRSSA.main(RRSSA.java:114)
    From breakpoint, I think the problem is the decrypt operation, and Cipher.doFinal() can not be operated correctly.
    I searched this problem from google, many people met the same problem with me, but most of them didn't got an answer.
    The source code is :
    Key generation:
    package RSA;
    import java.io.FileOutputStream;
    import java.io.ObjectOutputStream;
    import java.security.KeyPair;
    import java.security.KeyPairGenerator;
    import java.security.PrivateKey;
    import java.security.PublicKey;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    public class GenKey {
          * @param args
                     * @author tang
         public static void main(String[] args) {
              // TODO Auto-generated method stub
                 try {
                      KeyPairGenerator KPG = KeyPairGenerator.getInstance("RSA");
                      KPG.initialize(1024);
                      KeyPair KP=KPG.genKeyPair();
                      PublicKey pbKey=KP.getPublic();
                      PrivateKey prKey=KP.getPrivate();
                      //byte[] publickey = decryptBASE64(pbKey);
                      //save public key
                      FileOutputStream out=new FileOutputStream("RSAPublic.dat");
                      ObjectOutputStream fileOut=new ObjectOutputStream(out);
                      fileOut.writeObject(pbKey);
                      //save private key
                          FileOutputStream outPrivate=new FileOutputStream("RSAPrivate.dat");
                      ObjectOutputStream privateOut=new ObjectOutputStream(outPrivate);
                                 privateOut.writeObject(prKey)
         }Encrypte / Decrypt
    package RSA;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.ObjectInputStream;
    import java.security.Key;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.crypto.Cipher;
    //import sun.misc.BASE64Decoder;
    //import sun.misc.BASE64Encoder;
    public class RRSSA {
          * @param args
         public static void main(String[] argv) {
              // TODO Auto-generated method stub
                //File used to encrypt/decrypt
                 String dataFileName = argv[0];
                 //encrypt/decrypt: operation mode
                 String opMode = argv[1];
                 String keyFileName = null;
                 //Key file
                 if (opMode.equalsIgnoreCase("encrypt")) {
                 keyFileName = "RSAPublic.dat";
                 } else {
                 keyFileName = "RSAPrivate.dat";
                 try {
                 FileInputStream keyFIS = new FileInputStream(keyFileName);
                 ObjectInputStream OIS = new ObjectInputStream(keyFIS);
                 Key key = (Key) OIS.readObject();
                 Cipher cp = Cipher.getInstance("RSA/ECB/PKCS1Padding");//
                 if (opMode.equalsIgnoreCase("encrypt")) {
                 cp.init(Cipher.ENCRYPT_MODE, key);
                 } else if (opMode.equalsIgnoreCase("decrypt")) {
                 cp.init(Cipher.DECRYPT_MODE, key);
                 } else {
                 return;
                 FileInputStream dataFIS = new FileInputStream(dataFileName);
                 int size = dataFIS.available();
                 byte[] encryptByte = new byte[size];
                 dataFIS.read(encryptByte);
                 if (opMode.equalsIgnoreCase("encrypt")) {
                 FileOutputStream FOS = new FileOutputStream("cipher.txt");
                 //RSA Block size
                 //int blockSize = cp.getBlockSize();
                 int blockSize = 64 ;
                 int outputBlockSize = cp.getOutputSize(encryptByte.length);
                 /*if (blockSize == 0)
                      System.out.println("BLOCK SIZE ERROR!");       
                 }else
                 int leavedSize = encryptByte.length % blockSize;
                 int blocksNum = leavedSize == 0 ? encryptByte.length / blockSize
                 : encryptByte.length / blockSize + 1;
                 byte[] cipherData = new byte[outputBlockSize*blocksNum];
                 //encrypt each block
                 for (int i = 0; i < blocksNum; i++) {
                 if ((encryptByte.length - i * blockSize) > blockSize) {
                 cp.doFinal(encryptByte, i * blockSize, blockSize, cipherData, i * outputBlockSize);
                 } else {
                 cp.doFinal(encryptByte, i * blockSize, encryptByte.length - i * blockSize, cipherData, i * outputBlockSize);
                 //byte[] cipherData = cp.doFinal(encryptByte);
                 //BASE64Encoder encoder = new BASE64Encoder();
                 //String encryptedData = encoder.encode(cipherData);
                 //cipherData = encryptedData.getBytes();
                 FOS.write(cipherData);
                 FOS.close();
                 } else {
                FileOutputStream FOS = new FileOutputStream("plaintext.txt");
                 //int blockSize = cp.getBlockSize();
                 int blockSize = 64;
                 //int j = 0;
                 //BASE64Decoder decoder = new BASE64Decoder();
                 //String encryptedData = convert(encryptByte);
                 //encryptByte = decoder.decodeBuffer(encryptedData);
                 int outputBlockSize = cp.getOutputSize(encryptByte.length);
                 int leavedSize = encryptByte.length % blockSize;
                 int blocksNum = leavedSize == 0 ? encryptByte.length / blockSize
                           : encryptByte.length / blockSize + 1;
                 byte[] plaintextData = new byte[outputBlockSize*blocksNum];
                 for (int j = 0; j < blocksNum; j++) {
                 if ((encryptByte.length - j * blockSize) > blockSize) {
                      cp.doFinal(encryptByte, j * blockSize, blockSize, plaintextData, j * outputBlockSize);
                      } else {
                      cp.doFinal(encryptByte, j * blockSize, encryptByte.length - j * blockSize, plaintextData, j * outputBlockSize);
                 FOS.write(plaintextData);
                 //FOS.write(cp.doFinal(encryptByte));
                 FOS.close();
    }Edited by: sabre150 on Aug 3, 2012 6:43 AM
    Moderator action : added [ code] tags so as to make the code readable. Please do this yourself in the future.
    Edited by: 949003 on 2012-8-3 上午5:31

    1) Why are you not closing the streams when writing the keys to the file?
    2) Each block of RSA encrypted data has size equal to the key modulus (in bytes). This means that for a key size of 1024 bits you need to read 128 bytes and not 64 bytes at a time when decrypting ( this is probably the cause of your 'Data must start with zero exception'). Since the input block size depends on the key modulus you cannot hard code this. Note - PKCS1 padding has at least 11 bytes of padding so on encrypting one can process a maximum of the key modulus in bytes less 11. Currently you have hard coded the encryption block at 64 bytes which is OK for your 1024 bits keys but will fail for keys of modulus less than about 936 bits.
    3) int size = dataFIS.available(); is not a reliable way to get the size of an input stream. If you check the Javadoc for InputStream.available() you will see that it returns the number of bytes that can be read without blocking and not the stream size.
    4) InputStream.read(byte[]) does not guarantee to read all the bytes and returns the number of bytes actually read. This means that your code to read the content of the file into an array may fail. Again check the Javadoc. To be safe you should used DataInputStream.readFully() to read a block of bytes.
    5) Reading the whole of the cleartext or ciphertext file into memory does not scale and with very large files you will run out of memory. There is no need to do this since you can use a "read a block, write the transformed block" approach.
    RSA is a very very very slow algorithm and it is not normal to encrypt the whole of a file using it. The standard approach is to perform the encryption of the file content using a symmetric algorithm such as AES using a random session key and use RSA to encrypt the session key. One then writes to the ciphertext file the RSA encrypted session key followed by the symmetric encrypted data. To make it more secure one should actually follow the extended procedure outlined in section 13.6 of Practical Cryptography by Ferguson and Schneier.

  • Recursive Hierarchical Query with CONNECT BY/START WITH

    I want to traverse a tree which has is not hierarchical in linear sense. You know, like :
    A
    B
    C
    D
    E
    C
    F
    D
    E
    C
    You see that D, Eand C are repeated and C is under E as well as under B. I tried using CONNECT BY and START WITH but I get tripliate occurances of C under B, and 2 occurances of DEC under A and under F. Clearly this is not correct. I believe SQL3 has special way of handling with such recursive trees. How does O9i handle these constructs? Please help.

    CREATE OR REPLACE PACKAGE hierarchy
    IS
      TYPE branchtable_type IS TABLE OF VARCHAR2 (4000)
      INDEX BY BINARY_INTEGER;
      branchtable branchtable_type;
      FUNCTION branch
        (v_level     IN NUMBER,
         v_value     IN VARCHAR2,
         v_delimeter IN VARCHAR2 DEFAULT CHR (0))
        RETURN VARCHAR2;
      PRAGMA RESTRICT_REFERENCES (branch, WNDS);
    END hierarchy;
    CREATE OR REPLACE PACKAGE BODY hierarchy
    IS
      returnvalue VARCHAR2 (4000);
      FUNCTION branch
        (v_level     IN NUMBER,
         v_value     IN VARCHAR2,
         v_delimeter IN VARCHAR2 DEFAULT CHR (0))
        RETURN VARCHAR2
      IS
      BEGIN
        branchtable (v_level) := v_value;
        returnvalue := v_value;
        FOR i IN REVERSE 1 .. v_level - 1
        LOOP
          returnvalue := branchtable (i)
          || v_delimeter
          || returnvalue;
        END LOOP;
        RETURN returnvalue;
      END branch;
    END hierarchy;
    SELECT   id, parent_id, print_order, lvl
    FROM     (SELECT     id, parent_id, print_order, LEVEL lvl,
                         hierarchy.branch (LEVEL, print_order) branch
              FROM       test_table
              START WITH parent_id IS NULL
              CONNECT BY PRIOR id = parent_id)
    ORDER BY branch
            ID  PARENT_ID PRINT_ORDER        LVL
             1                      1          1
             6          1           1          2
             5          1           2          2
             2          1           3          2
             4          2           1          3
             3          2           2          3
    6 rows selected.

  • Applescript/Terminal: Get PIDs of processes starting with...

    Hello,
    Is there a way to return all the PIDs of processes starting with "Myapp_action_download" in a neat array in Applescript, so I can kill them using Terminal?
    Something like this:
    set openapps to {}
    set openapps to (do shell script "the shell script which I don't know")
    --This script gets all the PIDs of processes starting with "Myapp_action_download", and returns them in a neat array
    set appcount to 0
    repeat (count of items of openapps)
    set appcount to appcount + 1
    do shell script ("kill -9 " & (item appcount of openapps) as text)
    end repeat
    Kind regards,
    Isaiah

    try
    tell application "System Events"
              set procesList to the name of every process whose name contains "Myapp_action_download"
    end tell
    tell application "System Events"
              set {procesList, pidList} to the {name, unix id} of (every process whose name contains "Myapp_action_download")
    end tell
    You'll have two lists one with the process name and one with the pid's. They will be in a one-to-one relationship. That is the first entry in the processList will correspond to the first entry in the pidList.
    However if the apps aren't hung or in a weird state you should be able to just tell the process to quit without resorting to killing them.
    Message was edited by: Frank Caggiano

  • Vectors/Arrays Mixed with Classes

    Here's my problem
    I'm have a for loop which collects integers, (i). What'd I'd like to do is make a list of all the numbers "i" comes up as, and then record how many times "i" comes up as a certain number.
    For example,
    say the for loop is retrieving the number 1,5,7,3,1,1,6,3,4,5,7
    I'd like to create some type of data structure that will do this:
    Numbers/Instances
    1/3
    3/2
    4/1
    5/2
    6/1
    7/2
    I do NOT need it to say that there are no instances of 2, for example, but if it did I could live with that.
    I thought of creating a Class containing a variable for instances, and then making an array, where the index value would be the number and the variable would be the instances... so... say:
    The class name is Numbers, with public static int times:
    Numbers [] myNum=new Numbers[10];
    The problem with an array is that you can't resize it. I also have no guarantee that the numbers will stay below any certain number. While I could simply define myNum as having a million slots to be sure, I don't think its the best way.
    On the other hand, I can't figure out how to create a vector from a class, as you can't simply:
    Vector Numbers myBum=new Vector();
    I figured vectors would work well as their size is extremely flexible, however if I can't somehow get it to keep track of instances, I'm not working well.
    I was thinking of using hash tables, but I don't completely understand them... while I could somehow tell it to treat each collision as an instance, and add them, wouldn't some hash keys be shared among different numbers (ie perhaps 7 and 43 share the same hash key?) Like I said, I don't completely understand them, so I'm not sure if I'm doing something wrong. I used a hash table to sort strings once and it threw a lot of completely different words in the same part of the has table.
    Any help you can offer would be extremely appreciated. This is a huge mental block thing more than anything, I think. I'm sure there's a practical way to do this in Java.
    Regards,
    Alessandro

    Whenever an Object in Java is created, its original type is remembered. Thus,
    Object a = new Vector();
    Vector my_vector = (Vector)(a);is a valid cast, since "a" was a Vector to start with. Therefore, supposing you have a mutable number-counting object NumberCount, you could simply do the following:
    NumberCount count = new NumberCount(my_number);
    Vector count_vector = new Vector();
    count_vector.add(count);
    NumberCount inc_count = (NumberCount)(count_vector.get(index));
    inc_count.increment();For this project, I would personally recommend a Hashtable. A Hashtable is a type of Map; a Map contains a set of keys, each of which is mapped to a value. Keys are guaranteed to be unique. The only problem, however, is that putting a value into a Hashtable with a key that already exists in the Hashtable destroys the Hashtable's record of the old value.
    Thus, you could have...
    Hashtable table = new Hashtable();
    table.put(new Integer(1),count_value);
    table.get(new Integer(1),count_value.increment());Be careful with this approach; creating new Integer objects like this can be very costly on the garbage collector and will slow your program down if you do it too intensively. But that's another issue. ;)

  • If I copy the "lcds" folder, Tomcat starts with socket errors

    In the documentation it is said that when you create a new server-side application, you can start by copying the 'webapps/lcds' folder. I did that but then, Tomcat starts with some socket errors:
    [LCDS]SocketServer 'my-rtmp-SocketServer' failed to pre-validate desired socket settings for BindSocketAddress: 0.0.0.0:2038
    java.net.SocketException: Unrecognized Windows Sockets error: 0: JVM_Bind
    [LCDS]SocketServer 'my-rtmp-SocketServer' failed to start.
    flex.messaging.LocalizedException: SocketServer 'my-rtmp-SocketServer' cannot bind to accept client connections on port '2038' because another process has already bound the port. Please ensure that multiple endpoints across all applications  are not configured to use this same port.
    Am I doing something wrong?
    Thanks,
    Borek

    What is happening is that you are getting a port conflict for the socket-based NIO and RTMP endpoints used in the channel definitions in the services-config.xml file of your new web app. The issue is that you have endpoints bound to the same port  in the LCDS web and in your new web app.
    You can deal with this one of two ways:
    Option 1: In that services-config.xml file, search on "RTMP" and "NIO" to find the channel definitions and change the port numbers to something slightly different than the ones used in the LCDS web app.
    Options 2: Move the LCDS web app out of the picture so it doesn't get loaded, and just use a template for future web apps. If you aren't using it for any of your development, there is really no reason you have to load it.
    I'll add a note about this to the documentation that talks about using the LCDS web app as a template.

  • How do I stop iTunes from starting with Windows?

    Hi there.
    After installing iTunes 7, it launches with Windows despite there being no registry entries or Startup folder entries. I also can't find any preference settings in iTunes to change this. I don't want iTunes starting with Windows as it's a CPU hot and system drag as it is without it slowing down my startup.
    What's even more odd I find is that, if for whatever reason iTunes does NOT start with Windows, I don't have an Internet connection. It's strange but the connection between the two is absolute. If I reboot and iTunes starts with Windows, I have my Internet back.
    Any suggestions? I can't find anything through searches. I've also checked for viruses, spyware, backdoors, etc.
    Thanks.
    Custom   Windows XP  

    It turns out it was the Yahoo iTunes plugin.

  • Tried to reinstall OSX Mountain Lion 10.8.4 and every time i start with the installation i get a requested time out message, had to shut down my MacBook Pro retina. Now when i start up it automatically start internet recovery

    tried to reinstall OSX Mountain Lion 10.8.4 and every time i start with the installation i get a requested time out message, had to shut down my MacBook Pro retina. Now when i start up it automatically start internet recovery for two ouers. After the internet recovery the same problem with reinstalling OSX message

    Gave up on the GUI.  This script derived from http://blog.netnerds.net/2012/07/os-x-how-to-setup-nat-on-lion-and-mountain-lion / seems to work for me:
    gwdev=en0 # This is my WiFi connection (has Internet connection)
    targetdev=en1 # This is the USB to Ethernet adapter (to give Internet connection)
    /sbin/ifconfig $targetdev down
    /sbin/ifconfig bridge0 create
    /sbin/ifconfig bridge0 up
    /sbin/ifconfig bridge0 addm $gwdev
    /sbin/ifconfig bridge0 $HOST_ADDR
    /sbin/route add default -interface bridge0 -ifscope bridge0 -cloning
    /usr/sbin/sysctl -w net.inet.ip.forwarding=1
    /sbin/ipfw add 100 divert natd ip from any to any via $gwdev
    /usr/sbin/natd -interface $gwdev -use_sockets -same_ports -unregistered_only -dynamic -clamp_mss -enable_natportmap -natportmap_interface $targetdev

Maybe you are looking for

  • Changing name of directory created after source file is extracted

    This seems like it should not be a big problem, but I can't figure out how to fix it. I'm writing a PKGBUILD for a program called JAGS (http://calvin.iarc.fr/~martyn/software/jags/). When I use "pkgname = JAGS", the PKGBUILD works perfectly for my pu

  • Anyone experience with Oracle Release Management?

    Hi, I don't know in which forum to post this, but Order Management seems to be most appropriate. I am looking for someone with experience in Oracle Release Management. We are an Automotive company and a couple of our customers use EDI and we have man

  • Quicktime Pro - Slow conversion

    I have a Macbook 2.0ghz Core Duo/2GB 667mhz Ram/160GB HDD. Whenever Im converting videos on Quicktime Pro, the process is slow, as everyone already knows. My question is, will getting a Mac Pro with Quad or Octo 2.8 ghz and Possibly more than 2gb of

  • Iphoto 9.2.3 - updated then lost 3/4 of the images!

    I am using Mac OSX 10.7.3 and iphoto 9.2.3. Having recently updated my desktop, I was using iphoto when i found under 'events' that 3/4 of the event folders where shown as black suares i.e no image on the event. The events still have the titles and w

  • Wrong value help in "create new relationship"

    Hello, for contact persons we need the possibility to create an Z-Relationship to an employee. I created the Z-relationship-type and it works if i know the correct employee number. But the searchhelp is not correct. Instead of the search for employee