All Downloads are FREE. Search and download functionalities are using the official Maven repository.

it.xsemantics.runtime.caching.util.XsemanticsCacheUtils Maven / Gradle / Ivy

There is a newer version: 1.12.1
Show newest version
package it.xsemantics.runtime.caching.util;

import com.google.common.collect.Iterables;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.xtext.xbase.lib.Conversions;
import org.eclipse.xtext.xbase.lib.Functions.Function2;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.Pair;

/**
 * Utility functions for caching.
 * 
 * @author Lorenzo Bettini
 * 
 * @since 1.8
 */
@SuppressWarnings("all")
public class XsemanticsCacheUtils {
  public Resource getResource(final Object... elements) {
    Iterable _filter = Iterables.filter(((Iterable)Conversions.doWrapArray(elements)), EObject.class);
    EObject _head = IterableExtensions.head(_filter);
    Resource _eResource = null;
    if (_head!=null) {
      _eResource=_head.eResource();
    }
    return _eResource;
  }
  
  public Object getKeys(final Object... elements) {
    final Function2 _function = new Function2() {
      @Override
      public Object apply(final Object p1, final Object p2) {
        return Pair.of(p1, p2);
      }
    };
    return IterableExtensions.reduce(((Iterable)Conversions.doWrapArray(elements)), _function);
  }
}