use of org.apache.commons.lang3.Range in project Asqatasun by Asqatasun.
the class Rgaa40Rule110202Test method setProcess.
@Override
protected void setProcess() {
// ----------------------------------------------------------------------
// ------------------------------3NMI-01---------------------------------
// ----------------------------------------------------------------------
ProcessResult processResult = processPageTest("Rgaa40.Test.11.2.2-3NMI-01");
checkResultIsPreQualified(processResult, 2, 2);
checkRemarkIsPresent(processResult, TestSolution.NEED_MORE_INFO, RemarkMessageStore.MANUAL_CHECK_ON_ELEMENTS_MSG, HtmlElementStore.INPUT_ELEMENT, 1, new ImmutablePair(TITLE_ATTR, "title for input without type attribute (implicit text)"));
checkRemarkIsPresent(processResult, TestSolution.NEED_MORE_INFO, RemarkMessageStore.MANUAL_CHECK_ON_ELEMENTS_MSG, HtmlElementStore.INPUT_ELEMENT, 2, new ImmutablePair(TITLE_ATTR, "title for input with type equal to text"));
// ----------------------------------------------------------------------
// ------------------------------3NMI-02---------------------------------
// ----------------------------------------------------------------------
processResult = processPageTest("Rgaa40.Test.11.2.2-3NMI-02");
checkResultIsPreQualified(processResult, 17, 17);
HashMap<Integer, String> mapTypeAttribute = new HashMap<Integer, String>();
mapTypeAttribute.put(1, "checkbox");
mapTypeAttribute.put(2, "color");
mapTypeAttribute.put(3, "date");
mapTypeAttribute.put(4, "datetime-local");
mapTypeAttribute.put(5, "email");
mapTypeAttribute.put(6, "file");
mapTypeAttribute.put(7, "month");
mapTypeAttribute.put(8, "number");
mapTypeAttribute.put(9, "password");
mapTypeAttribute.put(10, "radio");
mapTypeAttribute.put(11, "range");
mapTypeAttribute.put(12, "search");
mapTypeAttribute.put(13, "tel");
mapTypeAttribute.put(14, "text");
mapTypeAttribute.put(15, "time");
mapTypeAttribute.put(16, "url");
mapTypeAttribute.put(17, "week");
for (Map.Entry item : mapTypeAttribute.entrySet()) {
int position = ((int) item.getKey());
checkRemarkIsPresent(processResult, TestSolution.NEED_MORE_INFO, RemarkMessageStore.MANUAL_CHECK_ON_ELEMENTS_MSG, HtmlElementStore.INPUT_ELEMENT, position, new ImmutablePair(TITLE_ATTR, "title for input with type equal to " + item.getValue()));
}
// ----------------------------------------------------------------------
// ------------------------------3NMI-03---------------------------------
// ----------------------------------------------------------------------
processResult = processPageTest("Rgaa40.Test.11.2.2-3NMI-03");
checkResultIsPreQualified(processResult, 1, 1);
checkRemarkIsPresent(processResult, TestSolution.NEED_MORE_INFO, RemarkMessageStore.MANUAL_CHECK_ON_ELEMENTS_MSG, HtmlElementStore.TEXTAREA_ELEMENT, 1, new ImmutablePair(TITLE_ATTR, "title value for TEXTAREA"));
// ----------------------------------------------------------------------
// ------------------------------3NMI-04---------------------------------
// ----------------------------------------------------------------------
processResult = processPageTest("Rgaa40.Test.11.2.2-3NMI-04");
checkResultIsPreQualified(processResult, 3, 3);
checkRemarkIsPresent(processResult, TestSolution.NEED_MORE_INFO, RemarkMessageStore.MANUAL_CHECK_ON_ELEMENTS_MSG, HtmlElementStore.SELECT_ELEMENT, 1, new ImmutablePair(TITLE_ATTR, "title value for SELECT"));
checkRemarkIsPresent(processResult, TestSolution.NEED_MORE_INFO, RemarkMessageStore.MANUAL_CHECK_ON_ELEMENTS_MSG, HtmlElementStore.OPTGROUP_ELEMENT, 2, new ImmutablePair(TITLE_ATTR, "title value for OPTGROUP"));
checkRemarkIsPresent(processResult, TestSolution.NEED_MORE_INFO, RemarkMessageStore.MANUAL_CHECK_ON_ELEMENTS_MSG, HtmlElementStore.OPTION_ELEMENT, 3, new ImmutablePair(TITLE_ATTR, "title value for OPTION"));
// ----------------------------------------------------------------------
// ------------------------------3NMI-05---------------------------------
// ----------------------------------------------------------------------
processResult = processPageTest("Rgaa40.Test.11.2.2-3NMI-05");
checkResultIsPreQualified(processResult, 1, 1);
checkRemarkIsPresent(processResult, TestSolution.NEED_MORE_INFO, RemarkMessageStore.MANUAL_CHECK_ON_ELEMENTS_MSG, HtmlElementStore.DATALIST_ELEMENT, 1, new ImmutablePair(TITLE_ATTR, "title value for DATALIST"));
// ----------------------------------------------------------------------
// ------------------------------3NMI-06---------------------------------
// ----------------------------------------------------------------------
processResult = processPageTest("Rgaa40.Test.11.2.2-3NMI-06");
checkResultIsPreQualified(processResult, 3, 3);
checkRemarkIsPresent(processResult, TestSolution.NEED_MORE_INFO, RemarkMessageStore.MANUAL_CHECK_ON_ELEMENTS_MSG, HtmlElementStore.PROGRESS_ELEMENT, 1, new ImmutablePair(TITLE_ATTR, "title value for PROGRESS"));
checkRemarkIsPresent(processResult, TestSolution.NEED_MORE_INFO, RemarkMessageStore.MANUAL_CHECK_ON_ELEMENTS_MSG, HtmlElementStore.OUTPUT_ELEMENT, 2, new ImmutablePair(TITLE_ATTR, "title value for OUTPUT"));
checkRemarkIsPresent(processResult, TestSolution.NEED_MORE_INFO, RemarkMessageStore.MANUAL_CHECK_ON_ELEMENTS_MSG, HtmlElementStore.METER_ELEMENT, 3, new ImmutablePair(TITLE_ATTR, "title value for METER"));
// ----------------------------------------------------------------------
// ------------------------------3NMI-07---------------------------------
// ----------------------------------------------------------------------
processResult = processPageTest("Rgaa40.Test.11.2.2-3NMI-07");
checkResultIsPreQualified(processResult, 11, 11);
HashMap<Integer, String> mapRoleAttribute = new HashMap<Integer, String>();
mapRoleAttribute.put(1, "checkbox");
mapRoleAttribute.put(2, "combobox");
mapRoleAttribute.put(3, "listbox");
mapRoleAttribute.put(4, "progressbar");
mapRoleAttribute.put(5, "option");
mapRoleAttribute.put(6, "radio");
mapRoleAttribute.put(7, "searchbox");
mapRoleAttribute.put(8, "slider");
mapRoleAttribute.put(9, "spinbutton");
mapRoleAttribute.put(10, "switch");
mapRoleAttribute.put(11, "textbox");
for (Map.Entry item : mapRoleAttribute.entrySet()) {
int position = ((int) item.getKey());
checkRemarkIsPresent(processResult, TestSolution.NEED_MORE_INFO, RemarkMessageStore.MANUAL_CHECK_ON_ELEMENTS_MSG, HtmlElementStore.DIV_ELEMENT, position, new ImmutablePair(TITLE_ATTR, "title value for ROLE " + item.getValue()));
}
// ----------------------------------------------------------------------
// ------------------------------3NMI-08---------------------------------
// ----------------------------------------------------------------------
processResult = processPageTest("Rgaa40.Test.11.2.2-3NMI-08");
checkResultIsPreQualified(processResult, 1, 1);
checkRemarkIsPresent(processResult, TestSolution.NEED_MORE_INFO, RemarkMessageStore.MANUAL_CHECK_ON_ELEMENTS_MSG, HtmlElementStore.INPUT_ELEMENT, 1, new ImmutablePair(TITLE_ATTR, "title for input without parent form tag"));
// ----------------------------------------------------------------------
// ------------------------------4NA-01----------------------------------
// ----------------------------------------------------------------------
checkResultIsNotApplicable(processPageTest("Rgaa40.Test.11.2.2-4NA-01"));
// ----------------------------------------------------------------------
// ------------------------------4NA-02----------------------------------
// ----------------------------------------------------------------------
checkResultIsNotApplicable(processPageTest("Rgaa40.Test.11.2.2-4NA-02"));
// ----------------------------------------------------------------------
// ------------------------------4NA-03----------------------------------
// ----------------------------------------------------------------------
checkResultIsNotApplicable(processPageTest("Rgaa40.Test.11.2.2-4NA-03"));
// ----------------------------------------------------------------------
// ------------------------------4NA-04----------------------------------
// ----------------------------------------------------------------------
checkResultIsNotApplicable(processPageTest("Rgaa40.Test.11.2.2-4NA-04"));
// ----------------------------------------------------------------------
// ------------------------------4NA-05----------------------------------
// ----------------------------------------------------------------------
checkResultIsNotApplicable(processPageTest("Rgaa40.Test.11.2.2-4NA-05"));
// ----------------------------------------------------------------------
// ------------------------------4NA-06----------------------------------
// ----------------------------------------------------------------------
checkResultIsNotApplicable(processPageTest("Rgaa40.Test.11.2.2-4NA-06"));
// ----------------------------------------------------------------------
// ------------------------------4NA-07----------------------------------
// ----------------------------------------------------------------------
checkResultIsNotApplicable(processPageTest("Rgaa40.Test.11.2.2-4NA-07"));
// ----------------------------------------------------------------------
// ------------------------------4NA-08----------------------------------
// ----------------------------------------------------------------------
checkResultIsNotApplicable(processPageTest("Rgaa40.Test.11.2.2-4NA-08"));
}
use of org.apache.commons.lang3.Range in project GDSC-SMLM by aherbert.
the class PsfCreator method fitPsf.
/**
* Fit the new PSF image and show a graph of the amplitude/width.
*
* @param psfStack the psf stack
* @param loess the loess
* @param cz the cz
* @param averageRange the average range
* @param fitCom the fit com
* @return The width of the PSF in the z-centre
*/
private double fitPsf(ImageStack psfStack, LoessInterpolator loess, int cz, double averageRange, final double[][] fitCom) {
IJ.showStatus("Fitting final PSF");
// is not appropriate for a normalised PSF.
if (fitConfig.getFitSolver() != FitSolver.LVM_LSE) {
ImageJUtils.log(" " + FitProtosHelper.getName(fitConfig.getFitSolver()) + " is not appropriate for final PSF fitting.");
ImageJUtils.log(" Switching to Least Square Estimation");
fitConfig.setFitSolver(FitSolver.LVM_LSE);
if (settings.getInteractiveMode()) {
// This assumes the LVM does not need the calibration
PeakFit.configureFitSolver(config, null, null, 0);
}
}
// Update the box radius since this is used in the fitSpot method.
boxRadius = psfStack.getWidth() / 2;
final int x = boxRadius;
final int y = boxRadius;
final double shift = fitConfig.getCoordinateShiftFactor();
// Scale the PSF
final PSF.Builder localPsf = fitConfig.getPsf().toBuilder();
for (int i = 0; i < localPsf.getParametersCount(); i++) {
final PSFParameter param = localPsf.getParameters(i);
if (param.getUnit() == PSFParameterUnit.DISTANCE) {
final PSFParameter.Builder b = param.toBuilder();
b.setValue(b.getValue() * settings.getMagnification());
localPsf.setParameters(i, b);
}
}
fitConfig.setPsf(localPsf.build());
// Need to be updated after the widths have been set
fitConfig.setCoordinateShiftFactor(shift);
fitConfig.setBackgroundFitting(false);
// Since the PSF will be normalised remove the camera calibration
fitConfig.setCameraType(CameraType.CAMERA_TYPE_NA);
fitConfig.setMinPhotons(0);
fitConfig.setBias(0);
fitConfig.setGain(1);
// No complex filtering so we get a fit. It should be easy to fit anyway.
fitConfig.setPrecisionThreshold(0);
fitConfig.setDirectFilter(null);
// fitConfig.setDisableSimpleFilter(true);
// Use this for debugging the fit
// fitConfig.setLog(uk.ac.sussex.gdsc.core.ij.ImageJPluginLoggerHelper.getDefaultLogger());
final MemoryPeakResults results = fitSpot(psfStack, psfStack.getWidth(), psfStack.getHeight(), x, y);
if (results.size() < 5) {
ImageJUtils.log(" Final PSF: Not enough fit results %d", results.size());
return 0;
}
// Get the results for the spot centre and width
final double[] z = new double[results.size()];
final double[] xCoord = new double[z.length];
final double[] yCoord = new double[z.length];
final double[] sd = new double[z.length];
final double[] a = new double[z.length];
// Set limits for the fit
final float maxWidth = (float) (Math.max(fitConfig.getInitialXSd(), fitConfig.getInitialYSd()) * settings.getMagnification() * 4);
// PSF is normalised to 1
final float maxSignal = 2;
final WidthResultProcedure wp = new WidthResultProcedure(results, DistanceUnit.PIXEL);
wp.getWxWy();
final HeightResultProcedure hp = new HeightResultProcedure(results, IntensityUnit.COUNT);
hp.getH();
final Counter counter = new Counter();
final Counter counterOk = new Counter();
// We have fit the results so they will be in the preferred units
results.forEach((PeakResultProcedure) peak -> {
int index = counter.getAndIncrement();
final float w = Math.max(wp.wx[index], wp.wy[index]);
if (peak.getIntensity() > maxSignal || w > maxWidth) {
return;
}
index = counterOk.getAndIncrement();
z[index] = peak.getFrame();
fitCom[0][peak.getFrame() - 1] = xCoord[index] = peak.getXPosition() - x;
fitCom[1][peak.getFrame() - 1] = yCoord[index] = peak.getYPosition() - y;
sd[index] = w;
a[index] = hp.heights[index];
});
// Truncate
final double[] z2 = Arrays.copyOf(z, counter.getCount());
final double[] xCoord2 = Arrays.copyOf(xCoord, z2.length);
final double[] yCoord2 = Arrays.copyOf(yCoord, z2.length);
final double[] sd2 = Arrays.copyOf(sd, z2.length);
final double[] a2 = Arrays.copyOf(a, z2.length);
// Extract the average smoothed range from the individual fits
final int r = (int) Math.ceil(averageRange / 2);
int start = 0;
int stop = z2.length - 1;
for (int j = 0; j < z2.length; j++) {
if (z2[j] > cz - r) {
start = j;
break;
}
}
for (int j = z2.length; j-- > 0; ) {
if (z2[j] < cz + r) {
stop = j;
break;
}
}
// Extract xy centre coords and smooth
double[] smoothX = new double[stop - start + 1];
double[] smoothY = new double[smoothX.length];
double[] smoothSd = new double[smoothX.length];
double[] smoothA = new double[smoothX.length];
final double[] newZ = new double[smoothX.length];
int smoothCzIndex = 0;
for (int j = start, k = 0; j <= stop; j++, k++) {
smoothX[k] = xCoord2[j];
smoothY[k] = yCoord2[j];
smoothSd[k] = sd2[j];
smoothA[k] = a2[j];
newZ[k] = z2[j];
if (newZ[k] == cz) {
smoothCzIndex = k;
}
}
smoothX = loess.smooth(newZ, smoothX);
smoothY = loess.smooth(newZ, smoothY);
smoothSd = loess.smooth(newZ, smoothSd);
smoothA = loess.smooth(newZ, smoothA);
// Update the widths and positions using the magnification
final double scale = 1.0 / settings.getMagnification();
for (int j = 0; j < xCoord2.length; j++) {
xCoord2[j] *= scale;
yCoord2[j] *= scale;
sd2[j] *= scale;
}
for (int j = 0; j < smoothX.length; j++) {
smoothX[j] *= scale;
smoothY[j] *= scale;
smoothSd[j] *= scale;
}
showPlots(z2, a2, newZ, smoothA, xCoord2, yCoord2, sd2, newZ, smoothX, smoothY, smoothSd, cz);
// Store the data for replotting
this.z = z2;
this.amplitude = a2;
this.smoothAz = newZ;
this.smoothA = smoothA;
this.xCoord = xCoord2;
this.yCoord = yCoord2;
this.sd = sd2;
this.newZ = newZ;
this.smoothX = smoothX;
this.smoothY = smoothY;
this.smoothSd = smoothSd;
// maximumIndex = findMinimumIndex(smoothSd, maximumIndex - start);
return smoothSd[smoothCzIndex];
}
use of org.apache.commons.lang3.Range in project GDSC-SMLM by aherbert.
the class ImageJ3DResultsViewer method getPoints.
/**
* Gets the points.
*
* @param results the results
* @param settings the settings
* @return the points
*/
static LocalList<Point3f> getPoints(MemoryPeakResults results, ImageJ3DResultsViewerSettingsOrBuilder settings) {
final LocalList<Point3f> points = new LocalList<>(results.size());
if (results.is3D()) {
results.forEach(DistanceUnit.NM, (XyzResultProcedure) (x, y, z) -> {
points.push(new Point3f(x, y, z));
});
} else {
results.forEach(DistanceUnit.NM, (XyResultProcedure) (x, y) -> {
points.push(new Point3f(x, y, 0));
});
final double range = settings.getDepthRange();
if (range > 0 && results.size() > 1) {
final DepthMode mode = DepthMode.forNumber(settings.getDepthMode());
final double min = -settings.getDepthRange() / 2;
switch(mode) {
case DITHER:
final SplitMix r = SplitMix.new64(settings.getDitherSeed());
for (int i = points.size(); i-- > 0; ) {
points.unsafeGet(i).z += (min + r.nextDouble() * range);
}
break;
case INTENSITY:
// Rank by intensity, highest first
final StandardResultProcedure p = new StandardResultProcedure(results);
p.getI();
final int[] indices = SimpleArrayUtils.natural(results.size());
SortUtils.sortIndices(indices, p.intensity, true);
final double inc = range / indices.length;
for (int i = 0; i < indices.length; i++) {
// The standard rendering has +z going away so put the highest rank at min
points.unsafeGet(indices[i]).z += (min + i * inc);
}
break;
case NONE:
break;
default:
throw new IllegalStateException("Unknown depth mode: " + mode);
}
}
}
return points;
}
use of org.apache.commons.lang3.Range in project GDSC-SMLM by aherbert.
the class Fire method calculatePrecisionHistogram.
/**
* Calculate a histogram of the precision. The precision can be either stored in the results or
* calculated using the Mortensen formula. If the precision method for Q estimation is not fixed
* then the histogram is fitted with a Gaussian to create an initial estimate.
*
* @return The precision histogram
*/
private PrecisionHistogram calculatePrecisionHistogram() {
final boolean logFitParameters = false;
final String title = results.getName() + " Precision Histogram";
// Check if the results has the precision already or if it can be computed.
final boolean canUseStored = canUseStoredPrecision(results);
final boolean canCalculatePrecision = canCalculatePrecision(results);
// Set the method to compute a histogram. Default to the user selected option.
PrecisionMethod method = null;
if ((canUseStored && precisionMethod == PrecisionMethod.STORED) || (canCalculatePrecision && precisionMethod == PrecisionMethod.CALCULATE)) {
method = precisionMethod;
}
if (method == null) {
// We only have two choices so if one is available then select it.
if (canUseStored) {
method = PrecisionMethod.STORED;
} else if (canCalculatePrecision) {
method = PrecisionMethod.CALCULATE;
}
// If the user selected a method not available then log a warning
if (method != null && precisionMethod != PrecisionMethod.FIXED) {
IJ.log(String.format("%s : Selected precision method '%s' not available, switching to '%s'", pluginTitle, precisionMethod, method.getName()));
}
if (method == null) {
// This does not matter if the user has provide a fixed input.
if (precisionMethod == PrecisionMethod.FIXED) {
final PrecisionHistogram histogram = new PrecisionHistogram(title);
histogram.mean = settings.mean;
histogram.sigma = settings.sigma;
return histogram;
}
// No precision
return null;
}
}
// We get here if we can compute precision.
// Build the histogram
StoredDataStatistics precision = new StoredDataStatistics(results.size());
if (method == PrecisionMethod.STORED) {
final StoredDataStatistics p = precision;
results.forEach((PeakResultProcedure) result -> p.add(result.getPrecision()));
} else {
precision.add(pp.precisions);
}
double yMin = Double.NEGATIVE_INFINITY;
double yMax = 0;
// Set the min and max y-values using 1.5 x IQR
final DescriptiveStatistics stats = precision.getStatistics();
final double lower = stats.getPercentile(25);
final double upper = stats.getPercentile(75);
if (Double.isNaN(lower) || Double.isNaN(upper)) {
if (logFitParameters) {
ImageJUtils.log("Error computing IQR: %f - %f", lower, upper);
}
} else {
final double iqr = upper - lower;
yMin = Math.max(lower - iqr, stats.getMin());
yMax = Math.min(upper + iqr, stats.getMax());
if (logFitParameters) {
ImageJUtils.log(" Data range: %f - %f. Plotting 1.5x IQR: %f - %f", stats.getMin(), stats.getMax(), yMin, yMax);
}
}
if (yMin == Double.NEGATIVE_INFINITY) {
final int n = 5;
yMin = Math.max(stats.getMin(), stats.getMean() - n * stats.getStandardDeviation());
yMax = Math.min(stats.getMax(), stats.getMean() + n * stats.getStandardDeviation());
if (logFitParameters) {
ImageJUtils.log(" Data range: %f - %f. Plotting mean +/- %dxSD: %f - %f", stats.getMin(), stats.getMax(), n, yMin, yMax);
}
}
// Get the data within the range
final double[] data = precision.getValues();
precision = new StoredDataStatistics(data.length);
for (final double d : data) {
if (d < yMin || d > yMax) {
continue;
}
precision.add(d);
}
final int histogramBins = HistogramPlot.getBins(precision, HistogramPlot.BinMethod.SCOTT);
final float[][] hist = HistogramPlot.calcHistogram(precision.getFloatValues(), yMin, yMax, histogramBins);
final PrecisionHistogram histogram = new PrecisionHistogram(hist, precision, title);
if (precisionMethod == PrecisionMethod.FIXED) {
histogram.mean = settings.mean;
histogram.sigma = settings.sigma;
return histogram;
}
// Fitting of the histogram to produce the initial estimate
// Extract non-zero data
float[] x = Arrays.copyOf(hist[0], hist[0].length);
float[] y = Arrays.copyOf(hist[1], hist[1].length);
int count = 0;
for (int i = 0; i < y.length; i++) {
if (y[i] > 0) {
x[count] = x[i];
y[count] = y[i];
count++;
}
}
x = Arrays.copyOf(x, count);
y = Arrays.copyOf(y, count);
// Sense check to fitted data. Get mean and SD of histogram
final double[] stats2 = HistogramPlot.getHistogramStatistics(x, y);
if (logFitParameters) {
ImageJUtils.log(" Initial Statistics: %f +/- %f", stats2[0], stats2[1]);
}
histogram.mean = stats2[0];
histogram.sigma = stats2[1];
// Standard Gaussian fit
final double[] parameters = fitGaussian(x, y);
if (parameters == null) {
ImageJUtils.log(" Failed to fit initial Gaussian");
return histogram;
}
final double newMean = parameters[1];
final double error = Math.abs(stats2[0] - newMean) / stats2[1];
if (error > 3) {
ImageJUtils.log(" Failed to fit Gaussian: %f standard deviations from histogram mean", error);
return histogram;
}
if (newMean < yMin || newMean > yMax) {
ImageJUtils.log(" Failed to fit Gaussian: %f outside data range %f - %f", newMean, yMin, yMax);
return histogram;
}
if (logFitParameters) {
ImageJUtils.log(" Initial Gaussian: %f @ %f +/- %f", parameters[0], parameters[1], parameters[2]);
}
histogram.mean = parameters[1];
histogram.sigma = parameters[2];
return histogram;
}
use of org.apache.commons.lang3.Range in project sts4 by spring-projects.
the class BoshCloudConfigSchema method createNetworkBlockSchema.
private YType createNetworkBlockSchema(BoshModels models) {
AbstractType t_manual_nw = f.ybean("ManualNetwork");
{
YBeanType t_subnet = f.ybean("Subnet[Manual]");
addProp(t_subnet, "range", t_ip_range).isRequired(true);
addProp(t_subnet, "gateway", t_ip_address).isRequired(true);
addProp(t_subnet, "dns", f.yseq(t_ip_address));
addProp(t_subnet, "reserved", f.yseq(t_ip_address_or_range));
addProp(t_subnet, "static", f.yseq(t_ip_address_or_range));
addProp(t_subnet, "az", t_az_ref);
addProp(t_subnet, "azs", f.yseq(t_az_ref));
addProp(t_subnet, "cloud_properties", t_params);
addProp(t_manual_nw, "subnets", f.yseq(t_subnet)).isRequired(true);
}
AbstractType t_vip_nw = f.ybean("VipNetwork");
addProp(t_vip_nw, "cloud_properties", t_params);
AbstractType t_dynamic_nw = f.ybean("DynamicNetwork");
addProp(t_dynamic_nw, "dns", f.yseq(t_ip_address));
addProp(t_dynamic_nw, "cloud_properties", t_params);
{
YBeanType t_subnet = f.ybean("Subnet[Dynamic]");
addProp(t_subnet, "dns", f.yseq(t_ip_address));
addProp(t_subnet, "az", t_az_ref);
addProp(t_subnet, "azs", f.yseq(t_az_ref));
addProp(t_subnet, "cloud_properties", t_params);
addProp(t_dynamic_nw, "subnets", f.yseq(t_subnet));
}
t_dynamic_nw.require(Constraints.mutuallyExclusive("dns", "subnets"));
t_dynamic_nw.require(Constraints.mutuallyExclusive("cloud_properties", "subnets"));
AbstractType t_network = f.contextAware("Network", dc -> {
String type = models.getTypeTag(dc);
if (StringUtil.hasText(type)) {
switch(type) {
case "manual":
return t_manual_nw;
case "dynamic":
return t_dynamic_nw;
case "vip":
return t_vip_nw;
default:
}
}
return null;
}).treatAsBean();
// Add shared properties to the 'super' type.
addProp(t_network, "name", t_network_def).isPrimary(true);
addProp(t_network, "type", f.yenum("NetworkType", "manual", "dynamic", "vip")).isRequired(true);
// Add shared properties to all 'sub' types.
for (AbstractType subtype : ImmutableList.of(t_dynamic_nw, t_manual_nw, t_vip_nw)) {
for (YTypedProperty sharedProp : t_network.getProperties()) {
subtype.addProperty(sharedProp);
}
}
return t_network;
}
Aggregations