-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #196 from bmarwell/194-guava
[#194] remove guava, not used.
- Loading branch information
Showing
7 changed files
with
141 additions
and
44 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
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,53 @@ | ||
/** | ||
* Copyright (c) 2012 Reficio (TM) - Reestablish your software! All Rights Reserved. | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.reficio.p2.bundler; | ||
|
||
import org.reficio.p2.P2Artifact; | ||
|
||
import java.util.*; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
public class P2ArtifactMap<T> extends ConcurrentHashMap<P2Artifact, Collection<T>> { | ||
|
||
public void putAll(P2Artifact key, Collection<T> values) { | ||
this.replace(key, compute(key, (k, oldValues) -> newOrAdd(oldValues, values))); | ||
} | ||
|
||
public void put(P2Artifact key, T value) { | ||
this.replace(key, compute(key, (k, oldValues) -> newOrAdd(oldValues, Collections.singleton(value)))); | ||
} | ||
|
||
private Collection<T> newOrAdd(Collection<T> oldValues, | ||
Collection<T> values) { | ||
if (oldValues == null) { | ||
return new ArrayList<>(values); | ||
} else { | ||
List<T> newList = new ArrayList<>(oldValues); | ||
newList.addAll(values); | ||
return newList; | ||
} | ||
} | ||
|
||
@Override | ||
public Collection<T> get(Object key) { | ||
return Optional.ofNullable(super.get(key)) | ||
.orElseGet(Collections::emptyList); | ||
} | ||
|
||
} |
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
39 changes: 39 additions & 0 deletions
39
src/test/java/org/reficio/p2/bundler/P2ArtifactMapTest.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,39 @@ | ||
/** | ||
* Copyright (c) 2012 Reficio (TM) - Reestablish your software! All Rights Reserved. | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.reficio.p2.bundler; | ||
|
||
import org.junit.Test; | ||
import org.reficio.p2.P2Artifact; | ||
|
||
import java.util.Collection; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class P2ArtifactMapTest { | ||
|
||
@Test | ||
public void getNoFoundValueReturnsEmptyList() { | ||
P2ArtifactMap<P2Artifact> mapUnderTest = new P2ArtifactMap<>(); | ||
|
||
Collection<P2Artifact> value = mapUnderTest.get(new P2Artifact()); | ||
|
||
assertNotNull(value); | ||
} | ||
} |