List of usage examples for com.google.common.collect ImmutableList indexOf
@Override public int indexOf(@Nullable Object object)
From source file:org.geogit.geotools.plumbing.ExportOp.java
private Iterator<SimpleFeature> alter(Iterator<SimpleFeature> plainFeatures, final ObjectId targetFeatureTypeId) { final RevFeatureType targetType = database.getFeatureType(targetFeatureTypeId); Function<SimpleFeature, SimpleFeature> alterFunction = new Function<SimpleFeature, SimpleFeature>() { @Override// w w w. j a v a 2 s .c o m public SimpleFeature apply(SimpleFeature input) { final RevFeatureType oldFeatureType; oldFeatureType = (RevFeatureType) input.getUserData().get(RevFeatureType.class); final ObjectId metadataId = oldFeatureType.getId(); if (targetType.getId().equals(metadataId)) { return input; } final RevFeature oldFeature; oldFeature = (RevFeature) input.getUserData().get(RevFeature.class); ImmutableList<PropertyDescriptor> oldAttributes = oldFeatureType.sortedDescriptors(); ImmutableList<PropertyDescriptor> newAttributes = targetType.sortedDescriptors(); ImmutableList<Optional<Object>> oldValues = oldFeature.getValues(); List<Optional<Object>> newValues = Lists.newArrayList(); for (int i = 0; i < newAttributes.size(); i++) { int idx = oldAttributes.indexOf(newAttributes.get(i)); if (idx != -1) { Optional<Object> oldValue = oldValues.get(idx); newValues.add(oldValue); } else { newValues.add(Optional.absent()); } } RevFeature newFeature = RevFeature.build(ImmutableList.copyOf(newValues)); FeatureBuilder featureBuilder = new FeatureBuilder(targetType); SimpleFeature feature = (SimpleFeature) featureBuilder.build(input.getID(), newFeature); return feature; } }; return Iterators.transform(plainFeatures, alterFunction); }
From source file:org.locationtech.geogig.geotools.plumbing.ExportOp.java
private Iterator<SimpleFeature> alter(Iterator<SimpleFeature> plainFeatures, final ObjectId targetFeatureTypeId) { final RevFeatureType targetType = objectDatabase().getFeatureType(targetFeatureTypeId); Function<SimpleFeature, SimpleFeature> alterFunction = new Function<SimpleFeature, SimpleFeature>() { @Override//w w w. j a v a2 s . c o m public SimpleFeature apply(SimpleFeature input) { final RevFeatureType oldFeatureType; oldFeatureType = (RevFeatureType) input.getUserData().get(RevFeatureType.class); final ObjectId metadataId = oldFeatureType.getId(); if (targetType.getId().equals(metadataId)) { return input; } final RevFeature oldFeature; oldFeature = (RevFeature) input.getUserData().get(RevFeature.class); ImmutableList<PropertyDescriptor> oldAttributes = oldFeatureType.sortedDescriptors(); ImmutableList<PropertyDescriptor> newAttributes = targetType.sortedDescriptors(); ImmutableList<Optional<Object>> oldValues = oldFeature.getValues(); List<Optional<Object>> newValues = Lists.newArrayList(); for (int i = 0; i < newAttributes.size(); i++) { int idx = oldAttributes.indexOf(newAttributes.get(i)); if (idx != -1) { Optional<Object> oldValue = oldValues.get(idx); newValues.add(oldValue); } else { newValues.add(Optional.absent()); } } RevFeature newFeature = RevFeatureImpl.build(ImmutableList.copyOf(newValues)); FeatureBuilder featureBuilder = new FeatureBuilder(targetType); SimpleFeature feature = (SimpleFeature) featureBuilder.build(input.getID(), newFeature); return feature; } }; return Iterators.transform(plainFeatures, alterFunction); }
From source file:org.locationtech.geogig.geotools.plumbing.ImportOp.java
/** * Translates a feature pointed by a node from its original feature type to a given one, using * values from those attributes that exist in both original and destination feature type. New * attributes are populated with null values * /*from w w w . j a va2 s . co m*/ * @param node The node that points to the feature. No checking is performed to ensure the node * points to a feature instead of other type * @param featureType the destination feature type * @return a feature with the passed feature type and data taken from the input feature */ private Feature alter(NodeRef node, RevFeatureType featureType) { RevFeature oldFeature = command(RevObjectParse.class).setObjectId(node.objectId()).call(RevFeature.class) .get(); RevFeatureType oldFeatureType; oldFeatureType = command(RevObjectParse.class).setObjectId(node.getMetadataId()).call(RevFeatureType.class) .get(); ImmutableList<PropertyDescriptor> oldAttributes = oldFeatureType.sortedDescriptors(); ImmutableList<PropertyDescriptor> newAttributes = featureType.sortedDescriptors(); ImmutableList<Optional<Object>> oldValues = oldFeature.getValues(); List<Optional<Object>> newValues = Lists.newArrayList(); for (int i = 0; i < newAttributes.size(); i++) { int idx = oldAttributes.indexOf(newAttributes.get(i)); if (idx != -1) { Optional<Object> oldValue = oldValues.get(idx); newValues.add(oldValue); } else { newValues.add(Optional.absent()); } } RevFeature newFeature = RevFeatureImpl.build(ImmutableList.copyOf(newValues)); FeatureBuilder featureBuilder = new FeatureBuilder(featureType); Feature feature = featureBuilder.build(node.name(), newFeature); return feature; }
From source file:com.siemens.sw360.portal.portlets.moderation.ModerationPortlet.java
private void renderNextModeration(RenderRequest request, RenderResponse response, final User user, String sessionMessage, ModerationService.Iface client, ModerationRequest moderationRequest) throws IOException, PortletException, TException { if (ACTION_CANCEL.equals(request.getParameter(ACTION))) { SessionMessages.add(request, "request_processed", sessionMessage); renderStandardView(request, response); return;//from w w w . ja va 2 s. co m } List<ModerationRequest> requestsByModerator = client.getRequestsByModerator(user); ImmutableList<ModerationRequest> openModerationRequests = FluentIterable.from(requestsByModerator) .filter(new Predicate<ModerationRequest>() { @Override public boolean apply(ModerationRequest input) { return ModerationState.PENDING.equals(input.getModerationState()); } }).toList(); Collections.sort(openModerationRequests, compareByTimeStamp()); int nextIndex = openModerationRequests.indexOf(moderationRequest) + 1; if (nextIndex < openModerationRequests.size()) { sessionMessage += " You have assigned yourself to this moderation request."; SessionMessages.add(request, "request_processed", sessionMessage); renderEditViewForId(request, response, openModerationRequests.get(nextIndex).getId()); } else { FluentIterable<ModerationRequest> requestsInProgressAndAssignedToMe = FluentIterable .from(requestsByModerator).filter(new Predicate<ModerationRequest>() { @Override public boolean apply(ModerationRequest input) { return ModerationState.INPROGRESS.equals(input.getModerationState()) && user.getEmail().equals(input.getReviewer()); } }); if (requestsInProgressAndAssignedToMe.first().isPresent()) { sessionMessage += " You have returned to your first open request."; SessionMessages.add(request, "request_processed", sessionMessage); renderEditViewForId(request, response, Collections.min(requestsInProgressAndAssignedToMe.toList(), compareByTimeStamp()).getId()); } else { sessionMessage += " You have no open Requests."; SessionMessages.add(request, "request_processed", sessionMessage); renderStandardView(request, response); } } }
From source file:retrofit.processor.EclipseHack.java
private void reorderProperties(TypeElement type, List<RetrofitProcessor.Property> properties) { PropertyOrderer propertyOrderer = getPropertyOrderer(type); if (propertyOrderer == null) { return;/*from w ww . j av a 2 s . c om*/ } final ImmutableList<String> order; try { order = propertyOrderer.determinePropertyOrder(); } catch (IOException e) { processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, e.toString()); return; } // We expect that all the properties will be found, but if not then we won't try reordering. boolean allFound = true; for (RetrofitProcessor.Property property : properties) { allFound &= order.contains(property.getGetter()); } if (allFound) { // We successfully found the abstract methods corresponding to all the properties, so now // reorder the List<Property> to reflect the order of the methods. Comparator<RetrofitProcessor.Property> comparator = new Comparator<RetrofitProcessor.Property>() { @Override public int compare(RetrofitProcessor.Property a, RetrofitProcessor.Property b) { String aName = a.getGetter(); String bName = b.getGetter(); return order.indexOf(aName) - order.indexOf(bName); } }; Collections.sort(properties, comparator); } }
From source file:auto.json.processor.EclipseHack.java
private void reorderProperties(TypeElement type, List<AutoJsonProcessor.Property> properties) { PropertyOrderer propertyOrderer = getPropertyOrderer(type); if (propertyOrderer == null) { return;/* w w w . j a v a 2s.c o m*/ } final ImmutableList<String> order; try { order = propertyOrderer.determinePropertyOrder(); } catch (IOException e) { processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, e.toString()); return; } // We expect that all the properties will be found, but if not then we won't try reordering. boolean allFound = true; for (AutoJsonProcessor.Property property : properties) { allFound &= order.contains(property.getGetter()); } if (allFound) { // We successfully found the abstract methods corresponding to all the properties, so now // reorder the List<Property> to reflect the order of the methods. Comparator<AutoJsonProcessor.Property> comparator = new Comparator<AutoJsonProcessor.Property>() { @Override public int compare(AutoJsonProcessor.Property a, AutoJsonProcessor.Property b) { String aName = a.getGetter(); String bName = b.getGetter(); return order.indexOf(aName) - order.indexOf(bName); } }; Collections.sort(properties, comparator); } }
From source file:auto.cursor.processor.EclipseHack.java
private void reorderProperties(TypeElement type, List<AutoCursorProcessor.Property> properties) { PropertyOrderer propertyOrderer = getPropertyOrderer(type); if (propertyOrderer == null) { return;/* ww w . j a v a2 s . co m*/ } final ImmutableList<String> order; try { order = propertyOrderer.determinePropertyOrder(); } catch (IOException e) { processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, e.toString()); return; } // We expect that all the properties will be found, but if not then we won't try reordering. boolean allFound = true; for (AutoCursorProcessor.Property property : properties) { allFound &= order.contains(property.getGetter()); } if (allFound) { // We successfully found the abstract methods corresponding to all the properties, so now // reorder the List<Property> to reflect the order of the methods. Comparator<AutoCursorProcessor.Property> comparator = new Comparator<AutoCursorProcessor.Property>() { @Override public int compare(AutoCursorProcessor.Property a, AutoCursorProcessor.Property b) { String aName = a.getGetter(); String bName = b.getGetter(); return order.indexOf(aName) - order.indexOf(bName); } }; Collections.sort(properties, comparator); } }
From source file:auto.parcel.processor.EclipseHack.java
private void reorderProperties(TypeElement type, List<AutoParcelProcessor.Property> properties) { PropertyOrderer propertyOrderer = getPropertyOrderer(type); if (propertyOrderer == null) { return;/* ww w .jav a 2 s. c om*/ } final ImmutableList<String> order; try { order = propertyOrderer.determinePropertyOrder(); } catch (IOException e) { processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, e.toString()); return; } // We expect that all the properties will be found, but if not then we won't try reordering. boolean allFound = true; for (AutoParcelProcessor.Property property : properties) { allFound &= order.contains(property.getGetter()); } if (allFound) { // We successfully found the abstract methods corresponding to all the properties, so now // reorder the List<Property> to reflect the order of the methods. Comparator<AutoParcelProcessor.Property> comparator = new Comparator<AutoParcelProcessor.Property>() { @Override public int compare(AutoParcelProcessor.Property a, AutoParcelProcessor.Property b) { String aName = a.getGetter(); String bName = b.getGetter(); return order.indexOf(aName) - order.indexOf(bName); } }; Collections.sort(properties, comparator); } }
From source file:retroweibo.processor.EclipseHack.java
private void reorderProperties(TypeElement type, List<RetroWeiboProcessor.Property> properties) { PropertyOrderer propertyOrderer = getPropertyOrderer(type); if (propertyOrderer == null) { return;/*from w w w . j a v a2s . c o m*/ } final ImmutableList<String> order; try { order = propertyOrderer.determinePropertyOrder(); } catch (IOException e) { processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, e.toString()); return; } // We expect that all the properties will be found, but if not then we won't try reordering. boolean allFound = true; for (RetroWeiboProcessor.Property property : properties) { allFound &= order.contains(property.getGetter()); } if (allFound) { // We successfully found the abstract methods corresponding to all the properties, so now // reorder the List<Property> to reflect the order of the methods. Comparator<RetroWeiboProcessor.Property> comparator = new Comparator<RetroWeiboProcessor.Property>() { @Override public int compare(RetroWeiboProcessor.Property a, RetroWeiboProcessor.Property b) { String aName = a.getGetter(); String bName = b.getGetter(); return order.indexOf(aName) - order.indexOf(bName); } }; Collections.sort(properties, comparator); } }
From source file:retrofacebook.processor.EclipseHack.java
private void reorderProperties(TypeElement type, List<RetroFacebookProcessor.Property> properties) { PropertyOrderer propertyOrderer = getPropertyOrderer(type); if (propertyOrderer == null) { return;/* w ww .j a va 2 s . c o m*/ } final ImmutableList<String> order; try { order = propertyOrderer.determinePropertyOrder(); } catch (IOException e) { processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, e.toString()); return; } // We expect that all the properties will be found, but if not then we won't try reordering. boolean allFound = true; for (RetroFacebookProcessor.Property property : properties) { allFound &= order.contains(property.getGetter()); } if (allFound) { // We successfully found the abstract methods corresponding to all the properties, so now // reorder the List<Property> to reflect the order of the methods. Comparator<RetroFacebookProcessor.Property> comparator = new Comparator<RetroFacebookProcessor.Property>() { @Override public int compare(RetroFacebookProcessor.Property a, RetroFacebookProcessor.Property b) { String aName = a.getGetter(); String bName = b.getGetter(); return order.indexOf(aName) - order.indexOf(bName); } }; Collections.sort(properties, comparator); } }