Example usage for java.util Objects requireNonNull

List of usage examples for java.util Objects requireNonNull

Introduction

In this page you can find the example usage for java.util Objects requireNonNull.

Prototype

public static <T> T requireNonNull(T obj) 

Source Link

Document

Checks that the specified object reference is not null .

Usage

From source file:io.github.retz.protocol.ListFilesRequest.java

@JsonCreator
public ListFilesRequest(@JsonProperty(value = "id", required = true) int id,
        @JsonProperty(value = "path", required = true) String dir) {
    this.id = id;
    this.path = Objects.requireNonNull(dir);
}

From source file:com.buildria.mocking.stub.Call.java

public static Call fromRequest(HttpRequest req) {
    Objects.requireNonNull(req);
    Call call = new Call();

    call.method = req.getMethod().name();
    QueryStringDecoder decoder = new QueryStringDecoder(req.getUri());
    call.path = QueryStringDecoder.decodeComponent(decoder.path());

    Map<String, List<String>> params = decoder.parameters();
    for (String name : params.keySet()) {
        List<String> values = params.get(name);
        for (String value : values) {
            call.parameters.add(new Pair(name, value));
        }/*  w  w  w  .  ja v  a2  s  .  c  o m*/
    }

    HttpHeaders headers = req.headers();
    for (String name : headers.names()) {
        List<String> values = headers.getAll(name);
        for (String value : values) {
            call.headers.add(new Pair(name, value));
        }
        if (CONTENT_TYPE.equalsIgnoreCase(name)) {
            call.contentType = MediaType.parse(headers.get(CONTENT_TYPE));
        }
    }

    if (req instanceof ByteBufHolder) {
        ByteBuf buf = ((ByteBufHolder) req).content();
        if (buf != null) {
            call.body = new byte[buf.readableBytes()];
            buf.readBytes(call.body);
        }
    }

    return call;
}

From source file:io.github.moosbusch.lumpi.gui.impl.Expression.java

public Expression(char separatorChar) {
    this.separatorChar = Objects.requireNonNull(separatorChar);
}

From source file:Main.java

/**
 * Creates a {@link Marshaller} based on the given {@link JAXBContext}
 * and configures it to use the given {@link Charset}, and allows to
 * output the XML code to be generated formatted and as an XML fragment.
 * /*  w  w w.  j a  va 2  s. co  m*/
 * @param ctx the {@link JAXBContext} to create a {@link Marshaller} for
 * @param charset the {@link Charset} the XML code should be formatted
 * @param formatted {@code true} if the XML code should be formatted,
 *       {@code false} otherwise
 * @param fragment {@code false} if the XML code should start with
 *       {@code <?xml }, or {@code true} if just fragment XML code should
 *       get generated
 * 
 * @return a preconfigured {@link Marshaller}
 * 
 * @throws IOException in case no {@link Marshaller} could get created
 */
public static Marshaller createMarshaller(JAXBContext ctx, Charset charset, boolean formatted, boolean fragment)
        throws IOException {
    if (charset == null) {
        return createMarshaller(ctx, Charset.defaultCharset(), formatted, fragment);
    }
    Objects.requireNonNull(ctx);
    try {
        Marshaller marshaller = ctx.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, formatted);
        marshaller.setProperty(Marshaller.JAXB_FRAGMENT, fragment);
        marshaller.setProperty(Marshaller.JAXB_ENCODING, charset.name());
        return marshaller;
    } catch (JAXBException e) {
        throw new IOException(e);
    }
}

From source file:edu.usu.sdl.openstorefront.validation.ValidationUtil.java

public static ValidationResult validate(ValidationModel validateModel) {
    Objects.requireNonNull(validateModel);

    ValidationResult validationResult = new ValidationResult();
    if (validateModel.getDataObject() == null && validateModel.isAcceptNull() == false) {
        RuleResult ruleResult = new RuleResult();
        ruleResult.setMessage("The whole data object is null.");
        ruleResult.setValidationRule("Don't allow null object");
        validationResult.getRuleResults().add(ruleResult);
    } else {//from ww  w. ja va2s.com
        if (validateModel.getDataObject() != null) {
            if (validateModel.getDataObject() instanceof Collection) {
                ((Collection) validateModel.getDataObject()).stream().forEach((dataObject) -> {
                    validationResult.getRuleResults()
                            .addAll(validate(ValidationModel.copy(validateModel, dataObject)).getRuleResults());
                });
            } else {
                if (validateModel.getApplyDefaults() && validateModel.getDataObject() instanceof BaseEntity) {
                    BaseEntity baseEntity = (BaseEntity) validateModel.getDataObject();
                    baseEntity.applyDefaultValues();
                }
                validationResult.getRuleResults().addAll(
                        validateFields(validateModel, validateModel.getDataObject().getClass(), null, null));
            }
        }
    }
    return validationResult;
}

From source file:io.github.retz.protocol.ListFilesResponse.java

@JsonCreator
public ListFilesResponse(@JsonProperty("job") Optional<Job> job,
        @JsonProperty("entries") List<DirEntry> entries) {
    this.job = Objects.requireNonNull(job);
    this.entries = (entries == null) ? new LinkedList<>() : entries;
}

From source file:io.github.retz.protocol.GetFileResponse.java

@JsonCreator
public GetFileResponse(@JsonProperty("job") Optional<Job> job,
        @JsonProperty("file") Optional<FileContent> file) {
    this.job = Objects.requireNonNull(job);
    this.file = Objects.requireNonNull(file);
}

From source file:com.spotify.hamcrest.jackson.IsJsonArray.java

private IsJsonArray(Matcher<? super Collection<JsonNode>> elementsMatcher) {
    super(JsonNodeType.ARRAY);
    this.elementsMatcher = Objects.requireNonNull(elementsMatcher);
}

From source file:com.ndemyanovskyi.observing.Listeners.java

public Listeners(Observable owner) {
    this.owner = Objects.requireNonNull(owner);
}

From source file:com.diffplug.gradle.pde.PdeProductBuildConfig.java

public PdeProductBuildConfig(Project project) {
    this.project = Objects.requireNonNull(project);
}