Skip to content
This repository has been archived by the owner on Sep 1, 2023. It is now read-only.

Commit

Permalink
Added support for 'int', 'long', 'float', and 'double expectedInputs
Browse files Browse the repository at this point in the history
- **BREAKING CHANGE NOTE**: Clients (e.g. older versions of `jobson-ui`) may not be prepared to handle these
  new data types. Minor version bumped from 0.0.x to 0.1.x in both `jobson` and `jobson-ui` to reflect this.
- Added support for numeric input types
- 'int': 32-bit signed integer. Max/min value = (2^31)-1. Should be sent to API as a JSON number (e.g. `"inputId": 34833`).
- 'long': 64-bit signed integer. Max/min value = (2^63)-1. Can be sent to the API as *either* a JSON number *or* a JSON string (clients may not support large in-memory numbers)
- 'float': 32-bit IEE754 floating point number
- 'long': 64-bit IEE754 floating point number
  • Loading branch information
adamkewley committed Oct 6, 2018
2 parents eab6519 + b0e778d commit ee42b3f
Show file tree
Hide file tree
Showing 28 changed files with 712 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.github.jobson.jobinputs.f32.F32ExpectedInput;
import com.github.jobson.jobinputs.f64.F64ExpectedInput;
import com.github.jobson.jobinputs.i32.I32ExpectedInput;
import com.github.jobson.jobinputs.i64.I64ExpectedInput;
import com.github.jobson.jobinputs.select.SelectExpectedInput;
import com.github.jobson.jobinputs.sql.SQLExpectedInput;
import com.github.jobson.jobinputs.string.StringExpectedInput;
Expand All @@ -40,7 +44,11 @@
@JsonSubTypes.Type(value = SQLExpectedInput.class, name = "sql"),
@JsonSubTypes.Type(value = SelectExpectedInput.class, name = "select"),
@JsonSubTypes.Type(value = StringExpectedInput.class, name = "string"),
@JsonSubTypes.Type(value = StringArrayExpectedInput.class, name = "string[]")
@JsonSubTypes.Type(value = StringArrayExpectedInput.class, name = "string[]"),
@JsonSubTypes.Type(value = F32ExpectedInput.class, name = "float"),
@JsonSubTypes.Type(value = F64ExpectedInput.class, name = "double"),
@JsonSubTypes.Type(value = I32ExpectedInput.class, name = "int"),
@JsonSubTypes.Type(value = I64ExpectedInput.class, name = "long"),
})
public abstract class JobExpectedInput<TJobInput extends JobInput> {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package com.github.jobson.jobinputs.f32;

import com.github.jobson.jobinputs.JobExpectedInput;
import com.github.jobson.utils.ValidationError;

import java.util.List;
import java.util.Optional;
import java.util.Random;

public final class F32ExpectedInput extends JobExpectedInput<F32Input> {
@Override
public Class<F32Input> getExpectedInputClass() {
return F32Input.class;
}

@Override
public Optional<List<ValidationError>> validate(F32Input input) {
return Optional.empty();
}

@Override
public F32Input generateExampleInput() {
final float val = new Random().nextFloat();
return new F32Input(val);
}
}
43 changes: 43 additions & 0 deletions jobson/src/main/java/com/github/jobson/jobinputs/f32/F32Input.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package com.github.jobson.jobinputs.f32;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import com.github.jobson.jobinputs.JobInput;

import javax.validation.constraints.NotNull;

public final class F32Input implements JobInput {

@NotNull
private float value;

@JsonCreator
public F32Input(float value) {
this.value = value;
}

@Override
@JsonValue
public String toString() {
return Float.toString(value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package com.github.jobson.jobinputs.f64;

import com.github.jobson.jobinputs.JobExpectedInput;
import com.github.jobson.utils.ValidationError;

import java.util.List;
import java.util.Optional;
import java.util.Random;

public final class F64ExpectedInput extends JobExpectedInput<F64Input> {
@Override
public Class<F64Input> getExpectedInputClass() {
return F64Input.class;
}

@Override
public Optional<List<ValidationError>> validate(F64Input input) {
return Optional.empty();
}

@Override
public F64Input generateExampleInput() {
final long value = new Random().nextLong();
return new F64Input(value);
}
}
52 changes: 52 additions & 0 deletions jobson/src/main/java/com/github/jobson/jobinputs/f64/F64Input.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package com.github.jobson.jobinputs.f64;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import com.github.jobson.jobinputs.JobInput;

import javax.validation.constraints.NotNull;

public final class F64Input implements JobInput {

@NotNull
private final double value;

@JsonCreator
public F64Input(double value) {
this.value = value;
}

public F64Input(String value) {
// The API may have to accept 64-bit doubles in string format because
// javascript clients can't handle 64-bit binary decimals without losing
// precision (after 16 significant digits, "real" doubles lose precision
// after 21 digits). Because of this, clients *may* send a double as a string
// which the server parses into a binary double server-side
this.value = Double.parseDouble(value);
}

@Override
@JsonValue
public String toString() {
return Double.toString(value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package com.github.jobson.jobinputs.i32;

import com.github.jobson.jobinputs.JobExpectedInput;
import com.github.jobson.utils.ValidationError;

import java.util.List;
import java.util.Optional;
import java.util.Random;

public final class I32ExpectedInput extends JobExpectedInput<I32Input> {
@Override
public Class<I32Input> getExpectedInputClass() {
return I32Input.class;
}

@Override
public Optional<List<ValidationError>> validate(I32Input input) {
return Optional.empty();
}

@Override
public I32Input generateExampleInput() {
final int value = new Random().nextInt();
return new I32Input(value);
}
}
43 changes: 43 additions & 0 deletions jobson/src/main/java/com/github/jobson/jobinputs/i32/I32Input.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package com.github.jobson.jobinputs.i32;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import com.github.jobson.jobinputs.JobInput;

import javax.validation.constraints.NotNull;

public final class I32Input implements JobInput {

@NotNull
private final int value;

@JsonCreator
public I32Input(int value) {
this.value = value;
}

@Override
@JsonValue
public String toString() {
return Integer.toString(this.value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package com.github.jobson.jobinputs.i64;

import com.github.jobson.jobinputs.JobExpectedInput;
import com.github.jobson.utils.ValidationError;

import java.util.List;
import java.util.Optional;
import java.util.Random;

public final class I64ExpectedInput extends JobExpectedInput<I64Input> {
@Override
public Class<I64Input> getExpectedInputClass() {
return I64Input.class;
}

@Override
public Optional<List<ValidationError>> validate(I64Input input) {
return Optional.empty();
}

@Override
public I64Input generateExampleInput() {
final long value = new Random().nextLong();
return new I64Input(value);
}
}
Loading

0 comments on commit ee42b3f

Please sign in to comment.