com.google.common.collect.Collections2#transform ( )源码实例Demo

下面列出了com.google.common.collect.Collections2#transform ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: tajo   文件: TypeProtobufEncoder.java
@Override
public void visitRecord(Record record) {
  super.visitRecord(record);

  Collection<QualifiedIdentifierProto> field_names =
      Collections2.transform(record.fields(), new Function<Field, QualifiedIdentifierProto>() {
    @Override
    public QualifiedIdentifierProto apply(@Nullable Field field) {
      return field.name().getProto();
    }
  });

  builder
      .addElements(TypeElement.newBuilder()
          .setChildNum(record.size())
          .addAllFieldNames(field_names)
          .setKind(RECORD));
}
 
源代码2 项目: registry   文件: SchemaRegistryModule.java
private Collection<? extends SchemaProvider> getSchemaProviders() {
    Collection<Map<String, Object>> schemaProviders = (Collection<Map<String, Object>>) config.get(SCHEMA_PROVIDERS);
    if (schemaProviders == null || schemaProviders.isEmpty()) {
        throw new IllegalArgumentException("No [" + SCHEMA_PROVIDERS + "] property is configured in schema registry configuration file.");
    }

    return Collections2.transform(schemaProviders, new Function<Map<String, Object>, SchemaProvider>() {
        @Nullable
        @Override
        public SchemaProvider apply(@Nullable Map<String, Object> schemaProviderConfig) {
            String className = (String) schemaProviderConfig.get("providerClass");
            if (className == null || className.isEmpty()) {
                throw new IllegalArgumentException("Schema provider class name must be non empty, Invalid provider class name [" + className + "]");
            }
            try {
                SchemaProvider schemaProvider = (SchemaProvider) Class.forName(className, true, Thread.currentThread().getContextClassLoader()).newInstance();
                schemaProvider.init(schemaProviderConfig);
                return schemaProvider;
            } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
                LOG.error("Error encountered while loading SchemaProvider [{}] ", className, e);
                throw new IllegalArgumentException(e);
            }
        }
    });
}
 
源代码3 项目: intellij   文件: BlazeCommandNameTest.java
@Test
public void userCommandNamesShouldBecomeKnown() {
  Collection<String> knownCommandStrings =
      Collections2.transform(
          BlazeCommandName.knownCommands(),
          new Function<BlazeCommandName, String>() {
            @Nullable
            @Override
            public String apply(BlazeCommandName input) {
              return input.toString();
            }
          });
  assertThat(knownCommandStrings).doesNotContain("user-command");
  BlazeCommandName userCommand = BlazeCommandName.fromString("user-command");
  assertThat(BlazeCommandName.knownCommands()).contains(userCommand);
}
 
源代码4 项目: bgpcep   文件: ParserToSalTest.java
private static Collection<byte[]> fixMessages(final Collection<byte[]> bgpMessages) {
    return Collections2.transform(bgpMessages, input -> {
        final byte[] ret = new byte[input.length + 1];
        // ff
        ret[0] = -1;
        System.arraycopy(input, 0, ret, 1, input.length);
        return ret;
    });
}
 
源代码5 项目: emodb   文件: QueueScanWorkflow.java
@Override
public void renewScanRangeTasks(Collection<ScanRangeTask> tasks, Duration ttl) {
    if (tasks.isEmpty()) {
        return;
    }

    Collection<String> messageIds = Collections2.transform(tasks, new Function<ScanRangeTask, String>() {
        @Override
        public String apply(ScanRangeTask task) {
            return ((QueueScanRangeTask) task).getMessageId();
        }
    });

    _queueService.renew(_pendingScanRangeQueue, messageIds, ttl);
}
 
源代码6 项目: attic-aurora   文件: SchedulerDriverService.java
@Override
public void acceptOffers(
    Protos.OfferID offerId,
    Collection<Protos.Offer.Operation> operations,
    Protos.Filters filter) {
  ensureRunning();

  OfferID convertedOfferId = ProtosConversion.convert(offerId);
  Collection<Operation> convertedOperations =
      Collections2.transform(operations, ProtosConversion::convert);
  Filters convertedFilter = ProtosConversion.convert(filter);

  Futures.getUnchecked(driverFuture)
      .acceptOffers(ImmutableList.of(convertedOfferId), convertedOperations, convertedFilter);
}
 
源代码7 项目: rice   文件: KeyValuesFinderFactory.java
@Override
public List<KeyValue> getKeyValues() {
    Collection<KeyValue> kvs = Collections2.transform(map.entrySet(), new Function<Map.Entry<String, String>, KeyValue>() {
        @Override
        public KeyValue apply(Map.Entry<String, String> input) {
            return new ConcreteKeyValue(input);
        }
    });
    return ImmutableList.copyOf(kvs);
}
 
源代码8 项目: mamute   文件: BlockedIpInterceptor.java
@Override
public void intercept(InterceptorStack interceptorStack, ControllerMethod controllerMethod, Object o) throws InterceptionException {
	List<BlockedIp> ips = blockedIps.list();
	Collection<IpMatcher> matchers = Collections2.transform(ips, extractIp);
	boolean isBlocked = matches(matchers);
	if (isBlocked) {
		result.use(http()).sendError(503);
		return;
	}
	interceptorStack.next(controllerMethod, o);
}
 
源代码9 项目: kylin-on-parquet-v2   文件: Coordinator.java
private void promoteNewSegment(CubingJob cubingJob, CubeInstance cubeInstance, CubeSegment cubeSegment)
        throws IOException {
    long sourceCount = cubingJob.findSourceRecordCount();
    long sourceSizeBytes = cubingJob.findSourceSizeBytes();
    long cubeSizeBytes = cubingJob.findCubeSizeBytes();
    Map<Integer, String> sourceCheckpoint = streamMetadataStore.getSourceCheckpoint(cubeInstance.getName(),
            cubeSegment.getName());

    ISourcePositionHandler positionOperator = StreamingSourceFactory.getStreamingSource(cubeInstance)
            .getSourcePositionHandler();
    Collection<ISourcePosition> sourcePositions = Collections2.transform(sourceCheckpoint.values(),
            new Function<String, ISourcePosition>() {
                @Nullable
                @Override
                public ISourcePosition apply(@Nullable String input) {
                    return positionOperator.parsePosition(input);
                }
            });
    ISourcePosition sourcePosition = positionOperator.mergePositions(sourcePositions, MergeStrategy.KEEP_SMALL);
    cubeSegment.setLastBuildJobID(cubingJob.getId());
    cubeSegment.setLastBuildTime(System.currentTimeMillis());
    cubeSegment.setSizeKB(cubeSizeBytes / 1024);
    cubeSegment.setInputRecords(sourceCount);
    cubeSegment.setInputRecordsSize(sourceSizeBytes);
    cubeSegment.setStreamSourceCheckpoint(positionOperator.serializePosition(sourcePosition));
    getCubeManager().promoteNewlyBuiltSegments(cubeInstance, cubeSegment);
}
 
/**
 * Promote a segment from realtime part into historical part.
 */
