Java Code Examples for java.util.Vector#firstElement()

The following examples show how to use java.util.Vector#firstElement() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NativeGSSFactory.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private GSSCredElement getCredFromSubject(GSSNameElement name,
                                          boolean initiate)
    throws GSSException {
    Oid mech = cStub.getMech();
    Vector<GSSCredElement> creds = GSSUtil.searchSubject
        (name, mech, initiate, GSSCredElement.class);

    // If Subject is present but no native creds available
    if (creds != null && creds.isEmpty()) {
        if (GSSUtil.useSubjectCredsOnly(caller)) {
            throw new GSSException(GSSException.NO_CRED);
        }
    }

    GSSCredElement result = ((creds == null || creds.isEmpty()) ?
                             null : creds.firstElement());
    // Force permission check before returning the cred to caller
    if (result != null) {
        result.doServicePermCheck();
    }
    return result;
}
 
Example 2
Source File: Krb5MechFactory.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static Krb5CredElement getCredFromSubject(GSSNameSpi name,
                                                  boolean initiate)
    throws GSSException {
    Vector<Krb5CredElement> creds =
        GSSUtil.searchSubject(name, GSS_KRB5_MECH_OID, initiate,
                              (initiate ?
                               Krb5InitCredential.class :
                               Krb5AcceptCredential.class));

    Krb5CredElement result = ((creds == null || creds.isEmpty()) ?
                              null : creds.firstElement());

    // Force permission check before returning the cred to caller
    if (result != null) {
        if (initiate) {
            checkInitCredPermission((Krb5NameElement) result.getName());
        } else {
            checkAcceptCredPermission
                ((Krb5NameElement) result.getName(), name);
        }
    }
    return result;
}
 
Example 3
Source File: BundleImpl.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * @see org.osgi.framework.Bundle#getResource(String name)
 */
public URL getResource(String name) {
  checkUninstalled();
  // NYI, sync BundleGeneration
  if (secure.okResourceAdminPerm(this) && !current().isFragment()) {
    if (getUpdatedState(new BundleImpl [] { this }, false) != INSTALLED) {
      final ClassLoader cl0 = getClassLoader();
      if (cl0 != null) {
        return cl0.getResource(name);
      }
    } else {
      final Vector<URL> uv = secure.getBundleClassPathEntries(current(), name, true);
      if (uv != null) {
        return uv.firstElement();
      }
    }
  }
  return null;
}
 
Example 4
Source File: WinGammaPlatformVC10.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
void writeFiles(Vector<BuildConfig> allConfigs, String projDir) {
   // This code assummes there are no config specific includes.
   startTag("ItemGroup");

   String sourceBase = BuildConfig.getFieldString(null, "SourceBase");

   // Use first config for all global absolute includes.
   BuildConfig baseConfig = allConfigs.firstElement();
   Vector<String> rv = new Vector<String>();

   // Then use first config for all relative includes
   Vector<String> ri = new Vector<String>();
   baseConfig.collectRelevantVectors(ri, "RelativeSrcInclude");
   for (String f : ri) {
      rv.add(sourceBase + Util.sep + f);
   }

   baseConfig.collectRelevantVectors(rv, "AbsoluteSrcInclude");

   handleIncludes(rv, allConfigs);

   endTag();
}
 
Example 5
Source File: HTMLComponent.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Scrolls the HTMLComponent to the specified element
 *
 * @param element The element to scroll to (must be contained in the document)
 * @param animate true to animate the scrolling, false otherwise
 * @throws IllegalArgumentException if the element is not contained in the current document.
 */
public void scrollToElement(HTMLElement element,boolean animate) {
    if (!pageLoading()) {
        if (!document.contains(element)) {
            throw new IllegalArgumentException("The specified element is not contained in the current document.");
        }
        Vector v=element.getUi();
        if ((v!=null) && (v.size()>0)) {
            Component cmp=((Component)v.firstElement());
            if (cmp!=null) {
                Container parent=cmp.getParent();
                int y=cmp.getY();
                while ((parent!=null) && (parent!=this)) {
                    y+=parent.getY();
                    parent=parent.getParent();
                }
                scrollTo(y , animate);
            }
        }
    } else {
        throw new IllegalStateException("Page is still loading");
    }
}
 
Example 6
Source File: Krb5MechFactory.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private static Krb5CredElement getCredFromSubject(GSSNameSpi name,
                                                  boolean initiate)
    throws GSSException {
    Vector<Krb5CredElement> creds =
        GSSUtil.searchSubject(name, GSS_KRB5_MECH_OID, initiate,
                              (initiate ?
                               Krb5InitCredential.class :
                               Krb5AcceptCredential.class));

    Krb5CredElement result = ((creds == null || creds.isEmpty()) ?
                              null : creds.firstElement());

    // Force permission check before returning the cred to caller
    if (result != null) {
        if (initiate) {
            checkInitCredPermission((Krb5NameElement) result.getName());
        } else {
            checkAcceptCredPermission
                ((Krb5NameElement) result.getName(), name);
        }
    }
    return result;
}
 
Example 7
Source File: Krb5MechFactory.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static Krb5CredElement getCredFromSubject(GSSNameSpi name,
                                                  boolean initiate)
    throws GSSException {
    Vector<Krb5CredElement> creds =
        GSSUtil.searchSubject(name, GSS_KRB5_MECH_OID, initiate,
                              (initiate ?
                               Krb5InitCredential.class :
                               Krb5AcceptCredential.class));

    Krb5CredElement result = ((creds == null || creds.isEmpty()) ?
                              null : creds.firstElement());

    // Force permission check before returning the cred to caller
    if (result != null) {
        if (initiate) {
            checkInitCredPermission((Krb5NameElement) result.getName());
        } else {
            checkAcceptCredPermission
                ((Krb5NameElement) result.getName(), name);
        }
    }
    return result;
}
 
Example 8
Source File: NativeGSSFactory.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private GSSCredElement getCredFromSubject(GSSNameElement name,
                                          boolean initiate)
    throws GSSException {
    Oid mech = cStub.getMech();
    Vector<GSSCredElement> creds = GSSUtil.searchSubject
        (name, mech, initiate, GSSCredElement.class);

    // If Subject is present but no native creds available
    if (creds != null && creds.isEmpty()) {
        if (GSSUtil.useSubjectCredsOnly(caller)) {
            throw new GSSException(GSSException.NO_CRED);
        }
    }

    GSSCredElement result = ((creds == null || creds.isEmpty()) ?
                             null : creds.firstElement());
    // Force permission check before returning the cred to caller
    if (result != null) {
        result.doServicePermCheck();
    }
    return result;
}
 
Example 9
Source File: RBTableBuilder.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
private final int getCharOrder(int ch) {
    int order = mapping.elementAt(ch);

    if (order >= RBCollationTables.CONTRACTCHARINDEX) {
        Vector<EntryPair> groupList = getContractValuesImpl(order - RBCollationTables.CONTRACTCHARINDEX);
        EntryPair pair = groupList.firstElement();
        order = pair.value;
    }
    return order;
}
 
Example 10
Source File: Dominator.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * this returns the vertex that is the dominator
 */
public Vertex getDominator(Vertex v) {
	Vector pathSet = this.allPathsContaining(v);
	if (pathSet.isEmpty()) {
		return v;
	}
	Vector path = (Vector) pathSet.firstElement();
	return this.allPathsContain(pathSet, v, path);
}
 
Example 11
Source File: WinGammaPlatformVC7.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
void writeFiles(Vector<BuildConfig> allConfigs) {

      // This code assummes there are no config specific includes.
      startTag("Files");
      String sourceBase = BuildConfig.getFieldString(null, "SourceBase");

      // Use first config for all global absolute includes.
      BuildConfig baseConfig = allConfigs.firstElement();
      Vector<String> rv = new Vector<String>();

      // Then use first config for all relative includes
      Vector<String> ri = new Vector<String>();
      baseConfig.collectRelevantVectors(ri, "RelativeSrcInclude");
      for (String f : ri) {
         rv.add(sourceBase + Util.sep + f);
      }

      baseConfig.collectRelevantVectors(rv, "AbsoluteSrcInclude");

      handleIncludes(rv, allConfigs);

      startTag("Filter", new String[] { "Name", "Resource Files", "Filter",
      "ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe" });
      endTag();

      endTag();
   }
 
Example 12
Source File: RBTableBuilder.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private final int getCharOrder(int ch) {
    int order = mapping.elementAt(ch);

    if (order >= RBCollationTables.CONTRACTCHARINDEX) {
        Vector<EntryPair> groupList = getContractValuesImpl(order - RBCollationTables.CONTRACTCHARINDEX);
        EntryPair pair = groupList.firstElement();
        order = pair.value;
    }
    return order;
}
 
Example 13
Source File: CollationElementIterator.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Get the ordering priority of the next contracting character in the
 * string.
 * @param ch the starting character of a contracting character token
 * @return the next contracting character's ordering.  Returns NULLORDER
 * if the end of string is reached.
 */
private int nextContractChar(int ch)
{
    // First get the ordering of this single character,
    // which is always the first element in the list
    Vector<EntryPair> list = ordering.getContractValues(ch);
    EntryPair pair = list.firstElement();
    int order = pair.value;

    // find out the length of the longest contracting character sequence in the list.
    // There's logic in the builder code to make sure the longest sequence is always
    // the last.
    pair = list.lastElement();
    int maxLength = pair.entryName.length();

    // (the Normalizer is cloned here so that the seeking we do in the next loop
    // won't affect our real position in the text)
    NormalizerBase tempText = (NormalizerBase)text.clone();

    // extract the next maxLength characters in the string (we have to do this using the
    // Normalizer to ensure that our offsets correspond to those the rest of the
    // iterator is using) and store it in "fragment".
    tempText.previous();
    key.setLength(0);
    int c = tempText.next();
    while (maxLength > 0 && c != NormalizerBase.DONE) {
        if (Character.isSupplementaryCodePoint(c)) {
            key.append(Character.toChars(c));
            maxLength -= 2;
        } else {
            key.append((char)c);
            --maxLength;
        }
        c = tempText.next();
    }
    String fragment = key.toString();
    // now that we have that fragment, iterate through this list looking for the
    // longest sequence that matches the characters in the actual text.  (maxLength
    // is used here to keep track of the length of the longest sequence)
    // Upon exit from this loop, maxLength will contain the length of the matching
    // sequence and order will contain the collation-element value corresponding
    // to this sequence
    maxLength = 1;
    for (int i = list.size() - 1; i > 0; i--) {
        pair = list.elementAt(i);
        if (!pair.fwd)
            continue;

        if (fragment.startsWith(pair.entryName) && pair.entryName.length()
                > maxLength) {
            maxLength = pair.entryName.length();
            order = pair.value;
        }
    }

    // seek our current iteration position to the end of the matching sequence
    // and return the appropriate collation-element value (if there was no matching
    // sequence, we're already seeked to the right position and order already contains
    // the correct collation-element value for the single character)
    while (maxLength > 1) {
        c = text.next();
        maxLength -= Character.charCount(c);
    }
    return order;
}
 
Example 14
Source File: CollationElementIterator.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Get the ordering priority of the previous contracting character in the
 * string.
 * @param ch the starting character of a contracting character token
 * @return the next contracting character's ordering.  Returns NULLORDER
 * if the end of string is reached.
 */
private int prevContractChar(int ch)
{
    // This function is identical to nextContractChar(), except that we've
    // switched things so that the next() and previous() calls on the Normalizer
    // are switched and so that we skip entry pairs with the fwd flag turned on
    // rather than off.  Notice that we still use append() and startsWith() when
    // working on the fragment.  This is because the entry pairs that are used
    // in reverse iteration have their names reversed already.
    Vector<EntryPair> list = ordering.getContractValues(ch);
    EntryPair pair = list.firstElement();
    int order = pair.value;

    pair = list.lastElement();
    int maxLength = pair.entryName.length();

    NormalizerBase tempText = (NormalizerBase)text.clone();

    tempText.next();
    key.setLength(0);
    int c = tempText.previous();
    while (maxLength > 0 && c != NormalizerBase.DONE) {
        if (Character.isSupplementaryCodePoint(c)) {
            key.append(Character.toChars(c));
            maxLength -= 2;
        } else {
            key.append((char)c);
            --maxLength;
        }
        c = tempText.previous();
    }
    String fragment = key.toString();

    maxLength = 1;
    for (int i = list.size() - 1; i > 0; i--) {
        pair = list.elementAt(i);
        if (pair.fwd)
            continue;

        if (fragment.startsWith(pair.entryName) && pair.entryName.length()
                > maxLength) {
            maxLength = pair.entryName.length();
            order = pair.value;
        }
    }

    while (maxLength > 1) {
        c = text.previous();
        maxLength -= Character.charCount(c);
    }
    return order;
}
 
