Skip to content
This repository has been archived by the owner on Dec 7, 2019. It is now read-only.

Added factories for SourcePersisters and the various GsonParser imple… #35

Merged
merged 2 commits into from
Jan 10, 2017
Merged

Added factories for SourcePersisters and the various GsonParser imple… #35

merged 2 commits into from
Jan 10, 2017

Conversation

scottroemeschke
Copy link
Contributor

"Added factories for SourcePersisters and the various GsonParser implementations. Updated README to use new factories. Updated example activity to use new factories. All factories return the general Store interfaces."

…mentations. Updated README to use new factories. Updated example activity to use new factories. All factories return the general Store interfaces.
@digitalbuddha
Copy link
Contributor

Thanks for contribution! Closes #30

*/
public static <T> Parser<Reader, T> createReaderParser(Class<T> parsedClass) {
if (parsedClass == null) throw new IllegalArgumentException("parsedClass cannot be null.");
return new GsonReaderParser<>(new Gson(), parsedClass);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is nice. Great addition!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the gson instance should be a singleton. My thinking is why create more than one if multiple stores want to use the convenience method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I had the same idea.
Not sure if that's something you would want to provide in the library, or have them write themselves.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other trick is that the factory is all static and has no state.
I'm not a fan of static variables that are mutable.

Copy link
Contributor

@alexio alexio Jan 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would vote against maintaining a singleton, if multiple instances are an issue the caller can resolve by passing in its own.

@scottroemeschke
Copy link
Contributor Author

Also, @digitalbuddha wasn't sure what the opinions on Precondition assertions were, as I didn't see any in the code besides the transcribed Guava cache code.

That being said, my personal preference is that I'm always happy when a library code fails immediately and clearly (of course at the cost of some boilerplate in the library code).

@digitalbuddha
Copy link
Contributor

I agree I like precondition checks as well. Feel free to add

@digitalbuddha
Copy link
Contributor

Let's wait for 1 more collab review before merging but lgtm. I agree on not holding static state.

@michaldrabik
Copy link
Contributor

I was also thinking about missing Preconditions when doing #28, but decided to not add any because there wasn't any in the codebase.

Maybe we could create an issue for that so a single PR can be made to add preconditions for the whole library (where necessary).

@digitalbuddha
Copy link
Contributor

Sure ticket made #41

return new GsonSourceParser<>(new Gson(), parsedClass);
}

/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment here and on next one seem to be reversed

import okio.BufferedSource;

/**
* Created by Scott on 1/8/2017.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace with an appropriate javadoc.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually just remove it, we can go to github to see who made file.

Copy link
Contributor Author

@scottroemeschke scottroemeschke Jan 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't mean to keep the "created" thing, just IDE setting I forgot to change, I'll fix.

@digitalbuddha
Copy link
Contributor

digitalbuddha commented Jan 9, 2017

remove the top level comment & flip the other two and this should be good to go.

@brianPlummer
Copy link
Contributor

@scottmeschke looks good! strip out the "created by" at the top of SourcePersisterFactory.java and it should be good to merge in!! :) thank you so much!!

@scottroemeschke
Copy link
Contributor Author

at work now, I'll fix these issues at home tonight. ty for the review

@scottroemeschke
Copy link
Contributor Author

Fixed the javadoc mistakes.

@digitalbuddha
Copy link
Contributor

Thank you do much for the contribution! We haven't even setup checkstyle yet. Love this community 💯

@digitalbuddha digitalbuddha merged commit f8a4a03 into nytimes:develop Jan 10, 2017
@scottroemeschke scottroemeschke deleted the scottmeschke/source_persister_and_gson_parser_factories branch January 10, 2017 02:06
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants