Skip to content

Commit

Permalink
Sskz update sort and spalte B value (eclipse-set#1292)
Browse files Browse the repository at this point in the history
* Sskz: column B modify PZB designation

* Sskz: column B sort by Class type
  • Loading branch information
TruongQuangSB authored Jan 28, 2025
1 parent 2ba9adc commit 0e16923
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@
import static org.eclipse.set.ppmodel.extensions.BasisAttributExtensions.getContainer;
import static org.eclipse.set.ppmodel.extensions.EObjectExtensions.getNullableObject;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.StreamSupport;
import java.util.stream.Stream;

import org.eclipse.set.core.services.enumtranslation.EnumTranslationService;
import org.eclipse.set.feature.table.pt1.AbstractPlanPro2TableModelTransformator;
Expand All @@ -46,6 +49,7 @@
import org.eclipse.set.ppmodel.extensions.container.MultiContainer_AttributeGroup;
import org.eclipse.set.ppmodel.extensions.utils.Case;
import org.eclipse.set.utils.table.TMFactory;
import org.eclipse.xtext.xbase.lib.IterableExtensions;

import com.google.common.collect.Streams;

Expand All @@ -55,7 +59,24 @@
* @author Truong
*/
public class SskzTransformator extends AbstractPlanPro2TableModelTransformator {
private static final Map<Class<? extends Ur_Objekt>, Function<MultiContainer_AttributeGroup, Iterable<? extends Ur_Objekt>>> fieldElementClasses = new HashMap<>();

private record OperationalIdentifierFieldElement(
Class<? extends Ur_Objekt> clazz,
List<String> elementIdentifierts) {

public static int compare(final OperationalIdentifierFieldElement first,
final OperationalIdentifierFieldElement second) {
final ArrayList<Class<? extends Ur_Objekt>> clazzList = new ArrayList<>(
fieldElementClasses.keySet());
final int firstIndex = clazzList.indexOf(first.clazz());
final int secondIndex = clazzList.indexOf(second.clazz());

return Integer.compare(firstIndex, secondIndex);
}

}

private static final LinkedHashMap<Class<? extends Ur_Objekt>, Function<MultiContainer_AttributeGroup, Iterable<? extends Ur_Objekt>>> fieldElementClasses = new LinkedHashMap<>();
static {
fieldElementClasses.put(W_Kr_Gsp_Element.class,
MultiContainer_AttributeGroup::getWKrGspElement);
Expand Down Expand Up @@ -119,21 +140,11 @@ private Table transform(final Iterable<Aussenelementansteuerung> controls,
.getBezeichnungAEA().getWert());

// B: Sskz.Betriebl_Bez_Feldelem
@SuppressWarnings("unchecked")
final Case<Aussenelementansteuerung>[] fieldElementCases = fieldElementClasses
.keySet().stream().map(this::fieldElementCase)
.toArray(Case[]::new);

fillIterable(row, getColumn(cols, Betriebl_Bez_Feldelem), control,
(final Aussenelementansteuerung element) -> List
.of(fieldElementCases).stream()
.filter(c -> c.condition.apply(element)
.booleanValue())
.map(c -> c.filling.apply(element))
.flatMap(it -> StreamSupport
.stream(it.spliterator(), false))
.toList(),
null);
this::getFieldElementIdentifier,
OperationalIdentifierFieldElement::compare,
t -> String.join(ITERABLE_FILLING_SEPARATOR,
t.elementIdentifierts()));

// C: Sskz.Techn_Bez_OC
fill(row, getColumn(cols, Techn_Bez_OC), control, e -> ""); //$NON-NLS-1$
Expand Down Expand Up @@ -172,6 +183,27 @@ private Table transform(final Iterable<Aussenelementansteuerung> controls,

}

private List<OperationalIdentifierFieldElement> getFieldElementIdentifier(
final Aussenelementansteuerung control) {
final HashMap<Class<? extends Ur_Objekt>, Case<Aussenelementansteuerung>> fillCases = new LinkedHashMap<>();
fieldElementClasses.forEach((clazz, elements) -> fillCases.put(clazz,
fieldElementCase(clazz)));

final List<OperationalIdentifierFieldElement> result = new LinkedList<>();
fillCases.forEach((clazz, fillCase) -> {
if (fillCase.condition.apply(control).booleanValue()) {
final Iterable<String> fillValuesIterable = fillCase.filling
.apply(control);
final List<String> sortList = IterableExtensions
.sortWith(fillValuesIterable, fillCase.comparator);
result.add(
new OperationalIdentifierFieldElement(clazz, sortList));
}
});
return result;

}

private <T extends Ur_Objekt> Case<Aussenelementansteuerung> fieldElementCase(
final Class<T> clazz) {
final Function<Aussenelementansteuerung, List<T>> getRelevantElementFunc = control -> getRelevantFieldElements(
Expand All @@ -181,7 +213,7 @@ private <T extends Ur_Objekt> Case<Aussenelementansteuerung> fieldElementCase(
!getRelevantElementFunc.apply(control).isEmpty()),
control -> getRelevantElementFunc.apply(control).stream()
.map(this::getFieldElementDesignation).toList(),
ITERABLE_FILLING_SEPARATOR, null
ITERABLE_FILLING_SEPARATOR, MIXED_STRING_COMPARATOR

);
}
Expand Down Expand Up @@ -218,32 +250,64 @@ private String getFieldElementDesignation(final Ur_Objekt object) {
.getBezeichnungTabelle().getWert();
case final FMA_Komponente fma -> fma.getBezeichnung()
.getBezeichnungTabelle().getWert();
case final PZB_Element pzb -> {
final ENUMPZBArt pzbArt = getNullableObject(pzb,
ele -> ele.getPZBArt().getWert()).orElse(null);
if (pzbArt == null) {
yield "";
}
final List<String> pzbElementBezugspunkt = PZBElementExtensions
.getPZBElementBezugspunkt(pzb).stream()
.map(ele -> switch (ele) {
case final Signal signal -> signal.getBezeichnung()
.getBezeichnungTabelle().getWert();
case final W_Kr_Gsp_Element gsp -> gsp.getBezeichnung()
.getBezeichnungTabelle().getWert();
default -> "";

}).toList();
yield String.format("%s (%s)", translate(pzbArt),
String.join(",", pzbElementBezugspunkt));
}
case final PZB_Element pzb -> getPzbDesignation(pzb);
case final Schluesselsperre schluessel -> schluessel.getBezeichnung()
.getBezeichnungTabelle().getWert();
default -> null;
};
return getNullableObject(object, destignationFunc::apply).orElse("");
}

@SuppressWarnings("nls")
private String getPzbDesignation(final PZB_Element pzb) {
final ENUMPZBArt pzbArt = getNullableObject(pzb,
ele -> ele.getPZBArt().getWert()).orElse(null);
if (pzbArt == null) {
return "";
}
final List<String> pzbElementBezugspunkt = PZBElementExtensions
.getPZBElementBezugspunkt(pzb).stream()
.map(ele -> switch (ele) {
case final Signal signal -> signal.getBezeichnung()
.getBezeichnungTabelle().getWert();
case final W_Kr_Gsp_Element gsp -> gsp.getBezeichnung()
.getBezeichnungTabelle().getWert();
default -> "";

}).toList();
if (pzb.getPZBElementGM() != null) {
return String.format("%s (%s)", translate(pzbArt),
String.join(",", pzbElementBezugspunkt));
}

if (pzb.getPZBElementGUE() != null) {
final BigInteger speedCheck = getNullableObject(
pzb.getPZBElementGUE(),
gue -> gue.getPruefgeschwindigkeit().getWert())
.orElse(null);
if (speedCheck != null) {
final String[] pzbArtEnum = translate(pzbArt).split("/");
final List<String> shortPzbArt = Stream.of(pzbArtEnum)
.map(ele -> {
try {
final double hz = Double.parseDouble(ele);
final double shortHz = hz / 1000;
if (shortHz == (int) shortHz) {
return Integer.toString((int) shortHz);
}
return Double.toString(shortHz);
} catch (final NumberFormatException e) {
return ele;
}
}).toList();
return String.format("%s/GÜ %s (%s)",
String.join("/", shortPzbArt), speedCheck,
String.join(",", pzbElementBezugspunkt));
}
}
return "";
}

private <T extends Ur_Objekt> List<T> getRelevantFieldElements(
final Class<T> clazz, final Aussenelementansteuerung control) {
final Function<MultiContainer_AttributeGroup, Iterable<? extends Ur_Objekt>> getElementFunc = fieldElementClasses
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,35 +235,41 @@ class CellContentExtensions {
Function<R, T> newFormatter,
BiFunction<R, T, U> postFormatter,
Function<R, S> sorter
) {
return formatCompareContent(
oldContent.filterNull.toSet.toList.sortBy(sorter),
newContent.filterNull.toSet.toList.sortBy(sorter),
oldFormatter,
commonFormatter,
newFormatter,
postFormatter
)
}

static def <R, T, U> Iterable<U> formatCompareContent(
Iterable<R> oldContent,
Iterable<R> newContent,
Function<R, T> oldFormatter,
Function<R, T> commonFormatter,
Function<R, T> newFormatter,
BiFunction<R, T, U> postFormatter
) {
// new and unchanged content is sorted together
val result = newContent.filterNull.toSet.toList.sortBy(sorter).map [
val result = newContent.filterNull.toSet.toList.map [
if (oldContent.contains(it))
return postFormatter.apply(it, commonFormatter.apply(it))
else
return postFormatter.apply(it, newFormatter.apply(it))
]

// old content is appended after that
return result + oldContent.filterNull.toSet.toList.sortBy(sorter).filter [
return result + oldContent.filterNull.toSet.toList.filter [
!newContent.contains(it)
].map [
postFormatter.apply(it, oldFormatter.apply(it))
]
}

static def <R extends Comparable<? super R>, T, U> Iterable<U> formatCompareContent(
Iterable<R> oldContent,
Iterable<R> newContent,
Function<R, T> oldFormatter,
Function<R, T> commonFormatter,
Function<R, T> newFormatter,
BiFunction<R, T, U> postFormatter
) {
return formatCompareContent(oldContent, newContent, oldFormatter,
commonFormatter, newFormatter, postFormatter, [it])
}

static def <T, U> Iterable<U> formatCompareContent(
Object content,
Function<String, T> oldFormatter,
Expand All @@ -273,7 +279,7 @@ class CellContentExtensions {
) {
switch content {
StringCellContent:
content.value.filterNull.toSet.toList.sort.map [
content.value.filterNull.toSet.toList.map [
postFormatter.apply(it, commonFormatter.apply(it))
]
CompareCellContent:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ package org.eclipse.set.utils.table
import java.util.Collection
import java.util.Comparator
import java.util.List
import org.eclipse.set.basis.constants.ToolboxConstants
import org.eclipse.set.model.planpro.Regelzeichnung.Regelzeichnung
import org.eclipse.set.model.tablemodel.ColumnDescriptor
import org.eclipse.set.model.tablemodel.MultiColorContent
import org.eclipse.set.model.tablemodel.TableRow
import org.eclipse.set.ppmodel.extensions.utils.Case
import org.eclipse.set.model.planpro.Regelzeichnung.Regelzeichnung
import org.eclipse.set.utils.ToolboxConfiguration
import org.slf4j.Logger
import org.slf4j.LoggerFactory
Expand Down Expand Up @@ -45,7 +46,7 @@ abstract class AbstractTableModelTransformator<T> implements TableModelTransform
typeof(AbstractTableModelTransformator))

protected val static String ITERABLE_FILLING_SEPARATOR = String.format("%n")

val static boolean DEVELOPMENT_MODE = ToolboxConfiguration.developmentMode

val static String BLANK = ""
Expand Down Expand Up @@ -296,7 +297,8 @@ abstract class AbstractTableModelTransformator<T> implements TableModelTransform
(S)=>Iterable<String> sequence,
Comparator<String> comparator
) {
row.fillIterable(column, object, sequence, comparator, [it])
row.fillIterable(column, object, sequence, comparator ?: ToolboxConstants.
LST_OBJECT_NAME_COMPARATOR, [it])
}

def <S, T> void fillMultiColorIterable(
Expand Down Expand Up @@ -377,7 +379,7 @@ abstract class AbstractTableModelTransformator<T> implements TableModelTransform
row.fillIterableWithSeparatorConditional(column, object, [true],
sequence, comparator, elementFilling, [], separator)
}

/**
* Fill a row with a sequence of string values depending on a condition and handle exceptions.
*
Expand Down

0 comments on commit 0e16923

Please sign in to comment.