Java Code Examples for com.google.common.collect.Sets

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project ades, under directory /src/main/java/com/cloudera/science/pig/.

Source file: Combinatorial.java

  15 
vote

@Override public DataBag exec(Tuple input) throws IOException {
  try {
    DataBag output=bagFactory.newDefaultBag();
    Object o=input.get(0);
    if (!(o instanceof DataBag)) {
      throw new IOException("Expected input to be a bag, but got: " + o.getClass().getName());
    }
    DataBag inputBag=(DataBag)o;
    Set<Comparable> uniqs=Sets.newTreeSet();
    for (    Tuple t : inputBag) {
      if (t != null && t.get(0) != null) {
        uniqs.add((Comparable)t.get(0));
      }
    }
    if (uniqs.size() < arity) {
      return output;
    }
    List<Comparable> values=Lists.newArrayList(uniqs);
    Comparable[] subset=new Comparable[arity];
    process(values,subset,0,0,output);
    return output;
  }
 catch (  ExecException e) {
    throw new IOException(e);
  }
}
 

Example 2

From project airlift, under directory /bootstrap/src/test/java/io/airlift/bootstrap/.

Source file: TestLifeCycleManager.java

  15 
vote

@Test public void testModule() throws Exception {
  Module module=new Module(){
    @Override public void configure(    Binder binder){
      binder.bind(DependentBoundInstance.class).to(DependentInstanceImpl.class).in(Scopes.SINGLETON);
      binder.bind(DependentInstance.class).in(Scopes.SINGLETON);
      binder.bind(InstanceOne.class).in(Scopes.SINGLETON);
      binder.bind(InstanceTwo.class).in(Scopes.SINGLETON);
    }
  }
;
  Injector injector=Guice.createInjector(Stage.PRODUCTION,new LifeCycleModule(),module);
  LifeCycleManager lifeCycleManager=injector.getInstance(LifeCycleManager.class);
  lifeCycleManager.start();
  lifeCycleManager.stop();
  Set<String> stateLogSet=Sets.newHashSet(stateLog);
  Assert.assertEquals(stateLogSet,Sets.newHashSet("postDependentBoundInstance","postDependentInstance","postMakeOne","postMakeTwo","preDestroyTwo","preDestroyOne","preDependentInstance","preDependentBoundInstance"));
}
 

Example 3

From project android_external_guava, under directory /src/com/google/common/util/concurrent/.

Source file: SimpleTimeLimiter.java

  15 
vote

private static Set<Method> findInterruptibleMethods(Class<?> interfaceType){
  Set<Method> set=Sets.newHashSet();
  for (  Method m : interfaceType.getMethods()) {
    if (declaresInterruptedEx(m)) {
      set.add(m);
    }
  }
  return set;
}
 

Example 4

From project appdriver, under directory /android/src/com/google/android/testing/nativedriver/server/handler/.

Source file: AndroidNativeFindChildElements.java

  15 
vote

@Override public ResultType call() throws Exception {
  response=newResponse();
  List<WebElement> elements=getElement().findElements(by);
  Function<WebElement,Map<String,String>> transform=new Function<WebElement,Map<String,String>>(){
    public Map<String,String> apply(    WebElement element){
      return ImmutableMap.of("ELEMENT",getKnownElements().add(element));
    }
  }
;
  Set<Map<String,String>> elementIds=Sets.newLinkedHashSet(Iterables.transform(elements,transform));
  response.setValue(elementIds);
  return ResultType.SUCCESS;
}
 

Example 5

From project artifactory-plugin, under directory /src/main/java/org/jfrog/hudson/generic/.

Source file: GenericArtifactsDeployer.java

  15 
vote

public List<Artifact> invoke(File workspace,VirtualChannel channel) throws IOException, InterruptedException {
  Multimap<String,File> targetPathToFilesMap=buildTargetPathToFiles(workspace);
  Set<DeployDetails> artifactsToDeploy=Sets.newHashSet();
  for (  Map.Entry<String,File> entry : targetPathToFilesMap.entries()) {
    artifactsToDeploy.addAll(buildDeployDetailsFromFileEntry(entry));
  }
  ArtifactoryBuildInfoClient client=server.createArtifactoryClient(credentials.getUsername(),credentials.getPassword(),proxyConfiguration);
  try {
    deploy(client,artifactsToDeploy);
    return convertDeployDetailsToArtifacts(artifactsToDeploy);
  }
  finally {
    client.shutdown();
  }
}
 

Example 6

From project astyanax, under directory /src/main/java/com/netflix/astyanax/connectionpool/impl/.

Source file: AbstractHostPartitionConnectionPool.java

  15 
vote

@Override public synchronized void setHosts(Map<BigInteger,List<Host>> ring){
  Set<Host> hostsToRemove=Sets.newHashSet(hosts.keySet());
  for (  Map.Entry<BigInteger,List<Host>> entry : ring.entrySet()) {
    for (    Host host : entry.getValue()) {
      addHost(host,false);
      hostsToRemove.remove(host);
    }
  }
  for (  Host host : hostsToRemove) {
    removeHost(host,false);
  }
  Map<BigInteger,Collection<HostConnectionPool<CL>>> tokens=Maps.newHashMap();
  for (  Map.Entry<BigInteger,List<Host>> entry : ring.entrySet()) {
    Set<HostConnectionPool<CL>> pools=Sets.newHashSet();
    for (    Host host : entry.getValue()) {
      pools.add(getHostPool(host));
    }
    tokens.put(entry.getKey(),pools);
  }
  topology.setPools(tokens);
}
 

Example 7

From project atlas, under directory /src/main/java/com/ning/atlas/.

Source file: ActualDeployment.java

  15 
vote

public void destroy(){
  ListeningExecutorService es=MoreExecutors.listeningDecorator(Executors.newCachedThreadPool());
  List<LifecycleListener> listeners=environment.getListeners();
  startDeployment(listeners);
  log.info("beginning unwind");
  fire(Events.startUnwind,listeners);
  Set<Identity> identities=space.findAllIdentities();
  Set<Identity> to_unwind=Sets.newHashSet();
  for (  Identity identity : identities) {
    final Maybe<WhatWasDone> mwwd=space.get(identity.createChild("atlas","unwind"),WhatWasDone.class,Missing.RequireAll);
    if (mwwd.isKnown()) {
      to_unwind.add(identity);
    }
  }
  unwindAll(es,to_unwind);
  log.info("finished unwind");
  fire(Events.finishUnwind,listeners);
  finishDeployment(listeners);
  es.shutdown();
}
 

Example 8

From project atunit, under directory /atunit/src/main/java/atunit/.

Source file: AtUnit.java

  15 
vote

/** 
 * Gets all declared fields and all inherited fields.
 */
protected Set<Field> getFields(Class<?> c){
  Set<Field> fields=Sets.newHashSet(c.getDeclaredFields());
  while ((c=c.getSuperclass()) != null) {
    for (    Field f : c.getDeclaredFields()) {
      if (!Modifier.isStatic(f.getModifiers()) && !Modifier.isPrivate(f.getModifiers())) {
        fields.add(f);
      }
    }
  }
  return fields;
}
 

Example 9

From project atunit_1, under directory /src/atunit/.

Source file: AtUnit.java

  15 
vote

/** 
 * Gets all declared fields and all inherited fields.
 */
protected Set<Field> getFields(Class<?> c){
  Set<Field> fields=Sets.newHashSet(c.getDeclaredFields());
  while ((c=c.getSuperclass()) != null) {
    for (    Field f : c.getDeclaredFields()) {
      if (!Modifier.isStatic(f.getModifiers()) && !Modifier.isPrivate(f.getModifiers())) {
        fields.add(f);
      }
    }
  }
  return fields;
}
 

Example 10

From project b1-pack, under directory /cli/src/main/java/org/b1/pack/cli/.

Source file: FileTools.java

  15 
vote

public static Set<FsObject> getFsObjects(List<String> names){
  Map<List<String>,FsObject> map=createRootMap(names);
  Set<FsObject> result=Sets.newLinkedHashSet();
  for (  FsObject fsObject : map.values()) {
    addPrecedingObjects(result,fsObject,map);
    addObjectWithChildren(result,fsObject);
  }
  return result;
}
 

Example 11

From project baseunits, under directory /src/main/java/jp/xet/baseunits/time/spec/.

Source file: DayOfWeeksSpecification.java

  15 
vote

/** 
 * ?????????????????
 * @param dayOfWeek ???
 * @param dayOfWeeks ???(optional)
 * @throws IllegalArgumentException [email protected] null}?????????
 */
DayOfWeeksSpecification(DayOfWeek dayOfWeek,DayOfWeek... dayOfWeeks){
  Validate.notNull(dayOfWeek);
  Validate.noNullElements(dayOfWeeks);
  this.dayOfWeeks=Sets.newHashSet(dayOfWeeks);
  this.dayOfWeeks.add(dayOfWeek);
}
 

Example 12

From project build-info, under directory /build-info-api/src/main/java/org/jfrog/build/api/builder/.

Source file: PromotionBuilder.java

  15 
vote

public PromotionBuilder addScope(String scope){
  if (scopes == null) {
    scopes=Sets.newHashSet();
  }
  scopes.add(scope);
  return this;
}
 

Example 13

From project C-Cat, under directory /core/src/main/java/gov/llnl/ontology/mains/.

Source file: DecentralizedSearch.java

  15 
vote

public static Set<Pair<Set<String>>> readTagPairs(String tagPairFile) throws Exception {
  Set<Pair<Set<String>>> tagPairs=Sets.newHashSet();
  BufferedReader br=new BufferedReader(new FileReader(tagPairFile));
  for (String line=null; (line=br.readLine()) != null; ) {
    String[] pair=line.split("\\|");
    tagPairs.add(new Pair(readTags(pair[0]),readTags(pair[1])));
  }
  return tagPairs;
}
 

Example 14

From project c10n, under directory /core/src/ext/guice/java/c10n/guice/.

Source file: C10NModule.java

  15 
vote

private Set<URL> getPackageURLs(){
  Iterable<URL> packages=Iterables.concat(Iterables.transform(Arrays.asList(packagePrefixes),new Function<String,Set<URL>>(){
    @Override public Set<URL> apply(    String prefix){
      return ClasspathHelper.forPackage(prefix);
    }
  }
));
  return Sets.newHashSet(packages);
}
 

Example 15

From project Cafe, under directory /webapp/src/org/openqa/selenium/android/.

Source file: SessionCookieManager.java

  15 
vote

/** 
 * Gets all cookies associated to a URL.
 * @param url
 * @return A string containing comma separated cookies
 */
public Set<Cookie> getAllCookies(String url){
  Set<Cookie> cookieSet=Sets.newHashSet();
  List<String> domains;
  try {
    domains=getDomainsFromUrl(new URL(url));
  }
 catch (  MalformedURLException e) {
    throw new WebDriverException("Error while adding cookie. " + e);
  }
  for (  String domain : domains) {
    cookieSet.addAll(getCookies(domain));
  }
  return cookieSet;
}
 

Example 16

From project candlepin, under directory /src/main/java/org/candlepin/sync/.

Source file: ProductImporter.java

  15 
vote

protected final boolean hasProductChanged(Product existingProd,Product importedProd){
  if (!existingProd.getName().equals(importedProd.getName())) {
    return true;
  }
  if (existingProd.getMultiplier() != importedProd.getMultiplier()) {
    return true;
  }
  if (existingProd.getAttributes().size() != importedProd.getAttributes().size()) {
    return true;
  }
  if (Sets.intersection(existingProd.getAttributes(),importedProd.getAttributes()).size() != existingProd.getAttributes().size()) {
    return true;
  }
  if (existingProd.getProductContent().size() != importedProd.getProductContent().size()) {
    return true;
  }
  if (Sets.intersection(existingProd.getProductContent(),importedProd.getProductContent()).size() != existingProd.getProductContent().size()) {
    return true;
  }
  return false;
}
 

Example 17

From project cdk, under directory /generator/src/main/java/org/richfaces/cdk/apt/processors/.

Source file: AttributesProcessorImpl.java

  15 
vote

@Override public void processType(final BeanModelBase component,TypeElement element) throws CdkException {
  log.debug("AttributesProcessorImpl.processType");
  log.debug("  -> component = " + component);
  log.debug("  -> typeElement = " + element);
  log.debug("  -- Process XML files with standard attributes definitions.");
  log.debug("     -> sourceUtils.visitSupertypes...");
  SourceUtils sourceUtils=getSourceUtils();
  sourceUtils.visitSupertypes(element,new SuperTypeVisitor(){
    @Override public void visit(    TypeMirror type){
      String uri=type.toString() + ".xml";
      try {
        log.debug("        -> visit - " + type.toString());
        component.getAttributes().addAll(parseProperties(uri));
      }
 catch (      CdkException e) {
        log.error(e);
      }
catch (      FileNotFoundException e) {
        log.debug("No properties description found at " + uri);
      }
    }
  }
);
  log.debug("  -- Process Java files.");
  Set<BeanProperty> properties=Sets.newHashSet();
  properties.addAll(sourceUtils.getBeanPropertiesAnnotatedWith(Attribute.class,element));
  for (  BeanProperty beanProperty : properties) {
    processAttribute(beanProperty,component.getOrCreateAttribute(beanProperty.getName()));
  }
}
 

Example 18

From project Cinch, under directory /src/com/palantir/ptoss/cinch/core/.

Source file: BindingContext.java

  15 
vote

private Map<String,ObjectFieldMethod> indexBindableProperties(Function<PropertyDescriptor,Method> methodFn) throws IntrospectionException {
  final Map<ObjectFieldMethod,String> getterOfms=Maps.newHashMap();
  for (  Field field : Sets.newHashSet(bindableModels.values())) {
    BeanInfo beanInfo=Introspector.getBeanInfo(field.getType());
    PropertyDescriptor[] props=beanInfo.getPropertyDescriptors();
    for (    PropertyDescriptor descriptor : props) {
      Method method=methodFn.apply(descriptor);
      if (method == null) {
        continue;
      }
      BindableModel model=getFieldObject(field,BindableModel.class);
      getterOfms.put(new ObjectFieldMethod(model,field,method),descriptor.getName());
    }
  }
  return dotIndex(getterOfms.keySet(),ObjectFieldMethod.TO_FIELD_NAME,Functions.forMap(getterOfms));
}
 

Example 19

From project CIShell, under directory /core/org.cishell.reference/src/org/cishell/reference/service/conversion/.

Source file: DataConversionServiceImpl.java

  15 
vote

/** 
 * If the final format is of type file-ext, then append the final converter to the converter list
 * @param converters Current converter chains
 * @param outFormat Final data type
 * @return The edited converter chains
 */
private ConverterImpl[] connectValidator(ConverterImpl[] converters,String outFormat){
  Collection<ConverterImpl> newConverters=Sets.newHashSet();
  Set<String> formats=Sets.newHashSet();
  for (int i=0; i < converters.length; i++) {
    String format=(String)converters[i].getProperties().get(OUT_DATA);
    if (!formats.contains(format)) {
      String filter="(&(" + ALGORITHM_TYPE + "="+ TYPE_VALIDATOR+ ")"+ "(!("+ REMOTE+ "=*))"+ "("+ IN_DATA+ "="+ format+ ")"+ "("+ OUT_DATA+ "="+ outFormat+ "))";
      try {
        Collection<ServiceReference<AlgorithmFactory>> refs=getAFServiceReferences(filter);
        if (refs != null && refs.size() > 0) {
          for (          ServiceReference<AlgorithmFactory> ref : refs) {
            List<ServiceReference<AlgorithmFactory>> chain=Lists.newArrayList(converters[i].getConverterList());
            chain.add(ref);
            newConverters.add(ConverterImpl.createConverter(bContext,ciContext,chain));
          }
          formats.add(format);
        }
      }
 catch (      InvalidSyntaxException e) {
        e.printStackTrace();
      }
    }
  }
  return newConverters.toArray(new ConverterImpl[0]);
}
 

Example 20

From project Citizens, under directory /src/core/net/citizensnpcs/permissions/.

Source file: PermissionManager.java

  15 
vote

public static Set<CitizensGroup> getGroups(Player player){
  if (!permissionsEnabled)   return null;
  Set<CitizensGroup> groups=Sets.newHashSet();
  for (  String group : provider.getPlayerGroups(player)) {
    groups.add(new CitizensGroup(group));
  }
  return groups;
}
 

Example 21

From project closure-templates, under directory /java/src/com/google/template/soy/jssrc/internal/.

Source file: FindCalleesNotInFileVisitor.java

  15 
vote

@Override protected void visitSoyFileNode(SoyFileNode node){
  templatesInFile=Sets.newHashSet();
  for (  TemplateNode template : node.getChildren()) {
    templatesInFile.add(template.getTemplateName());
  }
  calleesNotInFile=Sets.newTreeSet();
  visitChildren(node);
}
 

Example 22

From project cloud-management, under directory /src/test/java/com/proofpoint/cloudmanagement/service/inventoryclient/.

Source file: MockInventoryServer.java

  15 
vote

private Map<String,String> systemWithWithPredicate(Predicate<Map<String,String>> predicate){
  Preconditions.checkNotNull(predicate);
  Set<Map<String,String>> filtered=Sets.filter(inventory,predicate);
  if (filtered.size() > 1) {
    throw new IllegalStateException("Too many objects matching predicate in set");
  }
  if (filtered.isEmpty()) {
    return null;
  }
  return filtered.iterator().next();
}
 

Example 23

From project Cloud9, under directory /src/test/edu/umd/cloud9/util/map/.

Source file: TMapIVTest.java

  15 
vote

@Test public void testBasic2(){
  int size=100000;
  Random r=new Random();
  TreeSet<Integer> ints=Sets.newTreeSet();
  TMapIV<String> map=new TMapIV<String>();
  for (int i=0; i < size; i++) {
    int rand=r.nextInt(size);
    if (ints.contains(rand)) {
      continue;
    }
    map.put(rand,rand + "");
    ints.add(rand);
  }
  for (  Integer rand : ints) {
    String v=map.get(rand);
    assertEquals(v,rand + "");
    assertTrue(map.containsKey(rand));
  }
  Iterator<Integer> gIter=ints.iterator();
  for (  MapIV.Entry<String> entry : map.entrySet()) {
    assertTrue(gIter.hasNext());
    assertEquals((int)gIter.next(),entry.getKey());
  }
  assertFalse(gIter.hasNext());
}
 

Example 24

From project clustermeister, under directory /provisioning/src/main/java/com/github/nethad/clustermeister/provisioning/ec2/.

Source file: AmazonConfigurationLoader.java

  15 
vote

/** 
 * Returns a set of configured  {@link Credentials}.
 * @return the configured credentials.
 */
public Set<Credentials> getConfiguredCredentials(){
  List<Object> keypairList=configuration.getList(KEYPAIRS,Collections.EMPTY_LIST);
  Map<String,Map<String,String>> keypairSpecifications=ConfigurationUtil.reduceObjectList(keypairList,"Keypairs must be specified as a list of objects.");
  Set<Credentials> credentials=Sets.newHashSetWithExpectedSize(keypairSpecifications.size());
  for (  Map.Entry<String,Map<String,String>> entry : keypairSpecifications.entrySet()) {
    String keyPairName=entry.getKey();
    Map<String,String> keyPairValues=entry.getValue();
    String user=ConfigurationUtil.getCheckedConfigValue(USER,keyPairValues,"keypair",keyPairName);
    String privateKeyPath=ConfigurationUtil.getCheckedConfigValue(PRIVATE_KEY,keyPairValues,"keypair",keyPairName);
    File privateKey=ConfigurationUtil.getCheckedFile(privateKeyPath,PRIVATE_KEY,"keypair",keyPairName);
    String publicKeyPath=keyPairValues.get(PUBLIC_KEY);
    if (publicKeyPath != null) {
      File publicKey=ConfigurationUtil.getCheckedFile(publicKeyPath,PUBLIC_KEY,"keypair",keyPairName);
      credentials.add(new KeyPairCredentials(keyPairName,user,privateKey,publicKey));
    }
 else {
      credentials.add(new AmazonConfiguredKeyPairCredentials(keyPairName,user,privateKey));
    }
  }
  return credentials;
}
 

Example 25

From project community-plugins, under directory /deployit-cli-plugins/dar-manifest-exporter/src/main/java/ext/deployit/community/cli/manifestexport/collect/.

Source file: Maps2.java

  15 
vote

/** 
 * Constructs a map that contains all unique, non-<code>null</code> values from the input map as keys. The value for each key in the returned map is the set of keys from the input map that contained that value (i.e. the key in the returned map). <p> Keys in the input map with  {@code null} values are <u>omitted</u> from thereturned map.  <p> This operation is similar to the <em>reduce</em> step in a map-reduce algorithm,  hence the name. <p> Examples: <ul> <li>{"foo": 10, "bar": 10, "baz": 20} -> {10: {"foo", "bar"}, 20: {"baz"}} <li>{"foo": 10, "bar": 15, "baz": null} -> {10: {"foo"}, 15: {"bar"}} </ul>
 * @param < K > the type of the keys
 * @param < V > the type of the values
 * @param fromMap the map containing the value/key pairs to be inverted
 * @return a map containing, for every unique (according to{@link Object#equals(Object) equals} value, an entry with thatvalue as the key and a set of all keys from the input map as the value. All entries of the input map that have  {@code null} valuesare <u>omitted</u> from the returned map.
 */
public static @Nonnull <K,V>Map<V,Set<K>> reduce(@Nonnull Map<K,V> fromMap){
  Map<V,Set<K>> inProgress=newHashMap();
  for (  Entry<K,V> entry : filterValues(fromMap,notNull()).entrySet()) {
    V value=entry.getValue();
    if (!inProgress.containsKey(value)) {
      inProgress.put(value,Sets.<K>newHashSet());
    }
    inProgress.get(value).add(entry.getKey());
  }
  return copyOf(inProgress);
}
 

Example 26

From project components-ness-httpclient, under directory /client/src/main/java/com/nesscomputing/httpclient/internal/.

Source file: MultiTrustManager.java

  15 
vote

@Override public X509Certificate[] getAcceptedIssuers(){
  final Set<X509Certificate> certificates=Sets.newHashSet();
  for (  X509TrustManager trustManager : trustManagers) {
    certificates.addAll(Arrays.asList(trustManager.getAcceptedIssuers()));
  }
  return certificates.toArray(new X509Certificate[certificates.size()]);
}
 

Example 27

From project components-ness-httpserver_1, under directory /src/main/java/com/nesscomputing/httpserver/.

Source file: AbstractJetty8HttpServer.java

  15 
vote

private void buildConnectors(final Server server){
  final Set<HttpConnector> connectors=Sets.newHashSet();
  for (  Map.Entry<String,HttpConnector> entry : getConnectors().entrySet()) {
    final String connectorName=entry.getKey();
    final HttpConnector connector=entry.getValue();
    if (connectors.contains(connector)) {
      LOG.warn("Multiple configurations for '%s', skipping",connector);
      continue;
    }
    connectors.add(connector);
    final SelectChannelConnector jettyConnector;
    if (connector.isSecure()) {
      final SslContextFactory sslContextFactory=new SslContextFactory(SslContextFactory.DEFAULT_KEYSTORE_PATH);
      if (httpServerConfig.getSSLKeystorePath() != null) {
        sslContextFactory.setKeyStoreType(httpServerConfig.getSSLKeystoreType());
        sslContextFactory.setKeyStorePath(httpServerConfig.getSSLKeystorePath());
        sslContextFactory.setKeyStorePassword(httpServerConfig.getSSLKeystorePassword());
      }
      jettyConnector=new SslSelectChannelConnector(sslContextFactory);
    }
 else {
      jettyConnector=new SelectChannelConnector();
    }
    jettyConnector.setPort(connector.getPort());
    jettyConnector.setHost(connector.getAddress());
    connector.setJettyConnector(jettyConnector);
    jettyConnector.setStatsOn(true);
    jettyConnector.setForwarded(httpServerConfig.isForwarded());
    jettyConnector.setMaxIdleTime(httpServerConfig.getMaxIdletime());
    jettyConnector.setResponseHeaderSize(httpServerConfig.getResponseHeaderSize());
    LOG.debug("Adding connector [%s] as %s",connectorName,connector);
    server.addConnector(jettyConnector);
  }
}
 

