/** * Verifies that Annotations created by merging {@code annotations} is equal to actual * Annotations. * * @param actual Annotations to check * @param annotations */ private static void assertAnnotationsEquals( Annotations actual, SparseAnnotations... annotations) { SparseAnnotations expected = DefaultAnnotations.builder().build(); for (SparseAnnotations a : annotations) { expected = DefaultAnnotations.union(expected, a); } assertEquals(expected.keys(), actual.keys()); for (String key : expected.keys()) { assertEquals(expected.value(key), actual.value(key)); } }
/** * Generates an annotation from an existing annotation and DeviceConfig. * * @param bdc the device config entity from network config * @param an the annotation * @return annotation combining both sources */ public static SparseAnnotations combine(BasicDeviceConfig bdc, SparseAnnotations an) { DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder(); if (bdc.driver() != an.value(AnnotationKeys.DRIVER)) { newBuilder.set(AnnotationKeys.DRIVER, bdc.driver()); } if (bdc.name() != null) { newBuilder.set(AnnotationKeys.NAME, bdc.name()); } if (bdc.latitude() != DEFAULT_COORD) { newBuilder.set(AnnotationKeys.LATITUDE, Double.toString(bdc.latitude())); } if (bdc.longitude() != DEFAULT_COORD) { newBuilder.set(AnnotationKeys.LONGITUDE, Double.toString(bdc.longitude())); } if (bdc.rackAddress() != null) { newBuilder.set(AnnotationKeys.RACK_ADDRESS, bdc.rackAddress()); } if (bdc.owner() != null) { newBuilder.set(AnnotationKeys.OWNER, bdc.owner()); } DefaultAnnotations newAnnotations = newBuilder.build(); return DefaultAnnotations.union(an, newAnnotations); }