Comments (14)
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.
Original comment posted by gonzaloaune on 2007-11-19 at 03:39 PM
Like... List.charactersOf(List<String>, charSequence) ?
from guava.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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)
- Such content will give people a false sense of. HOT 1
- remove `synchronized` from `LocalCache::get(key, loader)` to allow for `VirtualThread`-friendly value-loading HOT 12
- Make BloomFilter.bitSize() public
- Btc
- T
- open access to constuct HashBasedTable object for supporting deserializer HOT 4
- Help Jackson with Guava Deserializers HOT 4
- There is no charset parameter on application/json HOT 5
- Support JDK 21 Sequenced Collections HOT 1
- x.y.z-jre version has -android.jar artifact with missing -jre classes HOT 2
- Move graph functionality to a separate module and maven artifact HOT 2
- Found 24 NPEs in guava HOT 1
- Consider reporting errors during encoding in ReaderInputStream HOT 3
- ArrayIndexOutOfBoundsException when creating a EntityManagerFactory HOT 1
- Support for weak values in `Multimap`
- debug android HOT 1
- Addition of Built-In Methods for Primitive Math operations HOT 1
- Could not find error_prone_annotations-2.11.0.jar HOT 1
- Gradle 6.x isn't able to pick right Guava variant HOT 3
- Guava build fails on `master` with JDK 21 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from guava.