Example 15
Source File: CollationElementIterator.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Get the ordering priority of the previous contracting character in the
 * string.
 * @param ch the starting character of a contracting character token
 * @return the next contracting character's ordering.  Returns NULLORDER
 * if the end of string is reached.
 */
private int prevContractChar(int ch)
{
    // This function is identical to nextContractChar(), except that we've
    // switched things so that the next() and previous() calls on the Normalizer
    // are switched and so that we skip entry pairs with the fwd flag turned on
    // rather than off.  Notice that we still use append() and startsWith() when
    // working on the fragment.  This is because the entry pairs that are used
    // in reverse iteration have their names reversed already.
    Vector<EntryPair> list = ordering.getContractValues(ch);
    EntryPair pair = list.firstElement();
    int order = pair.value;

    pair = list.lastElement();
    int maxLength = pair.entryName.length();

    NormalizerBase tempText = (NormalizerBase)text.clone();

    tempText.next();
    key.setLength(0);
    int c = tempText.previous();
    while (maxLength > 0 && c != NormalizerBase.DONE) {
        if (Character.isSupplementaryCodePoint(c)) {
            key.append(Character.toChars(c));
            maxLength -= 2;
        } else {
            key.append((char)c);
            --maxLength;
        }
        c = tempText.previous();
    }
    String fragment = key.toString();

    maxLength = 1;
    for (int i = list.size() - 1; i > 0; i--) {
        pair = list.elementAt(i);
        if (pair.fwd)
            continue;

        if (fragment.startsWith(pair.entryName) && pair.entryName.length()
                > maxLength) {
            maxLength = pair.entryName.length();
            order = pair.value;
        }
    }

    while (maxLength > 1) {
        c = text.previous();
        maxLength -= Character.charCount(c);
    }
    return order;
}
 
Example 16
Source File: CollationElementIterator.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Get the ordering priority of the previous contracting character in the
 * string.
 * @param ch the starting character of a contracting character token
 * @return the next contracting character's ordering.  Returns NULLORDER
 * if the end of string is reached.
 */
private int prevContractChar(int ch)
{
    // This function is identical to nextContractChar(), except that we've
    // switched things so that the next() and previous() calls on the Normalizer
    // are switched and so that we skip entry pairs with the fwd flag turned on
    // rather than off.  Notice that we still use append() and startsWith() when
    // working on the fragment.  This is because the entry pairs that are used
    // in reverse iteration have their names reversed already.
    Vector<EntryPair> list = ordering.getContractValues(ch);
    EntryPair pair = list.firstElement();
    int order = pair.value;

    pair = list.lastElement();
    int maxLength = pair.entryName.length();

    NormalizerBase tempText = (NormalizerBase)text.clone();

    tempText.next();
    key.setLength(0);
    int c = tempText.previous();
    while (maxLength > 0 && c != NormalizerBase.DONE) {
        if (Character.isSupplementaryCodePoint(c)) {
            key.append(Character.toChars(c));
            maxLength -= 2;
        } else {
            key.append((char)c);
            --maxLength;
        }
        c = tempText.previous();
    }
    String fragment = key.toString();

    maxLength = 1;
    for (int i = list.size() - 1; i > 0; i--) {
        pair = list.elementAt(i);
        if (pair.fwd)
            continue;

        if (fragment.startsWith(pair.entryName) && pair.entryName.length()
                > maxLength) {
            maxLength = pair.entryName.length();
            order = pair.value;
        }
    }

    while (maxLength > 1) {
        c = text.previous();
        maxLength -= Character.charCount(c);
    }
    return order;
}
 
Example 17
Source File: CollationElementIterator.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Get the ordering priority of the next contracting character in the
 * string.
 * @param ch the starting character of a contracting character token
 * @return the next contracting character's ordering.  Returns NULLORDER
 * if the end of string is reached.
 */
private int nextContractChar(int ch)
{
    // First get the ordering of this single character,
    // which is always the first element in the list
    Vector<EntryPair> list = ordering.getContractValues(ch);
    EntryPair pair = list.firstElement();
    int order = pair.value;

    // find out the length of the longest contracting character sequence in the list.
    // There's logic in the builder code to make sure the longest sequence is always
    // the last.
    pair = list.lastElement();
    int maxLength = pair.entryName.length();

    // (the Normalizer is cloned here so that the seeking we do in the next loop
    // won't affect our real position in the text)
    NormalizerBase tempText = (NormalizerBase)text.clone();

    // extract the next maxLength characters in the string (we have to do this using the
    // Normalizer to ensure that our offsets correspond to those the rest of the
    // iterator is using) and store it in "fragment".
    tempText.previous();
    key.setLength(0);
    int c = tempText.next();
    while (maxLength > 0 && c != NormalizerBase.DONE) {
        if (Character.isSupplementaryCodePoint(c)) {
            key.append(Character.toChars(c));
            maxLength -= 2;
        } else {
            key.append((char)c);
            --maxLength;
        }
        c = tempText.next();
    }
    String fragment = key.toString();
    // now that we have that fragment, iterate through this list looking for the
    // longest sequence that matches the characters in the actual text.  (maxLength
    // is used here to keep track of the length of the longest sequence)
    // Upon exit from this loop, maxLength will contain the length of the matching
    // sequence and order will contain the collation-element value corresponding
    // to this sequence
    maxLength = 1;
    for (int i = list.size() - 1; i > 0; i--) {
        pair = list.elementAt(i);
        if (!pair.fwd)
            continue;

        if (fragment.startsWith(pair.entryName) && pair.entryName.length()
                > maxLength) {
            maxLength = pair.entryName.length();
            order = pair.value;
        }
    }

    // seek our current iteration position to the end of the matching sequence
    // and return the appropriate collation-element value (if there was no matching
    // sequence, we're already seeked to the right position and order already contains
    // the correct collation-element value for the single character)
    while (maxLength > 1) {
        c = text.next();
        maxLength -= Character.charCount(c);
    }
    return order;
}
 
Example 18
Source File: CollationElementIterator.java    From Java8CN with Apache License 2.0 4 votes vote down vote up
/**
 * Get the ordering priority of the next contracting character in the
 * string.
 * @param ch the starting character of a contracting character token
 * @return the next contracting character's ordering.  Returns NULLORDER
 * if the end of string is reached.
 */
private int nextContractChar(int ch)
{
    // First get the ordering of this single character,
    // which is always the first element in the list
    Vector<EntryPair> list = ordering.getContractValues(ch);
    EntryPair pair = list.firstElement();
    int order = pair.value;

    // find out the length of the longest contracting character sequence in the list.
    // There's logic in the builder code to make sure the longest sequence is always
    // the last.
    pair = list.lastElement();
    int maxLength = pair.entryName.length();

    // (the Normalizer is cloned here so that the seeking we do in the next loop
    // won't affect our real position in the text)
    NormalizerBase tempText = (NormalizerBase)text.clone();

    // extract the next maxLength characters in the string (we have to do this using the
    // Normalizer to ensure that our offsets correspond to those the rest of the
    // iterator is using) and store it in "fragment".
    tempText.previous();
    key.setLength(0);
    int c = tempText.next();
    while (maxLength > 0 && c != NormalizerBase.DONE) {
        if (Character.isSupplementaryCodePoint(c)) {
            key.append(Character.toChars(c));
            maxLength -= 2;
        } else {
            key.append((char)c);
            --maxLength;
        }
        c = tempText.next();
    }
    String fragment = key.toString();
    // now that we have that fragment, iterate through this list looking for the
    // longest sequence that matches the characters in the actual text.  (maxLength
    // is used here to keep track of the length of the longest sequence)
    // Upon exit from this loop, maxLength will contain the length of the matching
    // sequence and order will contain the collation-element value corresponding
    // to this sequence
    maxLength = 1;
    for (int i = list.size() - 1; i > 0; i--) {
        pair = list.elementAt(i);
        if (!pair.fwd)
            continue;

        if (fragment.startsWith(pair.entryName) && pair.entryName.length()
                > maxLength) {
            maxLength = pair.entryName.length();
            order = pair.value;
        }
    }

    // seek our current iteration position to the end of the matching sequence
    // and return the appropriate collation-element value (if there was no matching
    // sequence, we're already seeked to the right position and order already contains
    // the correct collation-element value for the single character)
    while (maxLength > 1) {
        c = text.next();
        maxLength -= Character.charCount(c);
    }
    return order;
}
 
Example 19
Source File: CollationElementIterator.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Get the ordering priority of the next contracting character in the
 * string.
 * @param ch the starting character of a contracting character token
 * @return the next contracting character's ordering.  Returns NULLORDER
 * if the end of string is reached.
 */
private int nextContractChar(int ch)
{
    // First get the ordering of this single character,
    // which is always the first element in the list
    Vector<EntryPair> list = ordering.getContractValues(ch);
    EntryPair pair = list.firstElement();
    int order = pair.value;

    // find out the length of the longest contracting character sequence in the list.
    // There's logic in the builder code to make sure the longest sequence is always
    // the last.
    pair = list.lastElement();
    int maxLength = pair.entryName.length();

    // (the Normalizer is cloned here so that the seeking we do in the next loop
    // won't affect our real position in the text)
    NormalizerBase tempText = (NormalizerBase)text.clone();

    // extract the next maxLength characters in the string (we have to do this using the
    // Normalizer to ensure that our offsets correspond to those the rest of the
    // iterator is using) and store it in "fragment".
    tempText.previous();
    key.setLength(0);
    int c = tempText.next();
    while (maxLength > 0 && c != NormalizerBase.DONE) {
        if (Character.isSupplementaryCodePoint(c)) {
            key.append(Character.toChars(c));
            maxLength -= 2;
        } else {
            key.append((char)c);
            --maxLength;
        }
        c = tempText.next();
    }
    String fragment = key.toString();
    // now that we have that fragment, iterate through this list looking for the
    // longest sequence that matches the characters in the actual text.  (maxLength
    // is used here to keep track of the length of the longest sequence)
    // Upon exit from this loop, maxLength will contain the length of the matching
    // sequence and order will contain the collation-element value corresponding
    // to this sequence
    maxLength = 1;
    for (int i = list.size() - 1; i > 0; i--) {
        pair = list.elementAt(i);
        if (!pair.fwd)
            continue;

        if (fragment.startsWith(pair.entryName) && pair.entryName.length()
                > maxLength) {
            maxLength = pair.entryName.length();
            order = pair.value;
        }
    }

    // seek our current iteration position to the end of the matching sequence
    // and return the appropriate collation-element value (if there was no matching
    // sequence, we're already seeked to the right position and order already contains
    // the correct collation-element value for the single character)
    while (maxLength > 1) {
        c = text.next();
        maxLength -= Character.charCount(c);
    }
    return order;
}
 
Example 20
Source File: CollationElementIterator.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * Get the ordering priority of the previous contracting character in the
 * string.
 * @param ch the starting character of a contracting character token
 * @return the next contracting character's ordering.  Returns NULLORDER
 * if the end of string is reached.
 */
private int prevContractChar(int ch)
{
    // This function is identical to nextContractChar(), except that we've
    // switched things so that the next() and previous() calls on the Normalizer
    // are switched and so that we skip entry pairs with the fwd flag turned on
    // rather than off.  Notice that we still use append() and startsWith() when
    // working on the fragment.  This is because the entry pairs that are used
    // in reverse iteration have their names reversed already.
    Vector<EntryPair> list = ordering.getContractValues(ch);
    EntryPair pair = list.firstElement();
    int order = pair.value;

    pair = list.lastElement();
    int maxLength = pair.entryName.length();

    NormalizerBase tempText = (NormalizerBase)text.clone();

    tempText.next();
    key.setLength(0);
    int c = tempText.previous();
    while (maxLength > 0 && c != NormalizerBase.DONE) {
        if (Character.isSupplementaryCodePoint(c)) {
            key.append(Character.toChars(c));
            maxLength -= 2;
        } else {
            key.append((char)c);
            --maxLength;
        }
        c = tempText.previous();
    }
    String fragment = key.toString();

    maxLength = 1;
    for (int i = list.size() - 1; i > 0; i--) {
        pair = list.elementAt(i);
        if (pair.fwd)
            continue;

        if (fragment.startsWith(pair.entryName) && pair.entryName.length()
                > maxLength) {
            maxLength = pair.entryName.length();
            order = pair.value;
        }
    }

    while (maxLength > 1) {
        c = text.previous();
        maxLength -= Character.charCount(c);
    }
    return order;
}