/** * Copy the current immutable object by setting a value for the {@link FileVariable#getFirstLineIsColumnName() firstLineIsColumnName} attribute. * A value equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for firstLineIsColumnName * @return A modified copy of the {@code this} object */ public final ImmutableFileVariable withFirstLineIsColumnName(boolean value) { if (this.firstLineIsColumnName == value) return this; return new ImmutableFileVariable( this.columnsDelimiter, this.columnsNames, this.data, this.fileName, value, this.numOfFirstRowData, this.name, this.description, this.order, this.policy, this.scope, this.noValuesLeftBehavior); }
/** * This instance is equal to all instances of {@code ImmutableFileVariable} that have equal attribute values. * @return {@code true} if {@code this} is equal to {@code another} instance */ @Override public boolean equals(@Nullable Object another) { if (this == another) return true; return another instanceof ImmutableFileVariable && equalTo((ImmutableFileVariable) another); }
/** * Creates an immutable copy of a {@link FileVariable} value. * Uses accessors to get values to initialize the new immutable instance. * If an instance is already immutable, it is returned as is. * @param instance The instance to copy * @return A copied immutable FileVariable instance */ public static ImmutableFileVariable copyOf(FileVariable instance) { if (instance instanceof ImmutableFileVariable) { return (ImmutableFileVariable) instance; } return ImmutableFileVariable.builder() .from(instance) .build(); }
private void changeBaseNameForCopiedVariables() { ImmutableProject tmpProject = (ImmutableProject) project; List<Variable> newVariableList = new ArrayList<>(); List<String> fileLst = new ArrayList<>(); if (fileToCopy == null || fileToCopy.size() == 0) { return; } fileToCopy.get("variables").forEach(var -> fileLst.add(var.getAbsolutePath())); tmpProject.getVariables().forEach(var -> { if (var instanceof FileVariable && ((FileVariable) var).getFileName().isPresent() && fileLst.contains(((FileVariable) var).getFileName().get())) { ImmutableFileVariable fileVar = (ImmutableFileVariable) var; newVariableList.add(fileVar.withFileName( FileVariableWriter.VARIABLE_DIRECTORY + File.separator + new File(fileVar.getFileName().get()).getName())); } else { newVariableList.add(var); } }); project = tmpProject.withVariables(newVariableList); }
private void manageVariable(final String variableName) { final Wini.Section paramSection = fileInfos.get(variableName); //here we don't need to test if it exists because it has been added to this list on these tests String referenceVariableName = MethodUtils.normalizeString(leftBrace, rightBrace, paramSection.get("SelectNextRow")).substring( "Same line as ".length()); Variable refVar = variables.get(referenceVariableName); if (refVar == null || !(refVar instanceof FileVariable)) { logger.error("The reference parameter \"" + referenceVariableName + "\" does not exist or is not of the correct type for the parameter \"" + variableName); } else { FileVariable refVarFile = (FileVariable) refVar; nLVarValueFromLRVarName.put(MethodUtils.normalizeString(leftBrace, rightBrace, paramSection.get("ParamName")), refVarFile.getName() + "." + MethodUtils.normalizeString(leftBrace, rightBrace, paramSection.get("ColumnName"))); FileVariable newVariable = ImmutableFileVariable.copyOf(refVarFile); if (!(refVarFile.getFileName().isPresent() && refVarFile.getFileName().get().equals( //Here we create the dataFile full path to compare with the full path of the dependant variable "Local".equals(MethodUtils.normalizeString(leftBrace, rightBrace, paramSection.get(ParametersReaderUtils.TABLE_LOCATION))) ? folder + File.separator + MethodUtils.normalizeString(leftBrace, rightBrace, paramSection.get(ParametersReaderUtils.TABLE)) : MethodUtils.normalizeString(leftBrace, rightBrace, paramSection.get(ParametersReaderUtils.TABLE_LOCATION)) + File.separator + MethodUtils.normalizeString(leftBrace, rightBrace, paramSection.get(ParametersReaderUtils.TABLE))))) { newVariable = ParametersReaderUtils.handleDataForFileVariable(leftBrace, rightBrace, paramSection, refVarFile, folder); reader.removeDataFilesToCopyIf(dataFile -> dataFile.getAbsolutePath().equals(refVarFile.getFileName().orElse(""))); } newVariable = ParametersReaderUtils.handleVariableColumns(leftBrace, rightBrace, paramSection, newVariable); variables.put(referenceVariableName, newVariable); } }
public static FileVariable handleVariableColumns(final String leftBrace, final String rightBrace, final Ini.Section paramSection, final FileVariable refVarFile) { String newColName = MethodUtils.normalizeString(leftBrace, rightBrace, paramSection.get(COLUMNNAME)); List allColumns = ImmutableList.builder().addAll(refVarFile.getColumnsNames()).add(newColName).build(); return ImmutableFileVariable.builder() .from(refVarFile) .columnsNames(allColumns) .build(); }
/** * Copy the current immutable object by setting a value for the {@link FileVariable#getNumOfFirstRowData() numOfFirstRowData} attribute. * A value equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for numOfFirstRowData * @return A modified copy of the {@code this} object */ public final ImmutableFileVariable withNumOfFirstRowData(int value) { if (this.numOfFirstRowData == value) return this; return new ImmutableFileVariable( this.columnsDelimiter, this.columnsNames, this.data, this.fileName, this.firstLineIsColumnName, value, this.name, this.description, this.order, this.policy, this.scope, this.noValuesLeftBehavior); }
return ImmutableFileVariable.builder() .from(refVarFile) .data(newData)
/** * Copy the current immutable object with elements that replace the content of {@link FileVariable#getColumnsNames() columnsNames}. * @param elements The elements to set * @return A modified copy of {@code this} object */ public final ImmutableFileVariable withColumnsNames(String... elements) { ImmutableList<String> newValue = ImmutableList.copyOf(elements); return new ImmutableFileVariable( this.columnsDelimiter, newValue, this.data, this.fileName, this.firstLineIsColumnName, this.numOfFirstRowData, this.name, this.description, this.order, this.policy, this.scope, this.noValuesLeftBehavior); }
return ImmutableFileVariable.builder() .name(paramName) .policy(getPolicy(updateMethod, paramName))
/** * Copy the current immutable object by setting a value for the {@link FileVariable#getPolicy() policy} attribute. * A value equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for policy * @return A modified copy of the {@code this} object */ public final ImmutableFileVariable withPolicy(Variable.VariablePolicy value) { if (this.policy == value) return this; Variable.VariablePolicy newValue = Objects.requireNonNull(value, "policy"); return new ImmutableFileVariable( this.columnsDelimiter, this.columnsNames, this.data, this.fileName, this.firstLineIsColumnName, this.numOfFirstRowData, this.name, this.description, this.order, newValue, this.scope, this.noValuesLeftBehavior); }
/** * Copy the current immutable object by setting a value for the {@link FileVariable#getScope() scope} attribute. * A value equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for scope * @return A modified copy of the {@code this} object */ public final ImmutableFileVariable withScope(Variable.VariableScope value) { if (this.scope == value) return this; Variable.VariableScope newValue = Objects.requireNonNull(value, "scope"); return new ImmutableFileVariable( this.columnsDelimiter, this.columnsNames, this.data, this.fileName, this.firstLineIsColumnName, this.numOfFirstRowData, this.name, this.description, this.order, this.policy, newValue, this.noValuesLeftBehavior); }
/** * Copy the current immutable object with elements that replace the content of {@link FileVariable#getColumnsNames() columnsNames}. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param elements An iterable of columnsNames elements to set * @return A modified copy of {@code this} object */ public final ImmutableFileVariable withColumnsNames(Iterable<String> elements) { if (this.columnsNames == elements) return this; ImmutableList<String> newValue = ImmutableList.copyOf(elements); return new ImmutableFileVariable( this.columnsDelimiter, newValue, this.data, this.fileName, this.firstLineIsColumnName, this.numOfFirstRowData, this.name, this.description, this.order, this.policy, this.scope, this.noValuesLeftBehavior); }
/** * Copy the current immutable object by setting a <i>present</i> value for the optional {@link FileVariable#getData() data} attribute. * @param value The value for data * @return A modified copy of {@code this} object */ public final ImmutableFileVariable withData(String[][] value) { @Nullable String[][] newValue = Objects.requireNonNull(value, "data"); if (this.data == newValue) return this; return new ImmutableFileVariable( this.columnsDelimiter, this.columnsNames, newValue, this.fileName, this.firstLineIsColumnName, this.numOfFirstRowData, this.name, this.description, this.order, this.policy, this.scope, this.noValuesLeftBehavior); }
/** * Copy the current immutable object by setting a <i>present</i> value for the optional {@link FileVariable#getOrder() order} attribute. * @param value The value for order * @return A modified copy of {@code this} object */ public final ImmutableFileVariable withOrder(Variable.VariableOrder value) { @Nullable Variable.VariableOrder newValue = Objects.requireNonNull(value, "order"); if (this.order == newValue) return this; return new ImmutableFileVariable( this.columnsDelimiter, this.columnsNames, this.data, this.fileName, this.firstLineIsColumnName, this.numOfFirstRowData, this.name, this.description, newValue, this.policy, this.scope, this.noValuesLeftBehavior); }
/** * Copy the current immutable object by setting a <i>present</i> value for the optional {@link FileVariable#getNoValuesLeftBehavior() noValuesLeftBehavior} attribute. * @param value The value for noValuesLeftBehavior * @return A modified copy of {@code this} object */ public final ImmutableFileVariable withNoValuesLeftBehavior(Variable.VariableNoValuesLeftBehavior value) { @Nullable Variable.VariableNoValuesLeftBehavior newValue = Objects.requireNonNull(value, "noValuesLeftBehavior"); if (this.noValuesLeftBehavior == newValue) return this; return new ImmutableFileVariable( this.columnsDelimiter, this.columnsNames, this.data, this.fileName, this.firstLineIsColumnName, this.numOfFirstRowData, this.name, this.description, this.order, this.policy, this.scope, newValue); }
/** * Copy the current immutable object by setting an optional value for the {@link FileVariable#getData() data} attribute. * A shallow reference equality check is used on unboxed optional value to prevent copying of the same value by returning {@code this}. * @param optional A value for data * @return A modified copy of {@code this} object */ public final ImmutableFileVariable withData(Optional<? extends String[][]> optional) { @Nullable String[][] value = optional.orElse(null); if (this.data == value) return this; return new ImmutableFileVariable( this.columnsDelimiter, this.columnsNames, value, this.fileName, this.firstLineIsColumnName, this.numOfFirstRowData, this.name, this.description, this.order, this.policy, this.scope, this.noValuesLeftBehavior); }
/** * Copy the current immutable object by setting a value for the {@link FileVariable#getColumnsDelimiter() columnsDelimiter} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for columnsDelimiter * @return A modified copy of the {@code this} object */ public final ImmutableFileVariable withColumnsDelimiter(String value) { if (this.columnsDelimiter.equals(value)) return this; String newValue = Objects.requireNonNull(value, "columnsDelimiter"); return new ImmutableFileVariable( newValue, this.columnsNames, this.data, this.fileName, this.firstLineIsColumnName, this.numOfFirstRowData, this.name, this.description, this.order, this.policy, this.scope, this.noValuesLeftBehavior); }
/** * Copy the current immutable object by setting a value for the {@link FileVariable#getName() name} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for name * @return A modified copy of the {@code this} object */ public final ImmutableFileVariable withName(String value) { if (this.name.equals(value)) return this; String newValue = Objects.requireNonNull(value, "name"); return new ImmutableFileVariable( this.columnsDelimiter, this.columnsNames, this.data, this.fileName, this.firstLineIsColumnName, this.numOfFirstRowData, newValue, this.description, this.order, this.policy, this.scope, this.noValuesLeftBehavior); }
/** * Copy the current immutable object by setting a <i>present</i> value for the optional {@link FileVariable#getFileName() fileName} attribute. * @param value The value for fileName * @return A modified copy of {@code this} object */ public final ImmutableFileVariable withFileName(String value) { @Nullable String newValue = Objects.requireNonNull(value, "fileName"); if (Objects.equals(this.fileName, newValue)) return this; return new ImmutableFileVariable( this.columnsDelimiter, this.columnsNames, this.data, newValue, this.firstLineIsColumnName, this.numOfFirstRowData, this.name, this.description, this.order, this.policy, this.scope, this.noValuesLeftBehavior); }