-
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,8 +27,7 @@ | |
import java.io.File; | ||
import java.io.IOException; | ||
|
||
import static com.google.common.base.Preconditions.checkArgument; | ||
import static com.google.common.base.Preconditions.checkNotNull; | ||
import static java.util.Objects.requireNonNull; | ||
|
||
/** | ||
* @author Tom Bujok ([email protected])<br> | ||
|
@@ -94,13 +93,16 @@ public static class Builder { | |
private String metadataRepositoryLocation; | ||
|
||
public Builder p2ApplicationLauncher(P2ApplicationLauncher launcher) { | ||
checkNotNull(launcher, "p2ApplicationLauncher cannot be null"); | ||
requireNonNull(launcher, "p2ApplicationLauncher cannot be null"); | ||
this.launcher = launcher; | ||
return this; | ||
} | ||
|
||
public Builder forkedProcessTimeoutInSeconds(int forkedProcessTimeoutInSeconds) { | ||
checkArgument(forkedProcessTimeoutInSeconds >= 0, "forkedProcessTimeoutInSeconds cannot be negative"); | ||
if (forkedProcessTimeoutInSeconds < 0) { | ||
throw new IllegalArgumentException("forkedProcessTimeoutInSeconds cannot be negative but was: " + forkedProcessTimeoutInSeconds); | ||
} | ||
|
||
this.forkedProcessTimeoutInSeconds = forkedProcessTimeoutInSeconds; | ||
return this; | ||
} | ||
|
@@ -115,21 +117,21 @@ public Builder additionalArgs(String additionalArgs) { | |
} | ||
|
||
public Builder categoryFileLocation(String categoryFileLocation) { | ||
checkNotNull(categoryFileLocation, "categoryFileLocation cannot be null"); | ||
requireNonNull(categoryFileLocation, "categoryFileLocation cannot be null"); | ||
this.categoryFileLocation = categoryFileLocation; | ||
return this; | ||
} | ||
|
||
public Builder metadataRepositoryLocation(String metadataRepositoryLocation) { | ||
checkNotNull(metadataRepositoryLocation, "metadataRepositoryLocation cannot be null"); | ||
requireNonNull(metadataRepositoryLocation, "metadataRepositoryLocation cannot be null"); | ||
this.metadataRepositoryLocation = metadataRepositoryLocation; | ||
return this; | ||
} | ||
|
||
public CategoryPublisher build() { | ||
checkNotNull(launcher, "p2ApplicationLauncher cannot be null"); | ||
checkNotNull(categoryFileLocation, "categoryFileLocation cannot be null"); | ||
checkNotNull(metadataRepositoryLocation, "metadataRepositoryLocation cannot be null"); | ||
requireNonNull(launcher, "p2ApplicationLauncher cannot be null"); | ||
requireNonNull(categoryFileLocation, "categoryFileLocation cannot be null"); | ||
requireNonNull(metadataRepositoryLocation, "metadataRepositoryLocation cannot be null"); | ||
return new CategoryPublisher(launcher, forkedProcessTimeoutInSeconds, additionalArgs, categoryFileLocation, | ||
metadataRepositoryLocation); | ||
} | ||
|
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); | ||
} | ||
} |