static long nextMemberId(Container container) {
   AtomicLong counter = CONTAINER_COUNTER.putIfAbsent(container.id(), new AtomicLong(-1));
   if (counter == null) {
     counter = CONTAINER_COUNTER.get(container.id());
   }
   return counter.incrementAndGet();
 }
 private String generatePathForMember(Resource child, Container parent, String desiredPath)
     throws EndpointNotFoundException {
   if (parent.hasMember(child.id())) {
     Endpoint endpoint = getResourceEndpoint(parent.id());
     ContainerTemplate parentTemplate =
         templateManagementService.findTemplateById(
             parent.id().templateId(), ContainerTemplate.class);
     if (parentTemplate == null) {
       throw new IllegalStateException("Could not find template resource '" + parent + "'");
     }
     StringBuilder builder = new StringBuilder();
     addSegment(builder, endpoint.path());
     addSegment(builder, parentTemplate.memberPath().or(""));
     addSegment(builder, IdGenerator.nextMemberId(parent));
     addSegment(builder, desiredPath);
     //			Object lastSegment = desiredPath;
     //			if(lastSegment==null) {
     //				lastSegment=IdGenerator.nextMemberId(parent);
     //			}
     //			addSegment(builder,lastSegment);
     return builder.toString();
   }
   return null;
 }