void promoteNewSegment(CubingJob cubingJob, CubeInstance cubeInstance, CubeSegment cubeSegment) throws IOException {
    logger.debug("Try transfer segment's {} state to ready.", cubeSegment.getName());
    long sourceCount = cubingJob.findSourceRecordCount();
    long sourceSizeBytes = cubingJob.findSourceSizeBytes();
    long cubeSizeBytes = cubingJob.findCubeSizeBytes();
    Map<Integer, String> sourceCheckpoint = getCoordinator().getStreamMetadataStore()
            .getSourceCheckpoint(cubeInstance.getName(), cubeSegment.getName());

    ISourcePositionHandler positionOperator = StreamingSourceFactory.getStreamingSource(cubeInstance)
            .getSourcePositionHandler();
    Collection<ISourcePosition> sourcePositions = Collections2.transform(sourceCheckpoint.values(),
            new Function<String, ISourcePosition>() {
                @Nullable
                @Override
                public ISourcePosition apply(@Nullable String input) {
                    return positionOperator.parsePosition(input);
                }
            });
    ISourcePosition sourcePosition = positionOperator.mergePositions(sourcePositions,
            ISourcePositionHandler.MergeStrategy.KEEP_SMALL);
    cubeSegment.setLastBuildJobID(cubingJob.getId());
    cubeSegment.setLastBuildTime(System.currentTimeMillis());
    cubeSegment.setSizeKB(cubeSizeBytes / 1024);
    cubeSegment.setInputRecords(sourceCount);
    cubeSegment.setInputRecordsSize(sourceSizeBytes);
    cubeSegment.setStreamSourceCheckpoint(positionOperator.serializePosition(sourcePosition));
    getCoordinator().getCubeManager().promoteNewlyBuiltSegments(cubeInstance, cubeSegment);
}
 
源代码11 项目: mage-android   文件: ObservationViewActivity.java
private void onFavoritesClick(Collection<ObservationFavorite> favorites) {
	Collection<String> userIds = Collections2.transform(favorites, favorite -> favorite.getUserId());

	Intent intent = new Intent(this, PeopleActivity.class);
	intent.putStringArrayListExtra(PeopleActivity.USER_REMOTE_IDS, new ArrayList<>(userIds));
	startActivity(intent);
}
 
源代码12 项目: dsl-devkit   文件: CheckProjectInfo.java
public Collection<String> getMetamodelImports() {
  return Collections2.transform(grammarHelper.getMetamodelPackages(), new Function<String, String>() {
    public String apply(final String importPackageName) {
      return importPackageName + ".*";
    }
  });
}
 
源代码13 项目: emodb   文件: QueueScanWorkflow.java
@Override
public void releaseCompleteScanRanges(Collection<ScanRangeComplete> completions) {
    if (completions.isEmpty()) {
        return;
    }

    Collection<String> messageIds = Collections2.transform(completions, new Function<ScanRangeComplete, String>() {
        @Override
        public String apply(ScanRangeComplete completion) {
            return ((QueueScanRangeComplete) completion).getMessageId();
        }
    });

    _queueService.acknowledge(_completeScanRangeQueue, messageIds);
}
 
源代码14 项目: pushfish-android   文件: AbstractTask.java
private Collection<ContextAwareTaskAction> transformToContextAwareTaskActions(Collection<Object> c) {
    return Collections2.transform(c, new Function<Object, ContextAwareTaskAction>() {
        public ContextAwareTaskAction apply(@Nullable Object input) {
            return wrap((Action<? super Task>) input);
        }
    });
}
 
源代码15 项目: tajo   文件: TestLinkedMetadataManager.java
@Test
public void testGetTablespaces() throws Exception {
  Collection<String> names = Collections2.transform(catalog.getAllTablespaces(),
      new Function<CatalogProtos.TablespaceProto, String>() {
    @Override
    public String apply(@Nullable CatalogProtos.TablespaceProto input) {
      return input.getSpaceName();
    }
  });

  assertEquals(Sets.newHashSet("space1", "space2", "default"), Sets.newHashSet(names));
}
 
源代码16 项目: vespa   文件: ContentHandlerTestBase.java
private String generateResultArray(String... files) {
    Collection<String> output = Collections2.transform(Arrays.asList(files), input -> "\"" + baseUrl + input + "\"");
    StringBuilder sb = new StringBuilder();
    sb.append("[");
    sb.append(Joiner.on(",").join(output));
    sb.append("]");
    return sb.toString();
}
 
