Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2011.2012 Frank Appel and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: Frank Appel - initial API and implementation Holger Staudacher - ongoing development /
 
 package com.eclipsesource.jaxrs.publisher.internal;
 
 import java.util.*;
 
 import  org.osgi.framework.BundleContext;
 import  org.osgi.framework.ServiceReference;
 
 
 public class ServiceContainer<S> {
 
   private final Set<ServiceHolder<S>> services;
   private final BundleContext bundleContext;
 
   ServiceContainer( BundleContext bundleContext ) {
     this. = bundleContext;
     this. = new HashSet<ServiceHolder<S>>();
   }
 
   ServiceHolder<S> add( S service ) {
     return addservicenull );
   }
 
   ServiceHolder<S> add( ServiceReference<S> reference ) {
     return add.getService( reference ), reference );
   }
 
   void remove( S service ) {
     .removefindservice ) );
   }
 
   @SuppressWarnings"unchecked" )
   ServiceHolder<S>[] getServices() {
     Set<ServiceHolder<S>> result = new HashSet<ServiceHolder<S>>();
     Iterator<ServiceHolder<S>> iterator = .iterator();
     whileiterator.hasNext() ) {
       result.additerator.next() );
     }
     return result.toArraynew ServiceHolderresult.size() ]);
   }
 
   ServiceHolder<S> find( S service ) {
     Finder<S> finder = new Finder<S>();
     return finder.findServiceHolderservice );
   }
 
   void clear() {
     .clear();
   }
 
   int size() {
     return .size();
   }
 
   private ServiceHolder<S> add( S service, ServiceReference<S> reference ) {
     ServiceHolder<S> result = findservice );
     ifnotFoundresult ) ) {
       result = new ServiceHolder<S>( servicereference );
       .addresult );
     } else ifreferenceIsMissingreferenceresult ) ) {
       result.setServiceReferencereference );
     }
     return result;
   }
 
   private boolean notFoundServiceHolder<S> result ) {
     return result == null;
   }
 
   private boolean referenceIsMissing( ServiceReference<S> referenceServiceHolder<S> result ) {
     return reference != null && result.getReference() == null;
   }
 
   static class ServiceHolder<S> {
   
     private ServiceReference<S> serviceReference;
     private final S service;
   
      ServiceHolder( S service, ServiceReference<S> serviceReference ) {
       this. = service;
       this. = serviceReference;
     }
   
     S getService() {
       return ;
     }
   
     ServiceReference<S> getReference() {
       return ;
    }
  
    void setServiceReference( ServiceReference<S> serviceReference ) {
      this. = serviceReference;
    }
  }
  static class Finder<S> {
  
    ServiceHolder<S> findServiceHolder( S serviceSet<ServiceHolder<S>> collection ) {
      Iterator<ServiceHolder<S>> iterator = collection.iterator();
      ServiceHolder<S> result = null;
      whileiterator.hasNext() ) {
        ServiceHolder<S> serviceHolder = iterator.next();
        S found = serviceHolder.getService();
        ifservice.equalsfound ) ) {
          result = serviceHolder;
        }
      }
      return result;
    }
  }
New to GrepCode? Check out our FAQ X