use of java.util.IdentityHashMap in project robovm by robovm.
the class IdentityHashMapTest method test_keySet.
/**
* java.util.IdentityHashMap#keySet()
*/
public void test_keySet() {
// Test for method java.util.Set java.util.IdentityHashMap.keySet()
Set s = hm.keySet();
assertTrue("Returned set of incorrect size()", s.size() == hm.size());
for (int i = 0; i < objArray.length; i++) {
assertTrue("Returned set does not contain all keys", s.contains(objArray2[i]));
}
IdentityHashMap m = new IdentityHashMap();
m.put(null, "test");
assertTrue("Failed with null key", m.keySet().contains(null));
assertNull("Failed with null key", m.keySet().iterator().next());
Map map = new IdentityHashMap(101);
map.put(new Integer(1), "1");
map.put(new Integer(102), "102");
map.put(new Integer(203), "203");
Iterator it = map.keySet().iterator();
Integer remove1 = (Integer) it.next();
it.hasNext();
it.remove();
Integer remove2 = (Integer) it.next();
it.remove();
ArrayList list = new ArrayList(Arrays.asList(new Integer[] { new Integer(1), new Integer(102), new Integer(203) }));
list.remove(remove1);
list.remove(remove2);
assertTrue("Wrong result", it.next().equals(list.get(0)));
assertEquals("Wrong size", 1, map.size());
assertTrue("Wrong contents", map.keySet().iterator().next().equals(list.get(0)));
Map map2 = new IdentityHashMap(101);
map2.put(new Integer(1), "1");
map2.put(new Integer(4), "4");
Iterator it2 = map2.keySet().iterator();
Integer remove3 = (Integer) it2.next();
Integer next;
if (remove3.intValue() == 1)
next = new Integer(4);
else
next = new Integer(1);
it2.hasNext();
it2.remove();
assertTrue("Wrong result 2", it2.next().equals(next));
assertEquals("Wrong size 2", 1, map2.size());
assertTrue("Wrong contents 2", map2.keySet().iterator().next().equals(next));
}
use of java.util.IdentityHashMap in project sonatype-aether by sonatype.
the class DefaultDeployer method deploy.
private DeployResult deploy(SyncContext syncContext, RepositorySystemSession session, DeployRequest request) throws DeploymentException {
DeployResult result = new DeployResult(request);
RequestTrace trace = DefaultRequestTrace.newChild(request.getTrace(), request);
RemoteRepository repository = request.getRepository();
RepositoryConnector connector;
try {
connector = remoteRepositoryManager.getRepositoryConnector(session, repository);
} catch (NoRepositoryConnectorException e) {
throw new DeploymentException("Failed to deploy artifacts/metadata: " + e.getMessage(), e);
}
List<MetadataGenerator> generators = getMetadataGenerators(session, request);
try {
List<ArtifactUpload> artifactUploads = new ArrayList<ArtifactUpload>();
List<MetadataUpload> metadataUploads = new ArrayList<MetadataUpload>();
IdentityHashMap<Metadata, Object> processedMetadata = new IdentityHashMap<Metadata, Object>();
EventCatapult catapult = new EventCatapult(session, trace, repository, repositoryEventDispatcher);
List<Artifact> artifacts = new ArrayList<Artifact>(request.getArtifacts());
List<Metadata> metadatas = Utils.prepareMetadata(generators, artifacts);
syncContext.acquire(artifacts, Utils.combine(request.getMetadata(), metadatas));
for (Metadata metadata : metadatas) {
upload(metadataUploads, session, metadata, repository, connector, catapult);
processedMetadata.put(metadata, null);
}
for (int i = 0; i < artifacts.size(); i++) {
Artifact artifact = artifacts.get(i);
for (MetadataGenerator generator : generators) {
artifact = generator.transformArtifact(artifact);
}
artifacts.set(i, artifact);
artifactUploads.add(new ArtifactUploadEx(artifact, artifact.getFile(), catapult));
}
connector.put(artifactUploads, null);
for (ArtifactUpload upload : artifactUploads) {
if (upload.getException() != null) {
throw new DeploymentException("Failed to deploy artifacts: " + upload.getException().getMessage(), upload.getException());
}
result.addArtifact(upload.getArtifact());
}
metadatas = Utils.finishMetadata(generators, artifacts);
syncContext.acquire(null, metadatas);
for (Metadata metadata : metadatas) {
upload(metadataUploads, session, metadata, repository, connector, catapult);
processedMetadata.put(metadata, null);
}
for (Metadata metadata : request.getMetadata()) {
if (!processedMetadata.containsKey(metadata)) {
upload(metadataUploads, session, metadata, repository, connector, catapult);
processedMetadata.put(metadata, null);
}
}
connector.put(null, metadataUploads);
for (MetadataUpload upload : metadataUploads) {
if (upload.getException() != null) {
throw new DeploymentException("Failed to deploy metadata: " + upload.getException().getMessage(), upload.getException());
}
result.addMetadata(upload.getMetadata());
}
} finally {
connector.close();
}
return result;
}
use of java.util.IdentityHashMap in project sonatype-aether by sonatype.
the class NearestVersionConflictResolverTest method testViolationOfHardConstraintFallsBackToNearestSeenNotFirstSeen.
@Test
public void testViolationOfHardConstraintFallsBackToNearestSeenNotFirstSeen() throws Exception {
// root
// +- x:1
// +- a:1
// | \- b:1
// | \- x:3
// +- c:1
// | \- x:2
// \- d:1
// \- e:1
// \- x:[2,) # forces rejection of x:1, should fallback to nearest and not first-seen, i.e. x:2 and not x:3
DependencyNode x1 = builder.artifactId("x").version("1").build();
DependencyNode x2 = builder.artifactId("x").version("2").build();
DependencyNode x3 = builder.artifactId("x").version("3").build();
DependencyNode x2r = builder.artifactId("x").version("2").range("[2,)").build();
DependencyNode b = builder.artifactId("b").version("1").build();
b.getChildren().add(x3);
DependencyNode a = builder.artifactId("a").build();
a.getChildren().add(b);
DependencyNode c = builder.artifactId("c").build();
c.getChildren().add(x2);
DependencyNode e = builder.artifactId("e").build();
e.getChildren().add(x2r);
DependencyNode d = builder.artifactId("d").build();
d.getChildren().add(e);
DependencyNode root = builder.artifactId(null).build();
root.getChildren().add(x1);
root.getChildren().add(a);
root.getChildren().add(c);
root.getChildren().add(d);
Map<DependencyNode, Object> conflictIds = new IdentityHashMap<DependencyNode, Object>();
conflictIds.put(x1, "x");
conflictIds.put(x2, "x");
conflictIds.put(x3, "x");
conflictIds.put(x2r, "x");
conflictIds.put(a, "a");
conflictIds.put(b, "b");
conflictIds.put(c, "c");
conflictIds.put(d, "d");
conflictIds.put(e, "e");
context.put(TransformationContextKeys.CONFLICT_IDS, conflictIds);
NearestVersionConflictResolver transformer = new NearestVersionConflictResolver();
root = transformer.transformGraph(root, context);
List<DependencyNode> trail = find(root, "x");
assertEquals(3, trail.size());
assertSame(x2, trail.get(0));
}
use of java.util.IdentityHashMap in project sonatype-aether by sonatype.
the class NearestVersionConflictResolverTest method testConflictGroupCompletelyDroppedFromResolvedTree.
@Test
public void testConflictGroupCompletelyDroppedFromResolvedTree() throws Exception {
// root
// +- a:1
// | \- b:1
// | \- c:1 # conflict group c will completely vanish from resolved tree
// \- b:2
DependencyNode a = builder.artifactId("a").version("1").build();
DependencyNode b1 = builder.artifactId("b").version("1").build();
DependencyNode b2 = builder.artifactId("b").version("2").build();
DependencyNode c = builder.artifactId("c").version("1").build();
b1.getChildren().add(c);
a.getChildren().add(b1);
DependencyNode root = builder.artifactId(null).build();
root.getChildren().add(a);
root.getChildren().add(b2);
Map<DependencyNode, Object> conflictIds = new IdentityHashMap<DependencyNode, Object>();
conflictIds.put(a, "a");
conflictIds.put(b1, "b");
conflictIds.put(b2, "b");
conflictIds.put(c, "c");
context.put(TransformationContextKeys.CONFLICT_IDS, conflictIds);
NearestVersionConflictResolver transformer = new NearestVersionConflictResolver();
root = transformer.transformGraph(root, context);
assertEquals(2, root.getChildren().size());
assertSame(a, root.getChildren().get(0));
assertSame(b2, root.getChildren().get(1));
assertTrue(a.getChildren().isEmpty());
assertTrue(b2.getChildren().isEmpty());
}
use of java.util.IdentityHashMap in project sonatype-aether by sonatype.
the class NearestVersionConflictResolverTest method testNearestSoftVersionPrunedByFartherRange.
@Test
public void testNearestSoftVersionPrunedByFartherRange() throws Exception {
// root
// +- a:1
// | \- c:2
// \- b:1
// \- c:[1]
DependencyNode a = builder.artifactId("a").version("1").build();
DependencyNode b = builder.artifactId("b").version("1").build();
DependencyNode c1 = builder.artifactId("c").version("1").range("[1]").build();
DependencyNode c2 = builder.artifactId("c").version("2").build();
a.getChildren().add(c2);
b.getChildren().add(c1);
DependencyNode root = builder.artifactId(null).build();
root.getChildren().add(a);
root.getChildren().add(b);
Map<DependencyNode, Object> conflictIds = new IdentityHashMap<DependencyNode, Object>();
conflictIds.put(a, "a");
conflictIds.put(b, "b");
conflictIds.put(c1, "c");
conflictIds.put(c2, "c");
context.put(TransformationContextKeys.CONFLICT_IDS, conflictIds);
NearestVersionConflictResolver transformer = new NearestVersionConflictResolver();
root = transformer.transformGraph(root, context);
assertEquals(2, root.getChildren().size());
assertSame(a, root.getChildren().get(0));
assertSame(b, root.getChildren().get(1));
assertTrue(a.getChildren().isEmpty());
assertEquals(1, b.getChildren().size());
}
Aggregations