private Collection<DatadogReporter.Expansion> asExpansions(Collection<String> strings) {
    return Collections2.transform(strings, new Function<String, DatadogReporter.Expansion>() {
        @Override
        public DatadogReporter.Expansion apply(String string) {
            for (DatadogReporter.Expansion expansion : DatadogReporter.Expansion.values()) {
                if (expansion.toString().equals(string)) {
                    return expansion;
                }
            }
            throw new IllegalArgumentException("Unknown expansion: " + string);
        }
    });
}
 
源代码18 项目: ameba   文件: AbstractTemplateProcessor.java
private Collection<String> getTemplatePaths(String name, String basePath) {
    String lowerName = name.toLowerCase();
    final String templatePath = basePath.endsWith("/") ? basePath + name.substring(1) : basePath + name;

    // Check whether the given name ends with supported suffix.
    for (final String extension : supportedExtensions) {
        if (lowerName.endsWith(extension)) {
            return Collections.singleton(templatePath);
        }
    }

    return Collections2.transform(this.supportedExtensions, input -> templatePath + input);
}
 
源代码19 项目: tez   文件: VertexGroupCommitStartedEvent.java
public void fromProto(VertexGroupCommitStartedProto proto) {
  this.dagID = TezDAGID.fromString(proto.getDagId());
  this.vertexGroupName = proto.getVertexGroupName();
  this.vertexIds = Collections2.transform(proto.getVertexIdsList(), new Function<String, TezVertexID>() {
    @Override
    public TezVertexID apply(String input) {
      return TezVertexID.fromString(input);
    }
  });
}
 
源代码20 项目: core   文件: ScopedRoleDialog.java
public Widget asWidget() {
    TextBoxItem name = new TextBoxItem("name", "Name", true);
    ComboBoxItem baseRole = new ComboBoxItem("baseRole", "Base Role");
    baseRole.setDefaultToFirstOption(true);
    Collection<String> roleNames = Collections2.transform(StandardRole.values(), StandardRole::getId);
    baseRole.setValueMap(roleNames);

    ComboBoxItem type = new ComboBoxItem("type", "Type");
    type.setDefaultToFirstOption(true);
    type.setValueMap(new String[]{"Host", "Server Group"});

    ListItem scope = new ListItem("scope", "Scope");
    scope.setRequired(true);
    CheckBoxItem includeAll = new CheckBoxItem("includeAll", "Include All");

    Form<RoleBean> form = new Form<>(RoleBean.class);
    if (scoped) {
        form.setFields(name, baseRole, type, scope, includeAll);
    } else {
        form.setFields(name, includeAll);
    }
    if (this.existingRole != null) {
        name.setEnabled(false);
        type.setEnabled(false);
        form.edit(modelToBean(existingRole));
    }

    form.addFormValidator((formItems, outcome) -> {
        if (existingRole == null && duplicateNameAndType(beanToModel(form.getUpdatedEntity()))) {
            outcome.addError("name");
            name.setErrMessage("Role already exists");
            name.setErroneous(true);
        }
    });

    VerticalPanel layout = new VerticalPanel();
    layout.setStyleName("window-content");
    layout.add(new HelpPanel().asWidget());
    layout.add(form.asWidget());

    DialogueOptions options = new DialogueOptions(
            event -> {
                FormValidation validation = form.validate();
                if (!validation.hasErrors()) {
                    if (existingRole == null) {
                        circuit.dispatch(new AddScopedRole(beanToModel(form.getUpdatedEntity())));
                    } else if (existingRole.isScoped()) {
                        circuit.dispatch(new ModifyScopedRole(beanToModel(form.getUpdatedEntity())));
                    } else {
                        circuit.dispatch(new ModifyStandardRole(beanToModel(form.getUpdatedEntity())));
                    }
                    presenter.closeWindow();
                }
            },
            event -> presenter.closeWindow()
    );

    return new WindowContentBuilder(layout, options).build();
}