Coder Social home page Coder Social logo

Comments (14)

gissuebot avatar gissuebot commented on May 18, 2024

Original comment posted by gonzaloaune on 2007-11-19 at 03:37 PM


You want to get a list of characters specified in the CharSequence of a certain List
right?.

from guava.

gissuebot avatar gissuebot commented on May 18, 2024

Original comment posted by gonzaloaune on 2007-11-19 at 03:39 PM


Like... List.charactersOf(List<String>, charSequence) ?

from guava.

gissuebot avatar gissuebot commented on May 18, 2024

Original comment posted by kevinb9n on 2007-11-19 at 06:06 PM


No, just view a CharSequence as a List, for example Lists.charactersof("abc") returns
['a', 'b', 'c'].

from guava.

gissuebot avatar gissuebot commented on May 18, 2024

Original comment posted by gonzaloaune on 2007-11-19 at 07:15 PM


You can use something like that (sorry for my english) =), im just trying to help.

Regards!

  /**
   * Returns an {@code List} instance given the charSequence.
   *
   * @param charSequence the elements that the list should contain, in order.
   * @return an {@code List} instance containing those elements.
   * */
  public static List<CharSequence> charactersOf(CharSequence charSequence) {
    checkNotNull(charSequence);
    List<CharSequence> charsList = newArrayList();

for (int i = 0; i < charSequence.length(); i++) {
  charsList.add(charSequence.subSequence(i, i+1));
}

return charsList;

  }

from guava.

gissuebot avatar gissuebot commented on May 18, 2024

Original comment posted by gonzaloaune on 2007-11-20 at 02:20 PM


Also, we could add this validation to avoid the creation of the new list.

if (charSequence.length() == 0) {
  return null; //Or whatever you want... (emptyList?)
}

Regards!

from guava.

gissuebot avatar gissuebot commented on May 18, 2024

Original comment posted by mohammady.mahdy on 2009-05-04 at 07:57 AM


I implemented this as a view of the character sequence in the attached patch, I'd
really appreciate any review and comment on it even if its not included as this is
one of my very first open source contributions.

from guava.

gissuebot avatar gissuebot commented on May 18, 2024

Original comment posted by creswick on 2009-05-04 at 05:47 PM


I took a quick look over charctersOf.txt, and have a few questions/suggestions. I
don't have the experience to comment on the overall structure/approach, but hopefully
these comments are helpful:

   * There is no guarantee that a given CharSequence is immutable, and it looks like
subSequence(int, int) returns a copy, rather than a view, so the implementation of
CharSequenceListView.subList(int,int) may not maintain the contract specified in the
List api for subList(int,int). (This can be seen by using subSequence and delete on
a StringBuffer.)

   * Is it necessary to redefine add/addAll/remove/set given that
CharSequenceListView extends ImmutableCollection<Character>?

   * Should the overridden methods all have @Overrides annotations? (get/add/etc.)

   * I believe all the fields could be final.

   * @NonNull annotation on parameter of charactersOf(CharSequence)?

   * javadoc on charactersOf(CharSequence)

   * Would it make sense to have the ListIterator extend
     UnmodifiableIterator? (reusing the remove() method defined
     therin). It seems like what you want is an
     UnmodifiableListIterator, which doesn't seem to exist yet.

from guava.

gissuebot avatar gissuebot commented on May 18, 2024

Original comment posted by mohammady.mahdy on 2009-05-05 at 06:36 AM


thanks for taking time to read the code and comment :-), ok here goes:
1-you are absolutely right, i will rewrite the sublist function to view the same list
probably with start and end fields limiting the operations and altering the behavior
of the iterators.

2-yes in case i am extending ImmutableCollection, I should've extended ImmutableList
though.

3-you are absolutely right I should do that.

4-you are right.

5-sure I just wrote the code as a draft to get feedback about the approach.

6-ya I looked for an UnmodifiableListIterator but couldn't find any and found myself
asking the same question and decided to do it the direct way and just change it if
there was a good reason.

I also figured out a better way to do the iterators (make them fail by saving the
initial size and checking the current size each time instead of iterate on a copy,
thanks for pointing out that subsequence returns a copy not a view, this won't detect
any set kind of operations though -- any ideas ?).

from guava.

gissuebot avatar gissuebot commented on May 18, 2024

Original comment posted by mohammady.mahdy on 2009-05-05 at 11:18 AM


if i actually viewed the list with start and end fields how would i know if the
sequence has changed and that these fields should be updated?

from guava.

gissuebot avatar gissuebot commented on May 18, 2024

Original comment posted by kevinb9n on 2009-09-17 at 06:02 PM


(No comment entered for this change.)


Labels: Milestone-Post1.0

from guava.

gissuebot avatar gissuebot commented on May 18, 2024

Original comment posted by finnw1 on 2010-02-01 at 03:03 PM


Wouldn't com.google.common.primitives.Chars be a better place for this than
com.google.common.collect.Lists, e.g. an overload of Chars.asList()?

from guava.

gissuebot avatar gissuebot commented on May 18, 2024

Original comment posted by [email protected] on 2010-07-30 at 03:53 AM


(No comment entered for this change.)


Labels: -Milestone-Post1.0

from guava.

gissuebot avatar gissuebot commented on May 18, 2024

Original comment posted by [email protected] on 2010-07-30 at 03:56 AM


(No comment entered for this change.)


Labels: -Priority-Medium

from guava.

gissuebot avatar gissuebot commented on May 18, 2024

Original comment posted by [email protected] on 2010-09-14 at 08:49 PM


(No comment entered for this change.)


Status: Fixed
Owner: [email protected]
Labels: Milestone-Release07

from guava.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.