congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
TypeUtils.isOptional
Code IndexAdd Tabnine to your IDE (free)

How to use
isOptional
method
in
io.sundr.codegen.utils.TypeUtils

Best Java code snippets using io.sundr.codegen.utils.TypeUtils.isOptional (Showing top 11 results out of 315)

origin: sundrio/sundrio

  public TypeRef apply(TypeRef type) {
    if (type instanceof ClassRef) {
      ClassRef classRef = (ClassRef) type;
      if (TypeUtils.isOptional(classRef)) {
        return classRef.getArguments().get(0);
      }
      if (TypeUtils.isOptionalInt(classRef)) {
        return new TypeDefBuilder().withPackageName("java.lang").withName("Integer").build().toReference();
      }
      if (TypeUtils.isOptionalLong(classRef)) {
        return new TypeDefBuilder().withPackageName("java.lang").withName("Long").build().toReference();
      }
      if (TypeUtils.isOptionalDouble(classRef)) {
        return new TypeDefBuilder().withPackageName("java.lang").withName("Double").build().toReference();
      }
    }
    return type;
  }
};
origin: io.ap4k/crd-annotations

 public static JSONSchemaProps from(TypeRef typeRef) {
  //1. Handle Collections and Arrays
   if (typeRef.getDimensions() > 0 || TypeUtils.isCollection(typeRef)) {
    return new JSONSchemaPropsBuilder()
     .withType("array")
     .withNewItems()
      .withSchema(from(TypeAs.combine(TypeAs.UNWRAP_ARRAY_OF, TypeAs.UNWRAP_COLLECTION_OF).apply(typeRef)))
     .and()
     .build();
   //2. Handle Standard Types
   } else if (TYPE_MAP.containsKey(typeRef)) {
    return new JSONSchemaPropsBuilder()
     .withType(TYPE_MAP.get(typeRef))
     .build();
   //3. Handle Optionals
   } else if (TypeUtils.isOptional(typeRef)) {
    return from(TypeAs.UNWRAP_OPTIONAL_OF.apply(typeRef));
   //4. Handle complex types
   } else if (typeRef instanceof ClassRef) {
    ClassRef classRef = (ClassRef) typeRef;
    TypeDef def  = classRef.getDefinition();
    return from(def);
   }
   return null;
 }
}
origin: sundrio/sundrio

  public Method apply(final Property property) {
    String prefix = "has";
    String methodName = prefix + property.getNameCapitalized();
    List<Statement> statements = new ArrayList<Statement>();
    if (isPrimitive(property.getTypeRef())) {
      statements.add(new StringStatement("return true;"));
    } else if (isList(property.getTypeRef()) || isSet(property.getTypeRef())) {
      statements.add(new StringStatement("return " + property.getName() + " != null && !" + property.getName() + ".isEmpty();"));
    } else if (isOptional(property.getTypeRef())|| isOptionalInt(property.getTypeRef()) || isOptionalLong(property.getTypeRef()) || isOptionalDouble(property.getTypeRef())) {
      statements.add(new StringStatement("return " + property.getName() + " != null && " + property.getName() + ".isPresent();"));
    } else {
      statements.add(new StringStatement("return this." + property.getName() + " != null;"));
    }
    return new MethodBuilder()
        .withModifiers(TypeUtils.modifiersToInt(Modifier.PUBLIC))
        .withName(methodName)
        .withReturnType(BOOLEAN_REF)
        .withArguments()
        .withNewBlock()
        .withStatements(statements)
        .endBlock()
        .build();
  }
});
origin: sundrio/sundrio

isOptional(baseType)
    ?  "return withNew" + methodNameBase + "Like(get" + methodNameBase + "() != null  && get"+methodNameBase+"().isPresent() ? get" + methodNameBase + "().get() : new " + builderType.getName() + "().build());"
    : "return withNew" + methodNameBase + "Like(get" + methodNameBase + "() != null ? get" + methodNameBase + "(): new " + builderType.getName() + "().build());";
origin: sundrio/sundrio

