Skip to content

Commit

Permalink
fix: Ordering of channels when numbers are bigger than int [backport …
Browse files Browse the repository at this point in the history
…release-5.2.0] (#4625)

* fix: Ordering of channels when numbers are bigger than int (#4596)

* fix: Ordering of channels when numbers are bigger than int

Signed-off-by: MMaiero <matteo.maiero@eurotech.com>

* Updated copyright header

---------

Signed-off-by: MMaiero <matteo.maiero@eurotech.com>
Co-authored-by: nicolatimeus <nicola.timeus@eurotech.com>
(cherry picked from commit d61c8b0)

* chore: Include updated web2 version in distrib

Signed-off-by: Nicola Timeus <nicola.timeus@eurotech.com>

---------

Signed-off-by: Nicola Timeus <nicola.timeus@eurotech.com>
Co-authored-by: Matteo Maiero <matteo.maiero@eurotech.com>
Co-authored-by: Nicola Timeus <nicola.timeus@eurotech.com>
  • Loading branch information
3 people authored May 3, 2023
1 parent 04f8811 commit b360f14
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion kura/distrib/config/kura.build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ org.eclipse.kura.raspberrypi.sensehat.version=1.2.0
org.eclipse.kura.raspberrypi.sensehat.example.version=1.2.0
org.eclipse.kura.example.wire.math.singleport.provider.version=1.2.0
org.eclipse.kura.example.wire.math.multiport.provider.version=1.2.0
org.eclipse.kura.web2.version=2.2.1
org.eclipse.kura.web2.version=2.2.2-SNAPSHOT
org.eclipse.kura.wire.camel.version=1.2.0
org.eclipse.kura.wire.component.provider.version=1.2.0
org.eclipse.kura.wire.h2db.component.provider.version=2.2.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*******************************************************************************
* Copyright (c) 2017, 2020 Eurotech and/or its affiliates and others
*
* Copyright (c) 2017, 2023 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
*
* SPDX-License-Identifier: EPL-2.0
*
*
* Contributors:
* Eurotech
*******************************************************************************/
Expand Down Expand Up @@ -96,7 +96,7 @@ private void probeChannels() {
if (name != null) {
result.add(name);
} else {
extraParameters.add(param);
this.extraParameters.add(param);
}
}
this.channelNames = result;
Expand Down Expand Up @@ -124,6 +124,7 @@ private void loadChannelModels() {
LegacyChannelModel model = models.computeIfAbsent(channelName, name -> new LegacyChannelModel(name, index));
model.parameters[channelIndexes.get(propertyName)] = param;
}

ArrayList<Entry<String, LegacyChannelModel>> sortedModels = new ArrayList<>(models.entrySet());
Collections.sort(sortedModels, CHANNEL_LABEL_COMPARATOR);
List<LegacyChannelModel> sortedLegacyChannelModels = new ArrayList<>();
Expand Down Expand Up @@ -261,14 +262,14 @@ public String getAssetPid() {
@Override
public boolean isValid() {
for (final ChannelModel model : this.channelModels) {
for (final String param : paramIndexes.keySet()) {
for (final String param : this.paramIndexes.keySet()) {
if (!model.isValid(param)) {
return false;
}
}
}

for (final GwtConfigParameter extraParam : extraParameters) {
for (final GwtConfigParameter extraParam : this.extraParameters) {

if (!ValidationUtil.validateParameter(extraParam, extraParam.getValue())) {
return false;
Expand All @@ -281,19 +282,19 @@ public boolean isValid() {
@Override
public void addAllChannels(final AssetModel other) {
for (final ChannelModel model : other.getChannels()) {
final ChannelModel channel = channelModels.stream()
final ChannelModel channel = this.channelModels.stream()
.filter(c -> c.getChannelName().contentEquals(model.getChannelName())).findAny()
.orElseGet(() -> createNewChannel(model.getChannelName()));
for (final String param : paramIndexes.keySet()) {
for (final String param : this.paramIndexes.keySet()) {
channel.setValue(param, model.getValue(param));
}
}
}

@Override
public void replaceChannels(final AssetModel other) {
while (!channelNames.isEmpty()) {
deleteChannel(channelNames.iterator().next());
while (!this.channelNames.isEmpty()) {
deleteChannel(this.channelNames.iterator().next());
}
addAllChannels(other);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
/*******************************************************************************
* Copyright (c) 2018, 2020 Eurotech and/or its affiliates and others
*
* Copyright (c) 2018, 2023 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
*
* SPDX-License-Identifier: EPL-2.0
*
*
* Contributors:
* Eurotech
*******************************************************************************/
package org.eclipse.kura.web.client.util;

import java.math.BigInteger;
import java.util.Comparator;
import java.util.Map.Entry;

Expand Down Expand Up @@ -72,14 +73,12 @@ public int compare(Entry<String, T> e1, Entry<String, T> e2) {
i1 = getNumberEnd(o1, s1);
i2 = getNumberEnd(o2, s2);

int n1 = Integer.parseInt(o1.substring(s1, i1));
int n2 = Integer.parseInt(o2.substring(s2, i2));
BigInteger n1 = new BigInteger(o1.substring(s1, i1));
BigInteger n2 = new BigInteger(o2.substring(s2, i2));

if (n1 < n2) {
return -1;
}
if (n1 > n2) {
return 1;
int comparisonResult = n1.compareTo(n2);
if (comparisonResult != 0) {
return comparisonResult;
}

state = ComparatorState.COMPARE_STRING;
Expand Down

0 comments on commit b360f14

Please sign in to comment.