How to determine the maximum prefix of two CharSequences efficiently?

I have the following problem. I need a unicode friendly mechanism for determining the maximum prefix of 2 CharacterSequences. I've come up with the following code which appears to do the job, but which requires up to ([number of codepoints in smaller sequence] * 2) + 1 memory allocations. These memory allocations are rather irksome since I plan on calling this method extremely many times. The code I came up with looks like:
private static int getLengthOfMaxCommonPrefix(CharSequence str1, CharSequence str2, Collator collator) {
    if ((str1 == null) || (str2 == null)) { return 0; }
    if (Character.codePointCount(str1, 0, str1.length()) > Character.codePointCount(str2, 0, str2.length())) {
      CharSequence tmp = str1;
      str1 = str2;
      str2 = tmp;
    // @todo get rid of memory allocation
    char[] charArray = new char[4];
    int i = 0;
    for (int size = Character.codePointCount(str1, 0, str1.length()); i < size; i++) {
      Character.toChars(Character.codePointAt(str1, i), charArray, 0);
      Character.toChars(Character.codePointAt(str2, i), charArray, 2);
       // @todo get rid of memory allocation
      String char1Str = new String(charArray, 0, 2);
      // @todo get rid of memory allocation
      String char2Str = new String(charArray, 2, 2);
      if (collator.compare(char1Str, char2Str) != 0) {
        return i;
    return i;
  }Am I overlooking an API that would allow me have this same functionality without memory allocations? If not, would it be reasonable to request that the Java Collator API be updated to have:
Collator.compare(int codepoint1, int codepoint2)which would eliminate the need for these memory allocations. The only reason I would suggest this change is that more than a few pieces of my other code involving unicode has the same problem. Also, when looking over the API it seems that
static Character.toString(char c)exists, but the following method doesn't:
static Character.toString(int codepoint)which would at least minimize some of the ugliness in the above code and be in keeping with the other APIs under Character.
Edited by: APBrusseau on Feb 10, 2008 11:23 PM
Edited by: APBrusseau on Feb 10, 2008 11:24 PM
Edited by: APBrusseau on Feb 10, 2008 11:29 PM
Edited by: APBrusseau on Feb 10, 2008 11:45 PM
Edited by: APBrusseau on Feb 10, 2008 11:46 PM
Edited by: APBrusseau on Feb 10, 2008 11:48 PM

But still, surely just walking character by character through the strings and comparing them (using your collator) will do?
    char[] c1 = new char[1];
    char[] c2 = new char[1];
    // swap longest/shortest string, etc.
    // for each char {
        c1[0] = cs1.charAt(n);
        c2[0] = cs2.charAt(n);
        s1 = new String(c1);
        s2 = new String(c2);
        // use collator to compare
    // }The only thing I don't know is whether there are collators which look at sequences of characters. For example, I think in Unicode, you can have an 'a' followed by a 'add an accent to the previous character' character, which would obviously impact on the collation order.
In which case, something like
    // for n = 1 .. length of shortest {
        int result = collator.compare(cs1.subSequence(0, n).toString(), cs2.subSequence(0, n).toString());
        if (result != 0) {
            return result;
    // equal to length of shortest string. Make decision based on length.This might be efficient, or not, depending on the implementation of CharSequence. String, for example, has a very efficient subSequence() method.

Similar Messages

  • How to determine the maximum allowable length of a filename for Window ?

    Hi all,
    Could I know how to determine the allowable file length (the length of the absolute path) for a file in Window environment?
    Due to some reason, I generated a zip file with a very long filename ( > 170) and put in a folder(the length of the folder path around 90). The length of the absolute path is around 260.
    I used FileOutputStream with the ZipOutputStream to write out the zip file. Everything is working fine while i generating the zip file.
    However, while i try to extract some files from the zip file i just created, i encountered the error
    java.util.zip.ZipException The filename is too long.
    I am using the class ZipFile to extract the files from the zip file like the following
    String absPath = "A very long filepath which exceed 260";
    ZipFile zipF = new ZipFile(absPath);  //<-- here is the root causeIs it possible to pre-determine the maximum allowable filepath length prior i generate the zip file ? This is weird since i got no error while i created the zip file, but have problem in extracting the zip file ......
    Thanks

    Assuming you could determine the max, what would you do about it? I'd say you should just assume it will be successful, but accommodate (handle) the possible exception gracefully. Either way you're going to have to handle it as an "exception", whether you "catch" an actual "Exception" object and deal with that, or manually deal with the length exceeding the max.

  • How to determine the maximum size of JFrame?

    I am using JDK1.2 to develop an application. I have
    a problem to handle the maximum size of of JFrame.
    If the user clicks the maximum icon or double-clicks
    the title bar from the JFrame, the JFrame becomes
    maximum. How can I determine the state of maximization? I need to bring different views if the
    JFrame is maximum or minimum. I knew JDK1.4 can
    handle this problem. Or using JNI, either. Does
    anyone know other ways to handle this?
    Thanks,
    Peter

    So that you won't have to wait forever:
    Sorry, pal, the only way is JNI. I researched this earlier for 1.2, but can't find it right now in the database. They finally added it to 1.4.
    Good luck.

  • How to determine the maximum temperature in a consecutive of 2 minutes?

    I am doing the following application:
    1) Temperature signal is read in every 1 second, define in a while loop;
    2) I want to make sure that in a consecutive of 2 minutes, temperature value is always lower than a value, say 10 degree C;
    3) If it can meet the criterion, returns true, otherwise continue monitoring until it is true.
    A possible way it to define an 1D array with 120 elements, but I would like to know if there is a more elegant way? I cannot put the array in a subVI, as it is destroyed once subVI is left. LabVIEW system provides "RMS" calculation function (everything is in a sub VI) and I do not the function used in that VI.
    Solved!
    Go to Solution.

    Ah!! so thats what you meant, ok.
    You can easily implement this as a subvi:
    This is what the subvi would look like. You would use a while loop that only iterates once with an un-initialised shift register. This will then store the last value in its shift register.
    This is how it would look on your main vi:
    In this version you do not need to wire the time limit, its default value is 120. If you ever want to change this though you can wire in a new value.
    Rgs,
    Lucither
    Message Edited by Lucither on 05-06-2010 05:04 AM
    "Everything should be made as simple as possible but no simpler"
    Attachments:
    get if temp steady for 2 mins.vi ‏26 KB
    Temp comparison and increment demo.vi ‏9 KB

  • How to determine the type of the jobject... similar to instanceof

    hi,
    I would like to know how to determine the jobject reference of an instance is of which class.
    this is something similar to instanceof we use in java.
    is there any thing like 'instanceof' in JNI. if there how to use it?
    i got this as objective question for which answers were(i do not remember exactly)
    1.instanceof
    2.assignedto
    i could nt het much help in googling.
    thanks in advance

    Hi
    The JNI provides a native version to the java instanceof operator, this function takes two arguments
    an object refrence and a class refrence and reports JNI_TRUE.
    jclass myclass = env->FindClass("your class name");
    if(env->IsInstanceOf(obj,myclass) == JNI_TRUE)
    // obj is of type myclass
    }Regards
    pradish

  • How to determine the solution's ID in absl?

    Hello Community,
    I have a simple question yet I fear there is no simple answer (possibly no answer at all).
    The question is:
    Does any body know ways how to determine the ID (e.g. Y123ABCDY_) of the solution the code is running in?
    My use case is the following:
    We have a solution template which will be deployed in different customer tenant.
    Thus, each deployment will have a different solution ID.
    Now, somewhere in code, we generat PDFs using the OutputManagementUtilities.GetPDF reuse library.
    This method requires the form template code of the pdf to be generated as a parameter.
    However, this PDF form template code is composed of the solution ID and a fixed suffix.
    Thus, currently I need to modify the absl code in each customer installation to manually modify the form template code prefix to the solutions solution ID.
    Therefore I'd like to construct the form template code in absl but for this I need a way to determine the solution's ID.
    Any ideas?
    Best regards,
    Ludger

    Hi Fernando.
    After reading your post I initially thought "what is the ObjectTypeCode" supposed to do any good to determine the solution ID"?
    Using the Object Type code of a custom bo is indeed a way to solve this problem.
    With a little additional code I can extract the relevant solution ID part from there.
    Thanks for the hint, that was really useful.
    Best reegards,
    Ludger

  • How to Determine the Oracle Identity Manager Server Version?

    Friends,
    I have two questions about the Identity Manager...?
    How to Determine the OIM 11g Server Version?
    How to Determine the OIM 9 Server Version?
    Thanks

    The bundle patches are found by build number. If you go to metalink and check the bundle patches, there is a build number associated with them, usually also contained in the xellerate/config/Version.props file. This is written to the XSD table during patching. Once installed, there is no identifier that says "BPXXX applied".
    -Kevin

  • How to determine the second decimal of currency is equal to 0.

    Hi guys,
    My problem is how to determine the second decimal of currency is equal to 0.
    i.e: 130.23 the second decimal is 3.
    Thx in advance.
    Points will be rewarded.

    Hi Vincent,
    if you want to check the internal currency value, you can not know from the field contents what is the second decimal. Because ABAP currency fields (CURR) are connected to currency key CUKY. For USD or EUR you have two decimals, japanese yen have no decimals where as some arabian pound have three decimals. The default are 2 decimals; all excetions can be found in table TCURX.
    If you WRITE the value it is converted correctly according to the connected currency.
    Just multiply the value with 10 to the power of decimals, e.g. USD value * ( 10 ** 2 ). Then do a MOD: second_decimal_of_currency = ( value * ( 10 ** decimals ) mod 10.
    If result is zero, then the second decimal of currency is equal to 0.
    Regards,
    Clemens

  • How to find the maximum no of users logged in Database

    Hi All,
    How to find the maximum number of users logged in database at particular time? I can find currently logged users or umber of sessions running on Database but I wanted to find at what time maximum number of users or sessions connected to the DB? is that possible? if yes please help me. thanks.

    Vijay wrote:
    Hi All,
    How to find the maximum number of users logged in database at particular time? I can find currently logged users or umber of sessions running on Database but I wanted to find at what time maximum number of users or sessions connected to the DB? is that possible? if yes please help me. thanks.
    select * from v$resource_limit;Lists about 20 different resources with current, maximum and limit on usage. Session count is one of them. I don't think there's any (simple, efficient) way to determine the maximum number of different users of sessions, though.
    Regards
    Jonathan Lewis

  • How to determine the ROWNUM in a Master Detail Form

    Hello,
    I am working in a Master Detail Form with Orders and Order Items Information; and I created a process that allows the users to select a Product ID on a tabular form, and the next column is populated automatically with the Product Description.
    To achieve that, I followed some instructions by Denes Kubicek (http://apex.oracle.com/pls/otn/f?p=31517:241), but my case is slightly different:
    <ul>I am using a wizard-created tabular form, instead of a manual tabular form; and </ul>
    <ul>Instead of using another page as a Popup to pass the parameter of the ROWNUM, I am using a plug-in called “Tabular Form Super LOV” which is a modified version of the SkillBuilders’ Super LOV that works on Tabular Forms. </ul>
    The Product ID is returned in the correct row by the plug-in; but in the case of the Product Description, it is always returned into the first row; and my problem is that I don't know how to determine the row where the user clicked to call the plug-in.
    I set up an example in apex.oracle.com in case someone would like to look at it:
    Workspace: ediazjorge
    Username: test
    Password: test
    App Name: Sample App
    App Number: 1550
    BTW, I am using Apex 4.1.1.00.23 and Oracle DB 10.3.2.
    Thanks in advance,
    Erick

    Hello VC,
    Thank you for your time and help.
    Unfortunately, it is still not working properly:
    1. When the Popup LOV opens, the first row of the tabular form is 0, the second row is 1, and so on. How can I assign the values starting with 1 and in the format *0001* ? (I am still a novice on Apex and new to JavaScript :-), sorry about that).
    --2. Also, when I close the Popup LOV, the value of P1_ROWNUM is ‘undefined’ again so I'm not sure if the Product Name column will be populated.--
    3. And finally, you are using the jQuery Selector uPopupLOVIcon, which is an attribute of the Cloudy Theme. In my real application (Apex 4.1.1.00.26), my element looks like: *<img src="/i/lov_16x16.gif" width="16" height="16" alt="Popup Lov" alt="List" style="vertical-align:middle;" align="middle" />*. What do you recommend me to use as a jQuery Selector?
    Again, I really appreciate your help and time. I think you solved the most difficult part.
    Thank you so much,
    Erick
    Update: I just found out that the problem with my comment 2 is because I didn’t delete the previous dynamic action that set the value to P1_ROWNUM.
    Edited by: ediazjorge on Sep 18, 2012 11:20 AM

  • How to get the maximum bandwidth/MaxSpeed/Capacity of a Hyper-V virtual-switch?

    We are trying to monitor Hyper-V environment (Windows 2008 R2 and Windows 2012) using WMI, and have a very specific question Hyper-V virtual-switch.
    We have referred the below mentioned classes and their properties.
    1. Win32_NetworkAdapter (namespace:root\cimv2, property:Speed)
    2. Msvm_InternalEthernetPort (namespace:Root\virtualization\v2, property: Speed and Maxspeed)
    3. Msvm_EthernetSwitchBandwidthData (namespace:Root\virtualization\v2, property:Capacity and Reservation)
    All of the above classes and their properties returns 10000000000 (10 GBps) as MaxSpeed, which is NOT correct (as we know that our network connection is of 1 GBps)
    Here is our question: How to get the maximum bandwidth/MaxSpeed/Capacity of a Hyper-V virtual-switch?

    Until MSFT makes a change to increase the max speed of the virtual switch (and the resulting virtual ports) it will be 10 Gbps.
    It has been this way since the original introduction in 2008.
    What you are looking for is the most limiting segment in the path.  The virtual switch does not assume the properties of the most limiting segment.  Since the physical side could be a team, it could be a single NIC.
    Your management layer must interpret the most limiting segment.
    If you have not already been here:
    http://blogs.msdn.com/b/tvoellm/archive/2009/04/23/monitoring-hyper-v-performance.aspx  Then take a look.
    Brian Ehlert
    http://ITProctology.blogspot.com
    Learn. Apply. Repeat.

  • How to determine the mount point for directory /tmp ?

    Folks,
    Hello. I am installing Oracle 11gR2 RAC using 2 Virtual Machines (rac1 and rac2 whose OS are Oracle Linux 5.6) in VMPlayer and according to the tutorial
    http://appsdbaworkshop.blogspot.com/2011/10/11gr2-rac-on-linux-56-using-vmware.html
    I am installing Grid infrastructure. I am on step 7 of 10 (verify Grid installation enviroment) and get this error:
    "Free Space: Rac2: /tmp"
    Cause: Could not determine mount point for location specified.
    Action: Ensure location specified is available.
    Expected value: n/a
    Actual value: n/a
    I have checked the free space using the command:
    [root@Rac2 /]# df -k /tmp
    Output:
    Filesystem     1k-blocks     used     Available     Use%     Mounted on
    /dev/sda1     30470144     7826952     21070432     28%     /
    As you see above, the free space is enough, but could not determine mount point for /tmp.
    Do any folk understand how to determine the mount point for directory /tmp ?
    Thanks.

    I have just checked "/home/oracle/.bash_profile". But in my computer, there is no "oracle" under /home directory.Is this your first time Linux and Oracle installation? I had a brief look at your referenced link. The reason why you do not find a "oracle" user is because the instructions use "ora11g" instead, which, btw, is not standard. The directories of your installation and your installation source can be somewhat different from known standards and you will have to adjust it to your system.
    My best guess is that you have either missed something in the instructions or you need to ask the author of the blog what is wrong. The chance to find someone here who has experience with these custom instructions is probably unlikely.
    I suggest you try to locate the cluster verification tool, which should be in the bin directory of your grid installation. Alternatively you might want to check the RAC, ASM & Clusterware Installation forum: RAC, ASM & Clusterware Installation

  • How to determine the field size

    I am going to make a multiplatform application that hopefully
    will run on linux and windows 2000.If the os is 2000, then I will use
    vb.net/aspx else I'll use java servlets. I make the connection
    to the web server ( through HTTP) not directly to database server.
    So, the resultset will be stored in the String object. The columns
    will be separated by delimeter. Our problem is how to determine
    the size and type of the fields of mssql,oracle and postgres database
    so that we can include it in the String object.
    Ex.
    String sResultSet=new String();
    ResultSet rs=statement.executeQuery(sSQL);
    while(rs.next()){
    sResultset=sResultSet + rs.getString(field1) + "||" + rs.getString(field2) + "||";
    vertical bars acts as delimeter
    supposedly this is the code:
    sResultset=sResultSet + rs.getString(field1) +"_" + rs.getFieldType() + "_"+
    rs.getFieldSize() + "||" + rs.getString(field2) +"_" + rs.getFieldType() + "_"+
    rs.getFieldSize() + "||";
    supposedly this is the code if rs.getFieldType() and rs.getFieldSize() methods are existing
    Anyone can give me an idea how to get the field type and field size of the database?
    thanks in advance

    Yes, but I dont know how to do it.
    Can you give me an example of using it.
    Thanks in advance

  • How to determine the cost center

    Dear experts:
    Could you give me some suggestions about how to determine the cost center depending on the different
    storage location when we use the t-cdoe MI07
    Thanks in advance.
    Rong

    Hello experts!!!
    how have you resolved this issue???
    I have the same situation, and i dont know how to manage this.
    Thank you very much in advance.
    Best regards,
    M. Cecilia Vacatello.

  • How to determine the length of a curved path in illustrator CS2

    how to determine the length of a curved path in illustrator CS2?

    bornfree,
    The free Patharea/Pathlength Filters from Telegraphics is your friend (the former gives you both area and length, both in different units):
    Telegraphics - Free plugins for Photoshop & Illustrator...and other software

Maybe you are looking for