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

The following examples show how to use java.util.Vector#lastElement() . 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: SnmpSendServer.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
private void fireRequestList(Vector<SnmpInformRequest> reqList) {
    // Fire all requests as independent requests.
    while (!reqList.isEmpty()) {
        SnmpInformRequest req = reqList.lastElement() ;
        if (req != null && req.inProgress())
            fireRequest(req) ;
        reqList.removeElementAt(reqList.size() - 1) ;
    }
}
 
Example 2
Source File: DeepNodeListImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/** Returns the node at the specified index. */
public Node item(int index) {
    Node thisNode;

    // Tree changed. Do it all from scratch!
    if(rootNode.changes() != changes) {
        nodes   = new Vector();
        changes = rootNode.changes();
    }

    // In the cache
    if (index < nodes.size())
        return (Node)nodes.elementAt(index);

    // Not yet seen
    else {

        // Pick up where we left off (Which may be the beginning)
            if (nodes.size() == 0)
                thisNode = rootNode;
            else
                thisNode=(NodeImpl)(nodes.lastElement());

            // Add nodes up to the one we're looking for
            while(thisNode != null && index >= nodes.size()) {
                    thisNode=nextMatchingElementAfter(thisNode);
                    if (thisNode != null)
                        nodes.addElement(thisNode);
                }

        // Either what we want, or null (not avail.)
                return thisNode;
        }

}
 
Example 3
Source File: DeepNodeListImpl.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/** Returns the node at the specified index. */
public Node item(int index) {
    Node thisNode;

    // Tree changed. Do it all from scratch!
    if(rootNode.changes() != changes) {
        nodes   = new Vector();
        changes = rootNode.changes();
    }

    // In the cache
    if (index < nodes.size())
        return (Node)nodes.elementAt(index);

    // Not yet seen
    else {

        // Pick up where we left off (Which may be the beginning)
            if (nodes.size() == 0)
                thisNode = rootNode;
            else
                thisNode=(NodeImpl)(nodes.lastElement());

            // Add nodes up to the one we're looking for
            while(thisNode != null && index >= nodes.size()) {
                    thisNode=nextMatchingElementAfter(thisNode);
                    if (thisNode != null)
                        nodes.addElement(thisNode);
                }

        // Either what we want, or null (not avail.)
                return thisNode;
        }

}
 
Example 4
Source File: PopUpMineLauncherHandler.java    From megamek with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void handleEntityDamage(Entity entityTarget,
        Vector<Report> vPhaseReport, Building bldg, int hits, int nCluster,
        int bldgAbsorbs) {
    HitData hit = entityTarget.rollHitLocation(toHit.getHitTable(),
            toHit.getSideTable(), waa.getAimedLocation(),
            waa.getAimingMode(), toHit.getCover());
    hit.setAttackerId(getAttackerId());
    if (target instanceof Mech) {
        hit = new HitData(Mech.LOC_CT);
    } else { // te instanceof Tank
        hit = new HitData(Tank.LOC_FRONT);
    }
    hit.setGeneralDamageType(generalDamageType);
    // Do criticals.
    Vector<Report> specialDamageReport = server
            .criticalEntity(
                    entityTarget,
                    hit.getLocation(), hit.isRear(),
                    entityTarget.getArmorType(hit.getLocation()) == EquipmentType.T_ARMOR_HARDENED ? -2
                            : 0, 4);

    // Replace "no effect" results with 4 points of damage.
    if ((specialDamageReport.lastElement()).messageId == 6005) {
        int damage = 4;
        // ASSUMPTION: buildings CAN'T absorb *this* damage.
        // specialDamage = damageEntity(entityTarget, hit, damage);
        specialDamageReport = server
                .damageEntity(
                        entityTarget,
                        hit,
                        damage,
                        false,
                        ae.getSwarmTargetId() == entityTarget.getId() ? DamageType.IGNORE_PASSENGER
                                : damageType, false, false, throughFront,
                        underWater);
    } else {
        // add newline _before_ last report
        try {
            (specialDamageReport.elementAt(specialDamageReport.size() - 2)).newlines++;
        } catch (ArrayIndexOutOfBoundsException aiobe) {
            System.err
                    .println("ERROR: no previous report when trying to add newline");
        }
    }
    // Report the result
    vPhaseReport.addAll(specialDamageReport);
}
 
Example 5
Source File: ConfigParser.java    From Cybernet-VPN with GNU General Public License v3.0 4 votes vote down vote up
private Vector<String> getOption(String option, int minarg, int maxarg) throws ConfigParseError {
    Vector<Vector<String>> alloptions = getAllOption(option, minarg, maxarg);
    if (alloptions == null) return null;
    else return alloptions.lastElement();
}
 
Example 6
Source File: CollationElementIterator.java    From JDKSourceCode1.8 with MIT License 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 7
Source File: CollationElementIterator.java    From jdk8u-dev-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 8
Source File: Whitespace.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * Orders a set or rules by priority, removes redundant rules and rules
 * that are shadowed by stronger, contradicting rules.
 */
private static int prioritizeRules(Vector rules) {
    WhitespaceRule currentRule;
    int defaultAction = PRESERVE_SPACE;

    // Sort all rules with regard to priority
    quicksort(rules, 0, rules.size()-1);

    // Check if there are any "xsl:strip-space" elements at all.
    // If there are no xsl:strip elements we can ignore all xsl:preserve
    // elements and signal that all whitespaces should be preserved
    boolean strip = false;
    for (int i = 0; i < rules.size(); i++) {
        currentRule = (WhitespaceRule)rules.elementAt(i);
        if (currentRule.getAction() == STRIP_SPACE) {
            strip = true;
        }
    }
    // Return with default action: PRESERVE_SPACE
    if (!strip) {
        rules.removeAllElements();
        return PRESERVE_SPACE;
    }

    // Remove all rules that are contradicted by rules with higher priority
    for (int idx = 0; idx < rules.size(); ) {
        currentRule = (WhitespaceRule)rules.elementAt(idx);

        // Remove this single rule if it has no purpose
        if (findContradictingRule(rules,currentRule) != null) {
            rules.remove(idx);
        }
        else {
            // Remove all following rules if this one overrides all
            if (currentRule.getStrength() == RULE_ALL) {
                defaultAction = currentRule.getAction();
                for (int i = idx; i < rules.size(); i++) {
                    rules.removeElementAt(i);
                }
            }
            // Skip to next rule (there might not be any)...
            idx++;
        }
    }

    // The rules vector could be empty if first rule has strength RULE_ALL
    if (rules.size() == 0) {
        return defaultAction;
    }

    // Now work backwards and strip away all rules that have the same
    // action as the default rule (no reason the check them at the end).
    do {
        currentRule = (WhitespaceRule)rules.lastElement();
        if (currentRule.getAction() == defaultAction) {
            rules.removeElementAt(rules.size() - 1);
        }
        else {
            break;
        }
    } while (rules.size() > 0);

    // Signal that whitespace detection predicate must be used.
    return defaultAction;
}
 
Example 9
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 10
Source File: VectorTest.java    From SPDS with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void test1() {
    Vector s = new Vector();
    s.lastElement();
    mustBeInErrorState(s);
}
 
Example 11
Source File: Whitespace.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Orders a set or rules by priority, removes redundant rules and rules
 * that are shadowed by stronger, contradicting rules.
 */
private static int prioritizeRules(Vector rules) {
    WhitespaceRule currentRule;
    int defaultAction = PRESERVE_SPACE;

    // Sort all rules with regard to priority
    quicksort(rules, 0, rules.size()-1);

    // Check if there are any "xsl:strip-space" elements at all.
    // If there are no xsl:strip elements we can ignore all xsl:preserve
    // elements and signal that all whitespaces should be preserved
    boolean strip = false;
    for (int i = 0; i < rules.size(); i++) {
        currentRule = (WhitespaceRule)rules.elementAt(i);
        if (currentRule.getAction() == STRIP_SPACE) {
            strip = true;
        }
    }
    // Return with default action: PRESERVE_SPACE
    if (!strip) {
        rules.removeAllElements();
        return PRESERVE_SPACE;
    }

    // Remove all rules that are contradicted by rules with higher priority
    for (int idx = 0; idx < rules.size(); ) {
        currentRule = (WhitespaceRule)rules.elementAt(idx);

        // Remove this single rule if it has no purpose
        if (findContradictingRule(rules,currentRule) != null) {
            rules.remove(idx);
        }
        else {
            // Remove all following rules if this one overrides all
            if (currentRule.getStrength() == RULE_ALL) {
                defaultAction = currentRule.getAction();
                for (int i = idx; i < rules.size(); i++) {
                    rules.removeElementAt(i);
                }
            }
            // Skip to next rule (there might not be any)...
            idx++;
        }
    }

    // The rules vector could be empty if first rule has strength RULE_ALL
    if (rules.size() == 0) {
        return defaultAction;
    }

    // Now work backwards and strip away all rules that have the same
    // action as the default rule (no reason the check them at the end).
    do {
        currentRule = (WhitespaceRule)rules.lastElement();
        if (currentRule.getAction() == defaultAction) {
            rules.removeElementAt(rules.size() - 1);
        }
        else {
            break;
        }
    } while (rules.size() > 0);

    // Signal that whitespace detection predicate must be used.
    return defaultAction;
}
 