boolean isMap = TypeUtils.isMap(toAdd.getTypeRef());
boolean isAbstract = isAbstract(unwrapped);
boolean isOptional = TypeUtils.isOptional(toAdd.getTypeRef())
  || TypeUtils.isOptionalInt(toAdd.getTypeRef())
  || TypeUtils.isOptionalDouble(toAdd.getTypeRef())
origin: sundrio/sundrio

String methodName = prefix + methodNameBase + suffix;
String statement = isOptional(property.getTypeRef())
    ? "return withNew" + methodNameBase + "Like(get" + methodNameBase + "() != null && get"+methodNameBase+"().isPresent() ? get" + methodNameBase + "().get(): item);"
    : "return withNew" + methodNameBase + "Like(get" + methodNameBase + "() != null ? get" + methodNameBase + "(): item);";
origin: sundrio/sundrio

boolean isList = TypeUtils.isList(typeRef);
boolean isMap = TypeUtils.isMap(typeRef);
boolean isOptional = TypeUtils.isOptional(typeRef);
boolean isOptionalInt = TypeUtils.isOptionalInt(typeRef);
boolean isOptionalDouble = TypeUtils.isOptionalDouble(typeRef);
origin: sundrio/sundrio

String methodName = prefix + methodNameBase;
String statement = isOptional(property.getTypeRef())
    ? "return withNew" + methodNameBase + "Like(get" + methodNameBase + "() != null ? get" + methodNameBase + "().orElse(null) : null);"
    : "return withNew" + methodNameBase + "Like(get" + methodNameBase + "());";
origin: sundrio/sundrio

final boolean isMap = TypeUtils.isMap(property.getTypeRef());
final boolean isAbstract = isAbstract(unwrapped);
boolean isOptional = TypeUtils.isOptional(property.getTypeRef())
  || TypeUtils.isOptionalInt(property.getTypeRef())
  || TypeUtils.isOptionalDouble(property.getTypeRef())
origin: sundrio/sundrio

boolean isList = isList(property.getTypeRef());
boolean isSet = isSet(property.getTypeRef());
boolean isOptional = isOptional(property.getTypeRef()) || isOptionalDouble(property.getTypeRef()) || isOptionalInt(property.getTypeRef()) || isOptionalLong(property.getTypeRef());
origin: sundrio/sundrio

if (TypeUtils.isOptional(classRef)) {
  ClassRef optionalRef = Optionals.OPTIONAL.toReference(builderType);
  return new PropertyBuilder(property).withTypeRef(optionalRef)
io.sundr.codegen.utilsTypeUtilsisOptional

Javadoc

Checks if a TypeRef is a java.util.Optional.

Popular methods of TypeUtils

  • modifiersToInt
  • allProperties
  • isCollection
  • typeGenericOf
  • visitParents
  • fullyQualifiedNameDiff
  • getParameterDefinition
  • hasProperty
    Checks if property exists on the specified type.
  • isAbstract
    Checks a TypeRef is of an abstract type.
  • isArray
    Checks if a TypeRef is an array.
  • isBoolean
    Checks if a TypeRef is a Boolean or boolean.
  • isInstanceOf
    Checks if a TypeDef is an instance of an other TypeDef.
  • isBoolean,
  • isInstanceOf,
  • isList,
  • isMap,
  • isOptionalDouble,
  • isOptionalInt,
  • isOptionalLong,
  • isPrimitive,
  • isSet

Popular in Java

  • Making http post requests using okhttp
  • getResourceAsStream (ClassLoader)
  • findViewById (Activity)
  • getExternalFilesDir (Context)
  • NumberFormat (java.text)
    The abstract base class for all number formats. This class provides the interface for formatting and
  • HashMap (java.util)
    HashMap is an implementation of Map. All optional operations are supported.All elements are permitte
  • ExecutorService (java.util.concurrent)
    An Executor that provides methods to manage termination and methods that can produce a Future for tr
  • HttpServletRequest (javax.servlet.http)
    Extends the javax.servlet.ServletRequest interface to provide request information for HTTP servlets.
  • FileUtils (org.apache.commons.io)
    General file manipulation utilities. Facilities are provided in the following areas: * writing to a
  • StringUtils (org.apache.commons.lang)
    Operations on java.lang.String that arenull safe. * IsEmpty/IsBlank - checks if a String contains
  • Top Sublime Text plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now