-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Simon Spielmann <simon@MacBook-Pro.fritz.box>
- Loading branch information
Simon Spielmann
authored and
Simon Spielmann
committed
Nov 10, 2022
1 parent
e58beff
commit b2aeeab
Showing
5 changed files
with
71 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
....binding.icloud/src/main/java/org/openhab/binding/icloud/internal/utilities/ListUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* Copyright (c) 2010-2022 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.binding.icloud.internal.utilities; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
/** | ||
* This class implements util methods for list handling. | ||
* | ||
* @author Simon Spielmann - Initial contribution | ||
* | ||
*/ | ||
public abstract class ListUtil { | ||
|
||
private ListUtil() { | ||
}; | ||
|
||
/** | ||
* Replace entries in the given originalList with entries from replacements, if the have an equal key. | ||
* | ||
* @param <K> Type of first pair element | ||
* @param <V> Type of second pair element | ||
* @param originalList List with entries to replace | ||
* @param replacements Replacement entries | ||
* @return New list with replaced entries | ||
*/ | ||
public static <K, V> List<Pair<K, V>> replaceEntries(List<Pair<K, V>> originalList, List<Pair<K, V>> replacements) { | ||
List<Pair<K, V>> result = new ArrayList<>(originalList); | ||
if (replacements != null) { | ||
Iterator<Pair<K, V>> it = result.iterator(); | ||
while (it.hasNext()) { | ||
Pair<K, V> requestHeader = it.next(); | ||
for (Pair<K, V> replacementHeader : replacements) { | ||
if (requestHeader.getKey().equals(replacementHeader.getKey())) { | ||
it.remove(); | ||
} | ||
} | ||
} | ||
result.addAll(replacements); | ||
} | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters