Java Code Examples for com.google.common.collect.ImmutableMap.Builder#build()
The following examples show how to use
com.google.common.collect.ImmutableMap.Builder#build() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MetaContainer.java From sailfish-core with Apache License 2.0 | 6 votes |
/** * Returns a map of key field names mapped to their "transitive" flag. * If a field is marked as a transitive it means that is was marked as * a key one ONLY due to presence of key fields in its children. Key * fields in children are ignored if the field is marked as a key one * itself. * @return key fields map */ public Map<String, Boolean> getKeyFields() { if (children.isEmpty()) { return keyFields; } Builder<String, Boolean> builder = ImmutableMap.builder(); builder.putAll(keyFields); children.forEach((fieldName, metaContainers) -> { if (keyFields.containsKey(fieldName)) { return; } for (MetaContainer metaContainer : metaContainers) { if (metaContainer.hasKeyFields()) { builder.put(fieldName, Boolean.TRUE); return; } } }); return builder.build(); }
Example 2
Source File: UserAPIController.java From onboard with Apache License 2.0 | 6 votes |
/** * 获取未完成的bugs * * @param companyId * @param userId * @return */ @RequestMapping(value = "/{companyId}/user/{userId}/uncompletedBugs", method = RequestMethod.GET) @Interceptors({ CompanyMemberRequired.class, UserChecking.class }) @ResponseBody public Map<String, Object> viewUserOpenBugs(@PathVariable int companyId, @PathVariable int userId) { Builder<String, Object> builder = ImmutableMap.builder(); Map<Integer, String> projectIdToName = getProjectIdAndNameByCompanyId(companyId); builder.put("projectsName", projectIdToName); List<Integer> projectList = getProjectListOfCurrentUser(companyId); TreeMap<Integer, List<Bug>> bugs = bugService.getOpenBugsByUser(userId, projectList); TreeMap<Integer, List<BugDTO>> bugsDto = makeUserUncompletedBugsMapSerilizable(bugs); builder.put("uncompletedBugs", bugsDto); Map<Integer, List<User>> users = userService.getAllProjectUsersInCompany(companyId); Map<Integer, List<UserDTO>> userDtos = makeUserUncompletedTodosMapSerilizable(users); builder.put("userDtos", userDtos); UserDTO userDto = UserTransform.userToUserDTO(userService.getById(userId)); builder.put("user", userDto); return builder.build(); }
Example 3
Source File: StorageTxImpl.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
private Map<String, String> buildStorageHeaders(final String blobName, @Nullable final Supplier<InputStream> streamSupplier, @Nullable final Map<String, String> headers, @Nullable final String declaredContentType, final boolean skipContentVerification) throws IOException { checkArgument( !skipContentVerification || !Strings2.isBlank(declaredContentType), "skipContentVerification set true but no declaredContentType provided" ); Builder<String, String> storageHeaders = ImmutableMap.builder(); storageHeaders.put(Bucket.REPO_NAME_HEADER, repositoryName); storageHeaders.put(BlobStore.BLOB_NAME_HEADER, blobName); storageHeaders.put(BlobStore.CREATED_BY_HEADER, createdBy); storageHeaders.put(BlobStore.CREATED_BY_IP_HEADER, createdByIp); if (!skipContentVerification) { storageHeaders.put( BlobStore.CONTENT_TYPE_HEADER, determineContentType(streamSupplier, blobName, declaredContentType) ); } else { storageHeaders.put(BlobStore.CONTENT_TYPE_HEADER, declaredContentType); } if (headers != null) { storageHeaders.putAll(headers); } return storageHeaders.build(); }
Example 4
Source File: HelpCenterApiController.java From onboard with Apache License 2.0 | 5 votes |
@RequestMapping(value = "", method = RequestMethod.GET) @ResponseBody public Map<String, ?> getHelpTips() { Builder<String, Object> builder = ImmutableMap.builder(); List<HelpTip> helpTips = helpTipService.getHelpTips(0, -1); Map<String, List<HelpTip>> helpTipsMap = helpTipService.groupHelpTipsByTitle(helpTips); Map<String, List<HelpTipDTO>> helpTipDTOsMap = makeHelpTipsMapSerilizable(helpTipsMap); builder.put("helpTipDTOsMap", helpTipDTOsMap); return builder.build(); }
Example 5
Source File: IPv4Packet.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
@Override public Map<String, String> getFields() { Map<String, String> map = fFields; if (map == null) { Builder<@NonNull String, @NonNull String> builder = ImmutableMap.<@NonNull String, @NonNull String> builder() .put("Version", String.valueOf(fVersion)) //$NON-NLS-1$ .put("Header Length", String.valueOf(getHeaderLength()) + " bytes") //$NON-NLS-1$ //$NON-NLS-2$ .put("Differentiated Services Field", String.format("%s%02x", "0x", fDSCP)) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ .put("Explicit Congestion Notification", String.format("%s%02x", "0x", fExplicitCongestionNotification)) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ .put("Total Length", String.valueOf(fTotalLength) + " bytes") //$NON-NLS-1$ //$NON-NLS-2$ .put("Identification", String.format("%s%04x", "0x", fIdentification)) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ .put("Don't Fragment Flag", String.valueOf(fDontFragmentFlag)) //$NON-NLS-1$ .put("More Fragment Flag", String.valueOf(fMoreFragmentFlag)) //$NON-NLS-1$ .put("Fragment Offset", String.valueOf(fFragmentOffset)) //$NON-NLS-1$ .put("Time to live", String.valueOf(fTimeToLive)) //$NON-NLS-1$ .put("Protocol", IPProtocolNumberHelper.toString(fIpDatagramProtocol) + " (" + String.valueOf(fIpDatagramProtocol) + ")") //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ .put("Checksum", String.format("%s%04x", "0x", fHeaderChecksum)) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ .put("Source IP Address", nullToEmptyString(fSourceIpAddress.getHostAddress())) //$NON-NLS-1$ .put("Destination IP Address", nullToEmptyString(fDestinationIpAddress.getHostAddress())); //$NON-NLS-1$ byte[] options = fOptions; if (options == null) { builder.put("Options", EMPTY_STRING); //$NON-NLS-1$ } else { builder.put("Options", ConversionHelper.bytesToHex(options, true)); //$NON-NLS-1$ } fFields = builder.build(); return fFields; } return map; }
Example 6
Source File: UserAPIController.java From onboard with Apache License 2.0 | 5 votes |
@RequestMapping(value = "/{companyId}/user/{userId}/activities", method = RequestMethod.GET) @Interceptors({ CompanyMemberRequired.class, UserChecking.class }) @ResponseBody public Map<String, Object> viewUserActivities(@PathVariable int companyId, @PathVariable int userId, @RequestParam(value = "until", required = false) @DateTimeFormat(iso = ISO.DATE) Date until, Model model) { Builder<String, Object> builder = ImmutableMap.builder(); DateTime dt = until == null ? new DateTime() : new DateTime(until); until = dt.withTime(0, 0, 0, 0).plusDays(1).plusMillis(-1).toDate(); List<Integer> projectList = getProjectListOfCurrentUser(companyId); TreeMap<Date, List<Activity>> map = activityService.getByUserGroupByDate(companyId, userId, ACTIVITY_PER_PAGE, projectList, until); TreeMap<String, List<ActivityDTO>> mapDTO = makeMapSerilizable(map); builder.put("activities", mapDTO); boolean hasNext = false; if (map != null && map.size() > 0) { Date newUntil = new DateTime(map.lastKey()).plusDays(-1).withTime(0, 0, 0, 0).toDate(); TreeMap<Date, List<Activity>> nextMap = activityService.getByUserGroupByDate(companyId, userId, ACTIVITY_PER_PAGE, projectList, newUntil); hasNext = nextMap != null; builder.put("nextPage", dtf.print(new DateTime(newUntil))); } builder.put("hasNext", hasNext); return builder.build(); }
Example 7
Source File: UserAPIController.java From onboard with Apache License 2.0 | 5 votes |
/** * 看一个人完成的所有todo * * @param companyId * @param userId * @param model * @return */ @RequestMapping(value = "/{companyId}/user/{userId}/completed_todos", method = RequestMethod.GET) @Interceptors({ CompanyMemberRequired.class, UserChecking.class }) @ResponseBody public Map<String, Object> viewUserCompletedTodos(@PathVariable int companyId, @PathVariable int userId, @RequestParam(value = "until", required = false) @DateTimeFormat(iso = ISO.DATE) Date until, Model model) { Builder<String, Object> builder = ImmutableMap.builder(); DateTime dt = until == null ? new DateTime() : new DateTime(until); until = dt.withTime(0, 0, 0, 0).plusDays(1).plusMillis(-1).toDate(); List<Integer> projectList = getProjectListOfCurrentUser(companyId); TreeMap<Date, List<Todolist>> map = todoService.getCompletedTodolistsGroupByDateByUser(companyId, userId, projectList, until, PER_PAGE); TreeMap<String, List<TodolistDTO>> mapDTO = makeUserCompletedTodosMapSerilizable(map); builder.put("completedTodos", mapDTO); Map<Integer, String> projectIdToName = getProjectIdAndNameByCompanyId(companyId); builder.put("projectsName", projectIdToName); boolean hasNext = false; if (map != null && map.size() > 0) { Date newUntil = new DateTime(map.lastKey()).withTime(0, 0, 0, 0).plusMillis(-1).toDate(); TreeMap<Date, List<Todolist>> nextMap = todoService.getCompletedTodolistsGroupByDateByUser(companyId, userId, projectList, newUntil, PER_PAGE); hasNext = nextMap.size() > 0; builder.put("nextPage", dtf.print(new DateTime(newUntil))); } builder.put("hasNext", hasNext); return builder.build(); }
Example 8
Source File: BaseImpl.java From canvas-api with GNU Lesser General Public License v3.0 | 5 votes |
/** * Returns URL parameters after removing any that have an empty list in them. * For optional list arguments, we pass an empty list to the API method. This generates * an entry like includes[]= with no value. This function strips them out so we only * pass parameters to Canvas that have a value to send along. */ private Map<String, List<String>> stripEmptyParams(Map<String, List<String>> parameters) { Builder<String, List<String>> paramsBuilder = ImmutableMap.<String, List<String>>builder(); for (Map.Entry<String, List<String>> entry : parameters.entrySet()) { if(entry.getValue() != null && !entry.getValue().isEmpty()) { paramsBuilder.put(entry.getKey(), entry.getValue()); } } return paramsBuilder.build(); }
Example 9
Source File: UserAPIController.java From onboard with Apache License 2.0 | 5 votes |
/** * 查看用户所有附件 * * @param companyId * @param userId * @param until * @param model * @return */ @RequestMapping(value = "/{companyId}/user/{userId}/attachments", method = RequestMethod.GET) @Interceptors({ CompanyMemberRequired.class, UserChecking.class }) @ResponseBody public ImmutableMap<String, ?> viewUserAttachments(@PathVariable int companyId, @PathVariable int userId, @RequestParam(value = "until", required = false) @DateTimeFormat(iso = ISO.DATE) Date until, @RequestParam(value = "page", required = false, defaultValue = "1") Integer page) { Builder<String, Object> builder = ImmutableMap.builder(); DateTime dt = until == null ? new DateTime() : new DateTime(until); until = dt.withTime(0, 0, 0, 0).plusDays(1).plusMillis(-1).toDate(); List<Integer> projectList = getProjectListOfCurrentUser(companyId); TreeMap<Date, List<Attachment>> map = attachmentService.getAttachmentsByUserGroupByDate(companyId, userId, projectList, until, PER_PAGE); TreeMap<String, List<AttachmentDTO>> mapDTO = makeUserAttachmentsMapSerilizable(map); builder.put("userAttachments", mapDTO); // UserDTO userDto = new UserDTO(userService.getUserById(userId)); boolean hasNext = false; if (map != null && map.size() > 0) { Date newUntil = new DateTime(map.lastKey()).withTime(0, 0, 0, 0).plusMillis(-1).toDate(); TreeMap<Date, List<Attachment>> nextMap = attachmentService.getAttachmentsByUserGroupByDate(companyId, userId, projectList, newUntil, PER_PAGE); hasNext = nextMap.size() > 0; builder.put("nextPage", dtf.print(new DateTime(newUntil))); } builder.put("hasNext", hasNext); return builder.build(); }
Example 10
Source File: TypeManagerTest.java From binnavi with Apache License 2.0 | 5 votes |
private ImmutableMap<BaseType, Integer> captureTypeSizes() { final Builder<BaseType, Integer> builder = ImmutableMap.<BaseType, Integer>builder(); for (BaseType baseType : typeSystem.getTypes()) { builder.put(baseType, baseType.getBitSize()); } return builder.build(); }
Example 11
Source File: TypeManager.java From binnavi with Apache License 2.0 | 5 votes |
private static ImmutableMap<BaseType, Integer> captureTypeSizesState( final Set<BaseType> baseTypes) { final Builder<BaseType, Integer> builder = ImmutableMap.<BaseType, Integer>builder(); for (BaseType baseType : baseTypes) { if (baseType.getCategory() != BaseTypeCategory.FUNCTION_PROTOTYPE) { builder.put(baseType, baseType.getBitSize()); } } return builder.build(); }
Example 12
Source File: MetaContainer.java From sailfish-core with Apache License 2.0 | 5 votes |
/** * Sets non-transitive key fields to this meta container * @param keyFields set of key fields * @return instance on which it was called on */ public MetaContainer setKeyFields(Set<String> keyFields) { if (keyFields != null) { Builder<String, Boolean> builder = ImmutableMap.builder(); for (String keyField : keyFields) { builder.put(keyField, Boolean.FALSE); } this.keyFields = builder.build(); } return this; }
Example 13
Source File: QuotaQueryConverter.java From james-project with Apache License 2.0 | 5 votes |
QuotaQueryConverter() { Builder<Class<? extends QuotaClause>, Function<QuotaClause, QueryBuilder>> builder = ImmutableMap.builder(); builder.put(HasDomain.class, this::convertHasDomain); builder.put(And.class, this::disableNestedAnd); builder.put(MoreThan.class, this::convertMoreThan); builder.put(LessThan.class, this::convertLessThan); clauseConverter = builder.build(); }
Example 14
Source File: PhoenixConnection.java From phoenix with Apache License 2.0 | 5 votes |
private ImmutableMap<String, String> getImmutableCustomTracingAnnotations() { Builder<String, String> result = ImmutableMap.builder(); result.putAll(JDBCUtil.getAnnotations(url, info)); if (getSCN() != null) { result.put(PhoenixRuntime.CURRENT_SCN_ATTRIB, getSCN().toString()); } if (getTenantId() != null) { result.put(PhoenixRuntime.TENANT_ID_ATTRIB, getTenantId().getString()); } return result.build(); }
Example 15
Source File: MaterialCockpitRowFactory.java From metasfresh-webui-api-legacy with GNU General Public License v3.0 | 5 votes |
@VisibleForTesting Map<MainRowBucketId, MainRowWithSubRows> createEmptyRowBuckets( @NonNull final ImmutableSet<ProductId> productIds, @NonNull final LocalDate timestamp, final boolean includePerPlantDetailRows) { final DimensionSpec dimensionSpec = MaterialCockpitUtil.retrieveDimensionSpec(); final List<DimensionSpecGroup> groups = dimensionSpec.retrieveGroups(); final List<I_S_Resource> plants = retrieveCountingPlants(includePerPlantDetailRows); final Builder<MainRowBucketId, MainRowWithSubRows> result = ImmutableMap.builder(); for (final ProductId productId : productIds) { final MainRowBucketId key = MainRowBucketId.createPlainInstance(productId, timestamp); final MainRowWithSubRows mainRowBucket = MainRowWithSubRows.create(key); for (final I_S_Resource plant : plants) { mainRowBucket.addEmptyCountingSubrowBucket(plant.getS_Resource_ID()); } for (final DimensionSpecGroup group : groups) { mainRowBucket.addEmptyAttributesSubrowBucket(group); } result.put(key, mainRowBucket); } return result.build(); }
Example 16
Source File: JvmTypesResourceDescriptionStrategy.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected Map<String, String> createLazyUserData(final EObject eObject) { return new ForwardingMap<String, String>() { private Map<String,String> delegate; @Override protected Map<String, String> delegate() { if(delegate == null) { Builder<String, String> userData = ImmutableMap.builder(); createUserData(eObject, userData); delegate = userData.build(); } return delegate; } }; }
Example 17
Source File: Locomotive.java From circus-train with Apache License 2.0 | 5 votes |
@Override public void run(ApplicationArguments args) { locomotiveListener.circusTrainStartUp(args.getSourceArgs(), EventUtils.toEventSourceCatalog(sourceCatalog), EventUtils.toEventReplicaCatalog(replicaCatalog, security)); CompletionCode completionCode = CompletionCode.SUCCESS; Builder<String, Long> metrics = ImmutableMap.builder(); replicationFailures = 0; long replicated = 0; LOG.info("{} tables to replicate.", tableReplications.size()); for (TableReplication tableReplication : tableReplications) { String summary = getReplicationSummary(tableReplication); LOG.info("Replicating {} replication mode '{}', strategy '{}'.", summary, tableReplication.getReplicationMode(), tableReplication.getReplicationStrategy()); try { Replication replication = replicationFactory.newInstance(tableReplication); tableReplicationListener.tableReplicationStart(EventUtils.toEventTableReplication(tableReplication), replication.getEventId()); replication.replicate(); LOG.info("Completed replicating: {}.", summary); tableReplicationListener.tableReplicationSuccess(EventUtils.toEventTableReplication(tableReplication), replication.getEventId()); } catch (Throwable t) { replicationFailures++; completionCode = CompletionCode.FAILURE; LOG.error("Failed to replicate: {}.", summary, t); tableReplicationListener.tableReplicationFailure(EventUtils.toEventTableReplication(tableReplication), EventUtils.EVENT_ID_UNAVAILABLE, t); } replicated++; } metrics.put("tables_replicated", replicated); metrics.put(completionCode.getMetricName(), completionCode.getCode()); Map<String, Long> metricsMap = metrics.build(); metricSender.send(metricsMap); locomotiveListener.circusTrainShutDown(completionCode, metricsMap); }
Example 18
Source File: XYPresentationProvider.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
private OutputElementStyle createAppearance(Long seriesId, String seriesType, int width) { RGBAColor color = generateColor(); Builder<String, Object> builder = ImmutableMap.builder(); builder.put(StyleProperties.STYLE_NAME, seriesId); builder.put(StyleProperties.SERIES_TYPE, seriesType); builder.put(StyleProperties.SERIES_STYLE, generateStyle(seriesType)); builder.put(StyleProperties.COLOR, X11ColorUtils.toHexColor(color.getRed(), color.getGreen(), color.getBlue())); builder.put(StyleProperties.WIDTH, width); return new OutputElementStyle(null, builder.build()); }
Example 19
Source File: HqlTranslator.java From circus-train with Apache License 2.0 | 5 votes |
@Autowired public HqlTranslator(TableReplications tableReplications) { Builder<String, List<TableTranslation>> mappingsBuilder = ImmutableMap.<String, List<TableTranslation>>builder(); for (TableReplication tableReplication : tableReplications.getTableReplications()) { if (tableReplication.getTableMappings() == null || tableReplication.getTableMappings().isEmpty()) { continue; } mappingsBuilder.put(keyFor(tableReplication), buildTableTranslations(tableReplication)); } mappings = mappingsBuilder.build(); }
Example 20
Source File: EntityQueryNode.java From rya with Apache License 2.0 | 4 votes |
/** * Constructs an instance of {@link EntityQueryNode}. * * @param type - The type of {@link Entity} this node matches. (not null) * @param patterns - The query StatementPatterns that are solved using an * Entity of the Type. (not null) * @param entities - The {@link EntityStorage} that will be searched to match * {@link BindingSet}s when evaluating a query. (not null) */ public EntityQueryNode(final Type type, final Collection<StatementPattern> patterns, final EntityStorage entities) throws IllegalStateException { this.type = requireNonNull(type); this.patterns = requireNonNull(patterns); this.entities = requireNonNull(entities); bindingNames = new HashSet<>(); properties = new HashSet<>(); // Subject based preconditions. verifySameSubjects(patterns); // Predicate based preconditions. verifyAllPredicatesAreConstants(patterns); verifyHasCorrectTypePattern(type, patterns); verifyAllPredicatesPartOfType(type, patterns); // The Subject may either be constant or a variable. final Var subject = patterns.iterator().next().getSubjectVar(); subjectIsConstant = subject.isConstant(); if(subjectIsConstant) { subjectConstant = Optional.of( subject.getValue().toString() ); subjectVar = Optional.empty(); } else { subjectConstant = Optional.empty(); subjectVar = Optional.of( subject.getName() ); } // Any constant that appears in the Object portion of the SP will be used to make sure they match. final Builder<RyaIRI, Var> builder = ImmutableMap.builder(); for(final StatementPattern sp : patterns) { final Var object = sp.getObjectVar(); final Var pred = sp.getPredicateVar(); final RyaIRI predIRI = new RyaIRI(pred.getValue().stringValue()); bindingNames.addAll(sp.getBindingNames()); if(object.isConstant() && !pred.getValue().equals(RDF.TYPE)) { final RyaType propertyType = RdfToRyaConversions.convertValue(object.getValue()); properties.add(new Property(predIRI, propertyType)); } builder.put(predIRI, object); } objectVariables = builder.build(); }