/[classpath]/classpath/java/text/AttributedStringIterator.java
ViewVC logotype

Diff of /classpath/java/text/AttributedStringIterator.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.7.2.1 by gnu_andrew, Tue Aug 2 20:12:26 2005 UTC revision 1.7.2.2 by gnu_andrew, Wed Nov 2 00:43:36 2005 UTC
# Line 188  class AttributedStringIterator implement Line 188  class AttributedStringIterator implement
188      return(getRunLimit(s));      return(getRunLimit(s));
189    }    }
190    
191    public synchronized int getRunLimit(Set attribute_set)    public synchronized int getRunLimit(Set attributeSet)
192    {    {
193      boolean hit = false;      if (attributeSet == null)
194      int runLimit = ci.getEndIndex ();        return ci.getEndIndex();
195      int pos = ci.getIndex ();      
196        int current = ci.getIndex();
197      for (int i = 0; i < attribs.length; ++i)      int end = ci.getEndIndex();
198        int limit = current;
199        if (current == end)
200          return end;
201        Map runValues = getAttributes();
202        while (limit < end)
203        {
204          Iterator iterator = attributeSet.iterator();
205          while (iterator.hasNext())
206        {        {
207          if (pos >= attribs[i].begin_index &&          // Qualified name is a workaround for a gcj 4.0 bug.
208              pos < attribs[i].end_index)          AttributedCharacterIterator.Attribute attributeKey
209              = (AttributedCharacterIterator.Attribute) iterator.next();
210            Object v1 = runValues.get(attributeKey);
211            Object v2 = getAttribute(attributeKey, limit + 1);
212            boolean changed = false;
213            // check for equal or both null, if NO return start
214            if (v1 != null)
215              {
216                changed = !v1.equals(v2);
217              }
218            else
219            {            {
220              Iterator iter = attribute_set.iterator();              changed = (v2 != null);  
             while(iter.hasNext())  
               if (attribs[i].attribs.containsKey(iter.next()))  
                 {  
                   hit = true;  
                   runLimit = Math.min(runLimit, attribs[i].end_index);  
                 }  
221            }            }
222            if (changed)
223              return limit + 1;
224        }        }
225      if (hit)        // no differences, so increment limit and next and loop again
226        return runLimit;        limit++;
227      else      }
228        return ci.getEndIndex();      return end;
229    }    }
230    
231    /*************************************************************************/    /*************************************************************************/
# Line 221  class AttributedStringIterator implement Line 235  class AttributedStringIterator implement
235     * attribute combinations.     * attribute combinations.
236     */     */
237    
238      /**
239       * Returns the index of the first character in the run containing the current
240       * character and defined by all the attributes defined for that character
241       * position.
242       *
243       * @return The run start index.
244       */
245    public int getRunStart()    public int getRunStart()
246    {    {
247      return(getRunStart(getAttributes().keySet()));      return(getRunStart(getAttributes().keySet()));
248    }    }
249    
250      /**
251       * Returns the index of the first character in the run, defined by the
252       * specified attribute, that contains the current character.
253       *
254       * @param attrib  the attribute (<code>null</code> permitted).
255       *
256       * return The index of the first character in the run.
257       */
258    public int getRunStart(AttributedCharacterIterator.Attribute attrib)    public int getRunStart(AttributedCharacterIterator.Attribute attrib)
259    {    {
260        if (attrib == null)
261          return ci.getBeginIndex();
262      HashSet s = new HashSet();      HashSet s = new HashSet();
263      s.add(attrib);      s.add(attrib);
   
264      return(getRunStart(s));      return(getRunStart(s));
265    }    }
266    
267    public int getRunStart(Set attribute_set)    /**
268       * Returns the index of the first character in the run, defined by the
269       * specified attribute set, that contains the current character.
270       *
271       * @param attributeSet  the attribute set (<code>null</code> permitted).
272       *
273       * return The index of the first character in the run.
274       */
275      public int getRunStart(Set attributeSet)
276    {    {
277      boolean hit = false;      if (attributeSet == null)
278      int runBegin = 0;        return ci.getBeginIndex();
279      int pos = ci.getIndex();      
280        int current = ci.getIndex();
281      for (int i = 0; i < attribs.length; ++i)      int begin = ci.getBeginIndex();
282        int start = current;
283        if (start == begin)
284          return begin;
285        Map runValues = getAttributes();
286        int prev = start - 1;
287        while (start > begin)
288        {
289          Iterator iterator = attributeSet.iterator();
290          while (iterator.hasNext())
291        {        {
292          if (pos >= attribs[i].begin_index &&          // Qualified name is a workaround for a gcj 4.0 bug.
293              pos <= attribs[i].end_index)          AttributedCharacterIterator.Attribute attributeKey
294              = (AttributedCharacterIterator.Attribute) iterator.next();
295            Object v1 = runValues.get(attributeKey);
296            Object v2 = getAttribute(attributeKey, prev);
297            boolean changed = false;
298            // check for equal or both null, if NO return start
299            if (v1 != null)
300              {
301                changed = !v1.equals(v2);
302              }
303            else
304            {            {
305              Iterator iter = attribute_set.iterator();              changed = (v2 != null);  
             while(iter.hasNext())  
               if (attribs[i].attribs.containsKey(iter.next()))  
                 {  
                   hit = true;  
                   runBegin = Math.max(runBegin, attribs[i].begin_index);  
                 }  
306            }            }
307            if (changed)
308              return start;
309        }        }
310      if (hit)        // no differences, so decrement start and prev and loop again
311        return runBegin;        start--;
312      else        prev--;
313        return -1;      }
314        return start;
315    }    }
316    
317    /*************************************************************************/    /*************************************************************************/
318    
319    public Object getAttribute(AttributedCharacterIterator.Attribute attrib)    /**
320       * Returns the value for an attribute at the specified position.  If the
321       * attribute key (<code>key</code>) is <code>null</code>, the method returns
322       * <code>null</code>.
323       *
324       * @param key  the key (<code>null</code> permitted).
325       * @param pos  the character position.
326       *
327       * @return The attribute value (possibly <code>null</code>).
328       */
329      private Object getAttribute(AttributedCharacterIterator.Attribute key,
330              int pos)
331    {    {
332      if (attribs == null)      if (attribs == null)
333        return(null);        return null;
334        for (int i = attribs.length - 1; i >= 0; i--)
     for (int i = 0; i < attribs.length; i++)  
335        {        {
336          Set key_set = attribs[i].attribs.keySet();          if (pos >= attribs[i].begin_index && pos < attribs[i].end_index)
         Iterator iter = key_set.iterator();  
         while (iter.hasNext())  
337            {            {
338              Object obj = iter.next();              Set keys = attribs[i].attribs.keySet();
339                if (keys.contains(key))
340              // Check for attribute match and range match                {
341              if (obj.equals(attrib))                  return attribs[i].attribs.get(key);
342                if ((ci.getIndex() >= attribs[i].begin_index) &&                }
                   (ci.getIndex() < attribs[i].end_index))  
                 return(attribs[i].attribs.get(obj));  
343            }            }
344        }        }
345        return null;  
346      return(null);    }
347      
348      /**
349       * Returns the value for an attribute at the current position.  If the
350       * attribute key (<code>key</code>) is <code>null</code>, the method returns
351       * <code>null</code>.
352       *
353       * @param key  the key (<code>null</code> permitted).
354       *
355       * @return The attribute value (possibly <code>null</code>).
356       */
357      public Object getAttribute(AttributedCharacterIterator.Attribute key)
358      {
359        return getAttribute(key, ci.getIndex());
360    }    }
361    
362    /*************************************************************************/    /*************************************************************************/

Legend:
Removed from v.1.7.2.1  
changed lines
  Added in v.1.7.2.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26