Example 12
Source File: CollationElementIterator.java    From dragonwell8_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 13
Source File: CollationElementIterator.java    From dragonwell8_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: UpdateTransactionCache_taddr.java    From guarda-android-wallets with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void run() {
  synchronized (requestExistsMutex) {
    if (requestExist) {
      callback.onResponse("Another UpdateTransacionCache_taddr request exists.", null);
      return;
    } else {
      requestExist = true;
    }
  }

  Vector<ZCashTransactionDetails_taddr> transactions = cache;
  if (transactions == null) {
    synchronized (requestExistsMutex) {
      requestExist = false;
    }

    callback.onResponse("Wallet is not imported.", null);
    return;
  }


  SortedSet<ZCashTransactionDetails_taddr> uniqueTransactions = new TreeSet<>();
  long lastBlock = 0;

  if (transactions.isEmpty()) {
    rescan = true;
  } else {
    lastBlock = transactions.lastElement().blockHeight;
  }

  if (rescan) {
    synchronized (transactions) {
      transactions.clear();
    }
  }

  try {
    getAllRecv(20, 0, rescan, lastBlock, uniqueTransactions);
    getAllSent(20, 0, rescan, lastBlock, uniqueTransactions);
  } catch (ZCashException e) {
    synchronized (requestExistsMutex) {
      requestExist = false;
    }

    callback.onResponse(e.getMessage(), null);
    return;
  }

  boolean initialized = ZCashTransactionDetails_taddr.prepareAfterParsing(uniqueTransactions);
  if (initialized) {
    transactions.addAll(uniqueTransactions);
  } else {
    synchronized (requestExistsMutex) {
      requestExist = false;
    }

    return;
  }

  synchronized (requestExistsMutex) {
    requestExist = false;
  }


  callback.onResponse("ok", null);
}
 
Example 15
Source File: TLAExpr.java    From tlaplus with MIT License 4 votes vote down vote up
public void prepend(TLAExpr expr, int spaces) throws TLAExprException 
/*********************************************************************
* Prepends the expression expr to the front of the current           *
* expression, leaving `spaces' number of spaces between the last     *
* token of expr and the first token of the current expression.       *
*********************************************************************/
{ /*******************************************************************
  * Prepend all but the last line of expr to the current expression. *
  *******************************************************************/
  int i = 0 ;
  while (i < expr.tokens.size()-1)
    { this.tokens.add(i, expr.tokens.elementAt(i)) ;
      i = i + 1 ;
    } ;
  /*******************************************************************
  * Set exprLine to the last line of expr and thisLine to what was   *
  * the first line of the current expression.                        *
  *******************************************************************/
  Vector exprLine = (Vector) expr.tokens.elementAt(i) ;
  Vector thisLine = (Vector) this.tokens.elementAt(i) ;

  /*******************************************************************
  * Increment the columns of the tokens in thisLine.                 *
  *******************************************************************/
  TLAToken tok = (TLAToken) exprLine.lastElement() ;
  int incr = tok.column + tok.getWidth() + spaces ;
  int j = 0 ;
  while (j < thisLine.size())
    { tok = (TLAToken) thisLine.elementAt(j) ;
      tok.column = tok.column + incr ;
      j = j + 1 ;
    } ;

  /*******************************************************************
  * Prepend the last line of expr to the first line of this          *
  * expression.                                                      *
  *******************************************************************/
  j = 0 ;
  while (j < exprLine.size())
    { thisLine.add(j, exprLine.elementAt(j)) ;
      j = j + 1 ;
    } ;        

  /*******************************************************************
  * Modify anchorTokens and anchorTokCol.                            *
  *******************************************************************/
  TLAToken[] newAToks = new TLAToken[this.tokens.size()] ;
  int[]      newATCol = new int[this.tokens.size()] ;

  j = 0 ;
  while (j < expr.tokens.size())
    { newAToks[j] = expr.anchorTokens[j] ;
      newATCol[j] = expr.anchorTokCol[j] ;
      j = j + 1 ;
    } ;

  while (j < this.tokens.size())
     { newAToks[j] = this.anchorTokens[j - expr.tokens.size() + 1] ;
       newATCol[j] = this.anchorTokCol[j - expr.tokens.size() + 1] ;
       j = j + 1 ;
    } ;
  this.anchorTokens = newAToks ;
  this.anchorTokCol = newATCol ;
  
  this.renormalize() ;
  return ;
}
 
Example 16
Source File: ScriptHighlight.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Event.detail line start offset (input) Event.text line text (input) LineStyleEvent.styles Enumeration of
 * StyleRanges, need to be in order. (output) LineStyleEvent.background line background color (output)
 */
public void lineGetStyle( LineStyleEvent event ) {
  Vector<StyleRange> styles = new Vector<StyleRange>();
  int token;
  StyleRange lastStyle;

  if ( inBlockComment( event.lineOffset, event.lineOffset + event.lineText.length() ) ) {
    styles.addElement( new StyleRange( event.lineOffset, event.lineText.length() + 4, colors[2], null ) );
    event.styles = new StyleRange[styles.size()];
    styles.copyInto( event.styles );
    return;
  }
  scanner.setRange( event.lineText );
  String xs = ( (StyledText) event.widget ).getText();
  if ( xs != null ) {
    parseBlockComments( xs );
  }
  token = scanner.nextToken();
  while ( token != EOF ) {
    if ( token != OTHER ) {
      if ( ( token == WHITE ) && ( !styles.isEmpty() ) ) {
        int start = scanner.getStartOffset() + event.lineOffset;
        lastStyle = styles.lastElement();
        if ( lastStyle.fontStyle != SWT.NORMAL ) {
          if ( lastStyle.start + lastStyle.length == start ) {
            // have the white space take on the style before it to minimize font style
            // changes
            lastStyle.length += scanner.getLength();
          }
        }
      } else {
        Color color = getColor( token );
        if ( color != colors[0] ) { // hardcoded default foreground color, black
          StyleRange style =
            new StyleRange( scanner.getStartOffset() + event.lineOffset, scanner.getLength(), color, null );
          if ( token == KEY ) {
            style.fontStyle = SWT.BOLD;
          }
          if ( styles.isEmpty() ) {
            styles.addElement( style );
          } else {
            lastStyle = styles.lastElement();
            if ( lastStyle.similarTo( style ) && ( lastStyle.start + lastStyle.length == style.start ) ) {
              lastStyle.length += style.length;
            } else {
              styles.addElement( style );
            }
          }
        }
      }
    }
    token = scanner.nextToken();
  }
  event.styles = new StyleRange[styles.size()];
  styles.copyInto( event.styles );
}
 
Example 17
Source File: CollationElementIterator.java    From jdk8u-dev-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 18
Source File: ConfigParser.java    From Cake-VPN with GNU General Public License v2.0 4 votes vote down vote up
private Vector<String> getOption(String option, int minarg, int maxarg) throws ConfigParseError {
    Vector<Vector<String>> alloptions = getAllOption(option, minarg, maxarg);
    if (alloptions == null) return null;
    else return alloptions.lastElement();
}
 
Example 19
Source File: Config.java    From openjdk-jdk8u with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Gets the last-defined string value for the specified keys.
 * @param keys the keys, as an array from section name, sub-section names
 * (if any), to value name.
 * @return the value. When there are multiple values for the same key,
 * returns the last one. {@code null} is returned if not all the keys are
 * defined. For example, {@code get("libdefaults", "forwardable")} will
 * return null if "forwardable" is not defined in [libdefaults], and
 * {@code get("realms", "R", "kdc")} will return null if "R" is not
 * defined in [realms] or "kdc" is not defined for "R".
 * @throws IllegalArgumentException if any of the keys is illegal, either
 * because a key not the last one is not a (sub)section name or the last
 * key is still a section name. For example, {@code get("libdefaults")}
 * throws this exception because [libdefaults] is a section name instead of
 * a value name, and {@code get("libdefaults", "forwardable", "tail")}
 * also throws this exception because "forwardable" is already a value name
 * and has no sub-key at all (given "forwardable" is defined, otherwise,
 * this method has no knowledge if it's a value name or a section name),
 */
public String get(String... keys) {
    Vector<String> v = getString0(keys);
    if (v == null) return null;
    return v.lastElement();
}
 
Example 20
Source File: Config.java    From openjdk-8 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Gets the last-defined string value for the specified keys.
 * @param keys the keys, as an array from section name, sub-section names
 * (if any), to value name.
 * @return the value. When there are multiple values for the same key,
 * returns the last one. {@code null} is returned if not all the keys are
 * defined. For example, {@code get("libdefaults", "forwardable")} will
 * return null if "forwardable" is not defined in [libdefaults], and
 * {@code get("realms", "R", "kdc")} will return null if "R" is not
 * defined in [realms] or "kdc" is not defined for "R".
 * @throws IllegalArgumentException if any of the keys is illegal, either
 * because a key not the last one is not a (sub)section name or the last
 * key is still a section name. For example, {@code get("libdefaults")}
 * throws this exception because [libdefaults] is a section name instead of
 * a value name, and {@code get("libdefaults", "forwardable", "tail")}
 * also throws this exception because "forwardable" is already a value name
 * and has no sub-key at all (given "forwardable" is defined, otherwise,
 * this method has no knowledge if it's a value name or a section name),
 */
public String get(String... keys) {
    Vector<String> v = getString0(keys);
    if (v == null) return null;
    return v.lastElement();
}