Example 28

From project core_4, under directory /impl/src/main/java/org/richfaces/context/.

Source file: BaseExtendedVisitContext.java

  15 
vote

private void initializeCollections(Collection<String> clientIds){
  this.subtreeIds=HashMultimap.create();
  this.directSubtreeIds=ArrayListMultimap.create();
  this.shortIds=new HashSet<String>();
  this.clientIds=Sets.newHashSet();
  this.proxiedClientIds=new CollectionProxy();
  this.proxiedClientIds.addAll(clientIds);
}
 

Example 29

From project cp-common-utils, under directory /src/com/clarkparsia/common/base/.

Source file: Instrumentor.java

  15 
vote

/** 
 * Return all the classes loaded into the JVM which extend from the provided class
 * @param theClass the class
 * @param < T > the base class type
 * @return all the classes extending from the parameter. An empty collection will be returned if this java agent is not installed
 */
public static <T>Collection<Class<? extends T>> instancesOf(Class<T> theClass){
  Instrumentation aInst=instrumentation();
  if (aInst == null) {
    return Sets.newHashSet();
  }
  Set<Class<? extends T>> aClasses=Sets.newHashSet();
  for (  Class<?> aCls : aInst.getAllLoadedClasses()) {
    if (theClass.isAssignableFrom(aCls)) {
      aClasses.add((Class<T>)aCls);
    }
  }
  return aClasses;
}
 

Example 30

From project cp-openrdf-utils, under directory /core/src/com/clarkparsia/openrdf/.

Source file: ExtRepository.java

  15 
vote

/** 
 * Return a graph which describes the given Resource
 * @param theResource the resource to describe
 * @return the graph which describes the URI
 */
public ExtGraphImpl describe(Resource theResource){
  Graph aGraph=new SetGraph();
  RepositoryConnection aConn=null;
  try {
    aConn=getConnection();
    aGraph.addAll(Sets.newHashSet(new IterationIterator<Statement>(getStatements(theResource,null,null))));
  }
 catch (  Exception ex) {
    LOGGER.error("There was an error doing simple describe.",ex);
  }
 finally {
    close(aConn);
  }
  return new ExtGraphImpl(aGraph);
}
 

Example 31

From project crunch, under directory /crunch/src/main/java/org/apache/crunch/.

Source file: CombineFn.java

  15 
vote

@Override public void reset(){
  if (elements == null) {
    elements=Sets.newTreeSet();
  }
 else {
    elements.clear();
  }
}
 

Example 32

From project curator, under directory /curator-recipes/src/main/java/com/netflix/curator/framework/recipes/cache/.

Source file: PathChildrenCache.java

  15 
vote

private void processChildren(List<String> children,boolean forceGetDataAndStat) throws Exception {
  List<String> fullPaths=Lists.transform(children,new Function<String,String>(){
    @Override public String apply(    String child){
      return ZKPaths.makePath(path,child);
    }
  }
);
  Set<String> removedNodes=Sets.newHashSet(currentData.keySet());
  removedNodes.removeAll(fullPaths);
  for (  String fullPath : removedNodes) {
    remove(fullPath);
  }
  for (  String name : children) {
    String fullPath=ZKPaths.makePath(path,name);
    if (forceGetDataAndStat || !currentData.containsKey(fullPath)) {
      getDataAndStat(fullPath);
    }
  }
}
 

Example 33

From project daleq, under directory /integration/src/test/java/de/brands4friends/daleq/integration/rules/.

Source file: RestrictDbRule.java

  15 
vote

@Override public Statement apply(final Statement base,final Description description){
  final Restrict restrict=description.getAnnotation(Restrict.class);
  if (restrict != null) {
    final Set<SupportedDb> ignoredDbs=Sets.newHashSet(restrict.not());
    if (ignoredDbs.contains(currentDb)) {
      logger.info("Test {} will be ignored. {}",new Object[]{description.getDisplayName(),restrict.reason()});
      return new Noop();
    }
  }
  return base;
}
 

Example 34

From project datasalt-utils, under directory /src/main/java/com/datasalt/utils/commons/count/.

Source file: Counter.java

  15 
vote

private void c(Count currentLevel,Comparable<?> o){
  currentLevel.count++;
  try {
    if (countDistinct) {
      Set<Comparable<?>> distinctSet;
      distinctSet=(Set<Comparable<?>>)currentLevel.getDistinctList();
      if (distinctSet == null) {
        distinctSet=Sets.newTreeSet();
        currentLevel.distinctList=distinctSet;
      }
      distinctSet.add(o);
    }
  }
 catch (  Exception e) {
  }
}
 

Example 35

From project eclipse-task-editor, under directory /plugins/de.sebastianbenz.task/src/de/sebastianbenz/task/resource/.

Source file: Descriptions.java

  15 
vote

public static Set<String> tagsOf(IEObjectDescription description){
  String userData=description.getUserData(TAG_KEY);
  if (userData == null || userData.length() == 0) {
    return emptySet();
  }
  String[] tags=userData.split("\\" + SEPARATOR);
  Set<String> result=Sets.newHashSetWithExpectedSize(tags.length);
  for (  String tag : tags) {
    result.add(tag);
  }
  return result;
}
 

Example 36

From project edna-rcp, under directory /org.edna.datamodel.transformations/src/org/edna/datamodel/transformations/m2m/.

Source file: Uml2XsdTransformation.java

  15 
vote

private void createIncludes(){
  final Resource sourceResource=sourceModel.eResource();
  final Iterable<Resource> resources=Iterables.filter(sourceResource.getResourceSet().getResources(),new Predicate<Resource>(){
    public boolean apply(    Resource input){
      return input.getURI().lastSegment().endsWith(".xsd") && !input.getURI().lastSegment().equals(sourceResource.getURI().lastSegment()) && !IGNORED_RESOURCES.contains(input.getURI().lastSegment());
    }
  }
);
  Set<XSDInclude> includes=Sets.newHashSet();
  for (  Resource r : resources) {
    XSDInclude include=XSDFactory.eINSTANCE.createXSDInclude();
    String path=r.getURI().lastSegment().replace(UMLResource.FILE_EXTENSION,".xsd");
    include.setSchemaLocation(path);
    includes.add(include);
  }
  targetModel.getContents().addAll(includes);
}
 

Example 37

From project elephant-twin, under directory /com.twitter.elephanttwin.lucene/src/main/java/com/twitter/elephanttwin/lucene/indexing/.

Source file: HadoopSplitDocument.java

  15 
vote

public void addKeyValue(String key,String value){
  Set<String> set=keyValueListMap.get(key);
  if (set == null) {
    set=Sets.newHashSet();
  }
  set.add(value);
  keyValueListMap.put(key,set);
}
 

Example 38

From project EMF-IncQuery, under directory /plugins/org.eclipse.viatra2.emf.incquery.tooling.generator/src/org/eclipse/viatra2/emf/incquery/tooling/generator/genmodel/.

Source file: GenModelMetamodelProviderService.java

  15 
vote

@Override public Collection<EPackage> getAllMetamodelObjects(IProject project) throws CoreException {
  Preconditions.checkArgument(project.exists() && project.hasNature(IncQueryNature.NATURE_ID),"Only works for EMF-IncQuery projects");
  Set<EPackage> referencedPackages=Sets.newLinkedHashSet();
  IncQueryGeneratorModel generatorModel=getGeneratorModel(project);
  for (  GeneratorModelReference ref : generatorModel.getGenmodels()) {
    referencedPackages.addAll(Lists.transform(ref.getGenmodel().getGenPackages(),new Function<GenPackage,EPackage>(){
      @Override public EPackage apply(      GenPackage desc){
        Preconditions.checkNotNull(desc);
        return desc.getEcorePackage();
      }
    }
));
  }
  referencedPackages.addAll(getMetamodelMap().values());
  return referencedPackages;
}