Giter Club home page Giter Club logo

Comments (11)

shadeven avatar shadeven commented on August 28, 2024

@alexfu, that's what I normally do for methods exposed to an interface. We can create a separate class which is only responsible for validation or create a new interface containing a valid() method which every builder should implement.

What do you think?

from sqlitequerybuilder.

monxalo avatar monxalo commented on August 28, 2024

You can use Preconditions for this.

public CreateTableBuilder column(Column column) {
  Preconditions.checkNotNull(column, "A non-null column is required.");

  definitions.add(column);
  return this;
}

from sqlitequerybuilder.

shadeven avatar shadeven commented on August 28, 2024

Or we can use the Java Objects class instead of introducing new library.

public CreateTableBuilder column(Column column) {
  Objects.requireNonNull(column, "A non-null column is required.");
  definitions.add(column);
  return this;
}

If the validation becomes more detailed and specific, then we need to create our own.

from sqlitequerybuilder.

monxalo avatar monxalo commented on August 28, 2024

Didn't know Objects had those checks. If It's just to check if an argument is null i agree.

Preconditions have other checks such as checkArgument(boolean expression) and throws an IllegalArgumentException accordingly.

It won't introduce another library, we can just include the Preconditions.java file (or just some methods) as it doesn't have any dependencies.

from sqlitequerybuilder.

monxalo avatar monxalo commented on August 28, 2024

Just noticed that in case of using on Android the Objects class is only available >= API 19, so just a limitation there.

from sqlitequerybuilder.

shadeven avatar shadeven commented on August 28, 2024

Oops, it is a limitation. Use other available library or check null by yourself then.
What sort of android project are you working on at the moment?

from sqlitequerybuilder.

monxalo avatar monxalo commented on August 28, 2024

@shadeven just a personal app, ticket manager for train trips here in portugal. It only imports the tickets from pdfs that the company sends by email; notifies of the next trip with convenient information like gate, carriage and seat number.

from sqlitequerybuilder.

shadeven avatar shadeven commented on August 28, 2024

@monxalo, sounds interesting. I want to up-skill in android development area, please let me know if you need extra hands.

from sqlitequerybuilder.

alexfu avatar alexfu commented on August 28, 2024

I'm in favor for doing null checks by hand or use Assert.assertNotNull. Using a third party library like Guava brings in unnecessary code in addition to depending on yet another library.

from sqlitequerybuilder.

monxalo avatar monxalo commented on August 28, 2024

@alexfu Like i said above you don't need to add the library as a dependency, just add the file needed to the util package like u2020.

from sqlitequerybuilder.

alexfu avatar alexfu commented on August 28, 2024

@monxalo sorry, must of missed that. that works too.

from sqlitequerybuilder.

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.