本文整理汇总了Java中org.eclipse.xtext.xbase.lib.ListExtensions.sortInplaceBy方法的典型用法代码示例。如果您正苦于以下问题:Java ListExtensions.sortInplaceBy方法的具体用法?Java ListExtensions.sortInplaceBy怎么用?Java ListExtensions.sortInplaceBy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.xtext.xbase.lib.ListExtensions
的用法示例。
在下文中一共展示了ListExtensions.sortInplaceBy方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeTokenFile
import org.eclipse.xtext.xbase.lib.ListExtensions; //导入方法依赖的package包/类
public void writeTokenFile(PrintWriter out) throws IOException {
List<Map.Entry<Integer, String>> entries = Lists.newArrayList(getTokenDefMap().entrySet());
ListExtensions.sortInplaceBy(entries, new Functions.Function1<Map.Entry<Integer, String>, String>() {
@Override
public String apply(Map.Entry<Integer, String> p) {
return p.getValue();
}
});
for(Map.Entry<Integer, String> entry: entries) {
out.print(entry.getValue());
out.print('=');
out.println(entry.getKey());
}
out.close();
}
示例2: doTestResource
import org.eclipse.xtext.xbase.lib.ListExtensions; //导入方法依赖的package包/类
protected void doTestResource(String platformPath, String... packageNames) {
Resource resource = resourceSet.getResource(URI.createPlatformPluginURI(platformPath, false), true);
assertNotNull(resource);
assertEquals(1, resource.getContents().size());
EObject obj = resource.getContents().get(0);
if (obj instanceof EPackage) {
assertEquals(packageNames[0], ((EPackage) obj).getName());
} else if (obj instanceof GenModel) {
GenModel model = (GenModel) obj;
List<GenPackage> packages = Lists.newArrayList(model.getGenPackages());
assertEquals(packageNames.length, packages.size());
ListExtensions.sortInplaceBy(packages, new Functions.Function1<GenPackage, String>() {
@Override
public String apply(GenPackage p) {
return p.getEcorePackage().getName();
}
});
List<String> packageNamesList = Arrays.asList(packageNames);
Collections.sort(packageNamesList);
for(int i = 0; i < packageNamesList.size(); i++) {
assertEquals(packageNamesList.get(i), packages.get(i).getEcorePackage().getName());
}
IStatus status = model.validate();
assertTrue(printLeafs(status), status.isOK());
EObject orig = EcoreUtil.copy(obj);
((GenModel) obj).reconcile();
if (!EcoreUtil.equals(orig, obj)) {
Predicate<EStructuralFeature> ignoreContainer = new Predicate<EStructuralFeature>() {
@Override
public boolean apply(EStructuralFeature f) {
if (f instanceof EReference) {
EReference casted = (EReference) f;
return !casted.isContainment();
}
return false;
}
};
String origAsString = EmfFormatter.objToStr(orig, ignoreContainer);
String newAsString = EmfFormatter.objToStr(obj, ignoreContainer);
throw new ComparisonFailure("Reconcile changed model", origAsString, newAsString);
}
} else {
fail("Unexpected root element type: " + obj.eClass().getName());
}
}