/** @return The interval info map for the aggregator */ protected Map<AggregationInterval, AggregationIntervalInfo> getAggregatorIntervalInfo( final Class<? extends IPortalEventAggregator<?>> aggregatorType) { final AggregatedIntervalConfig aggregatorIntervalConfig = this.intervalsForAggregatorHelper.getAggregatorIntervalConfig(aggregatorType); Map<AggregationInterval, AggregationIntervalInfo> intervalInfo = this.aggregatorReadOnlyIntervalInfo.get(aggregatorType); if (intervalInfo == null) { final Builder<AggregationInterval, AggregationIntervalInfo> intervalInfoBuilder = ImmutableMap.builder(); for (Map.Entry<AggregationInterval, AggregationIntervalInfo> intervalInfoEntry : this.currentIntervalInfo.entrySet()) { final AggregationInterval key = intervalInfoEntry.getKey(); if (aggregatorIntervalConfig.isIncluded(key)) { intervalInfoBuilder.put(key, intervalInfoEntry.getValue()); } } intervalInfo = intervalInfoBuilder.build(); aggregatorReadOnlyIntervalInfo.put(aggregatorType, intervalInfo); } return intervalInfo; }
static { Builder<Integer, NodeAttributesMask> builder = ImmutableMap.builder(); for (NodeAttributesMask e : values()) { builder.put(e.getValue(), e); } VALUES = builder.build(); }
@Subscribe public void buildModList(FMLLoadEvent event) { this.modList = loader.getIndexedModList(); Builder<String, EventBus> eventBus = ImmutableMap.builder(); for (ModContainer mod : loader.getModList()) { EventBus bus = new EventBus(mod.getModId()); boolean isActive = mod.registerBus(bus, this); if (isActive) { Level level = Logger.getLogger(mod.getModId()).getLevel(); FMLLog.log( mod.getModId(), Level.FINE, "Mod Logging channel %s configured at %s level.", level == null ? "default" : level); FMLLog.log(mod.getModId(), Level.INFO, "Activating mod %s", mod.getModId()); activeModList.add(mod); modStates.put(mod.getModId(), ModState.UNLOADED); eventBus.put(mod.getModId(), bus); } else { FMLLog.log( mod.getModId(), Level.WARNING, "Mod %s has been disabled through configuration", mod.getModId()); modStates.put(mod.getModId(), ModState.UNLOADED); modStates.put(mod.getModId(), ModState.DISABLED); } } eventChannels = eventBus.build(); }
@Override public Map<String, Team> getTeams() throws DataSourceException { if (teamNamesCache == null) { synchronized (this) { if (teamNamesCache == null) { final Builder<String, Team> teamNamesBuilder = ImmutableMap.builder(); String sql = "select Name, users.FirstName, DraftOrder " + "from teams " + "inner join users " + "on teams.userid = users.user"; try { executeQuery( sql, new ResultSetCallback() { @Override public void onResultSet(ResultSet resultSet) throws SQLException, DataSourceException { while (resultSet.next()) { Team team = beanFactory.createTeam().as(); team.setShortName(resultSet.getString("FirstName")); team.setLongName(resultSet.getString("Name")); teamNamesBuilder.put(resultSet.getString("DraftOrder"), team); } } }); } catch (SQLException e) { throw new DataSourceException(e); } teamNamesCache = teamNamesBuilder.build(); } } } return teamNamesCache; }
@Provides @Singleton @ImageQuery protected Map<String, String> imageQuery(ValueOfConfigurationKeyOrNull config) { String amiQuery = Strings.emptyToNull(config.apply(PROPERTY_EC2_AMI_QUERY)); String owners = config.apply(PROPERTY_EC2_AMI_OWNERS); if ("".equals(owners)) { amiQuery = null; } else if (owners != null) { StringBuilder query = new StringBuilder(); if ("*".equals(owners)) query.append("state=available;image-type=machine"); else query.append("owner-id=").append(owners).append(";state=available;image-type=machine"); Logger.getAnonymousLogger() .warning( String.format( "Property %s is deprecated, please use new syntax: %s=%s", PROPERTY_EC2_AMI_OWNERS, PROPERTY_EC2_AMI_QUERY, query.toString())); amiQuery = query.toString(); } Builder<String, String> builder = ImmutableMap.<String, String>builder(); if (amiQuery != null) builder.put(PROPERTY_EC2_AMI_QUERY, amiQuery); String ccQuery = Strings.emptyToNull(config.apply(PROPERTY_EC2_CC_AMI_QUERY)); if (ccQuery != null) builder.put(PROPERTY_EC2_CC_AMI_QUERY, ccQuery); return builder.build(); }
static { Builder<Integer, NodeClass> builder = ImmutableMap.builder(); for (NodeClass e : values()) { builder.put(e.getValue(), e); } VALUES = builder.build(); }
static { Builder<Integer, BrowseDirection> builder = ImmutableMap.builder(); for (BrowseDirection e : values()) { builder.put(e.getValue(), e); } VALUES = builder.build(); }
/* (non-Javadoc) * @see org.jasig.portal.portlet.container.properties.BaseRequestPropertiesManager#getRequestProperties(javax.servlet.http.HttpServletRequest, org.jasig.portal.portlet.om.IPortletWindow) */ @Override public Map<String, String[]> getRequestProperties( HttpServletRequest portletRequest, IPortletWindow portletWindow) { if (this.propertyToAttributeMappings.isEmpty() && this.nonNamespacedProperties.isEmpty()) { return Collections.emptyMap(); } final HttpServletRequest portalRequest = this.portalRequestUtils.getOriginalPortalRequest(portletRequest); final String windowIdStr = portletWindow.getPortletWindowId().getStringId(); final Builder<String, String[]> properties = ImmutableMap.builder(); for (final Enumeration<String> attributeNames = portalRequest.getAttributeNames(); attributeNames.hasMoreElements(); ) { final String fullAttributeName = attributeNames.nextElement(); final String propertyName = getPropertyName(windowIdStr, fullAttributeName); if (propertyName == null) { continue; } logger.debug( "Found portal request attribute {} returning as property {}", fullAttributeName, propertyName); final Object value = portalRequest.getAttribute(fullAttributeName); final String[] values = convertValue(value); properties.put(propertyName, values); } return properties.build(); }
private Map<String, Object> toMap(@SuppressWarnings("rawtypes") Dictionary properties) { Builder<String, Object> b = ImmutableMap.builder(); for (Enumeration<?> e = properties.keys(); e.hasMoreElements(); ) { String k = (String) e.nextElement(); b.put(k, properties.get(k)); } return b.build(); }
public void testBuilderPutNullValueViaPutAll() { Builder<String, Integer> builder = new Builder<String, Integer>(); try { builder.putAll(Collections.<String, Integer>singletonMap("one", null)); fail(); } catch (NullPointerException expected) { } }
public void testBuilderPutNullValue() { Builder<String, Integer> builder = new Builder<String, Integer>(); try { builder.put("one", null); fail(); } catch (NullPointerException expected) { } }
public void testBuilderReuse() { Builder<String, Integer> builder = new Builder<String, Integer>(); ImmutableMap<String, Integer> mapOne = builder.put("one", 1).put("two", 2).build(); ImmutableMap<String, Integer> mapTwo = builder.put("three", 3).put("four", 4).build(); assertMapEquals(mapOne, "one", 1, "two", 2); assertMapEquals(mapTwo, "one", 1, "two", 2, "three", 3, "four", 4); }
private Map<String, ? extends Identified> series(int seriesCount) { Builder<String, Series> builder = ImmutableMap.builder(); for (int j = 0; j < seriesCount; j++) { Series series = new Series("uri" + j, "curie", Publisher.BBC); builder.put(series.getCanonicalUri(), series); } ; return builder.build(); }
public static Map<String, String> cleanseAttributes(Attributes in) { Builder<String, String> attrs = ImmutableMap.<String, String>builder(); for (int i = 0; i < in.getLength(); i++) { String name = in.getQName(i); if (name.indexOf(':') != -1) name = name.substring(name.indexOf(':') + 1); attrs.put(name, in.getValue(i)); } return attrs.build(); }
public void testBuilder_orderEntriesByValueAfterExactSizeBuild() { Builder<String, Integer> builder = new Builder<String, Integer>(2).put("four", 4).put("one", 1); ImmutableMap<String, Integer> keyOrdered = builder.build(); ImmutableMap<String, Integer> valueOrdered = builder.orderEntriesByValue(Ordering.natural()).build(); assertMapEquals(keyOrdered, "four", 4, "one", 1); assertMapEquals(valueOrdered, "one", 1, "four", 4); }
public void testBuilderPutMutableEntryWithNullKeyFailsAtomically() { Builder<String, Integer> builder = new Builder<String, Integer>(); try { builder.put(new SimpleEntry<String, Integer>(null, 1)); fail(); } catch (NullPointerException expected) { } builder.put("foo", 2); assertMapEquals(builder.build(), "foo", 2); }
public static <T> ImmutableMap<Integer, T> getColInfoMap(List<T> hiveCols, int startIndx) { Builder<Integer, T> bldr = ImmutableMap.<Integer, T>builder(); int indx = startIndx; for (T ci : hiveCols) { bldr.put(indx, ci); indx++; } return bldr.build(); }
public static ImmutableMap<String, Integer> getColNameIndxMap(List<FieldSchema> tableFields) { Builder<String, Integer> bldr = ImmutableMap.<String, Integer>builder(); int indx = 0; for (FieldSchema fs : tableFields) { bldr.put(fs.getName(), indx); indx++; } return bldr.build(); }
public void testPuttingTheSameKeyTwiceThrowsOnBuild() { Builder<String, Integer> builder = new Builder<String, Integer>() .put("one", 1) .put("one", 1); // throwing on this line would be even better try { builder.build(); fail(); } catch (IllegalArgumentException expected) { } }
public static ImmutableMap<Integer, VirtualColumn> getVColsMap( List<VirtualColumn> hiveVCols, int startIndx) { Builder<Integer, VirtualColumn> bldr = ImmutableMap.<Integer, VirtualColumn>builder(); int indx = startIndx; for (VirtualColumn vc : hiveVCols) { bldr.put(indx, vc); indx++; } return bldr.build(); }
public static ImmutableMap<String, Integer> getRowColNameIndxMap( List<RelDataTypeField> rowFields) { Builder<String, Integer> bldr = ImmutableMap.<String, Integer>builder(); int indx = 0; for (RelDataTypeField rdt : rowFields) { bldr.put(rdt.getName(), indx); indx++; } return bldr.build(); }
public void testBuilder_withImmutableEntryAndNullContents() { Builder<String, Integer> builder = new Builder<String, Integer>(); try { builder.put(Maps.immutableEntry("one", (Integer) null)); fail(); } catch (NullPointerException expected) { } try { builder.put(Maps.immutableEntry((String) null, 1)); fail(); } catch (NullPointerException expected) { } }
protected void encodeScript(FacesContext facesContext, UIComponent component) throws IOException { JavaScriptService javaScriptService = ServiceTracker.getService(JavaScriptService.class); JSFunction messageObject = new JSObject(getJSClassName(), component.getClientId(facesContext)); Map<String, Object> attributes = component.getAttributes(); Builder<String, Object> parametersBuilder = ImmutableMap.builder(); String forId = (String) attributes.get("for"); RendererUtils rendererUtils = RendererUtils.getInstance(); if (!Strings.isNullOrEmpty(forId)) { UIComponent target = rendererUtils.findComponentFor(component, forId); if (null != target) { parametersBuilder.put("forComponentId", target.getClientId(facesContext)); } } Severity level = getLevel(component); if (FacesMessage.SEVERITY_INFO != level) { parametersBuilder.put("level", level.getOrdinal()); } if (!rendererUtils.isBooleanAttribute(component, "showSummary")) { parametersBuilder.put("showSummary", false); } if (rendererUtils.isBooleanAttribute(component, "showDetail")) { parametersBuilder.put("showDetail", true); } if (rendererUtils.isBooleanAttribute(component, "tooltip")) { parametersBuilder.put("tooltip", true); } if (isComponentMessages(component)) { parametersBuilder.put("isMessages", true); } messageObject.addParameter(parametersBuilder.build()); // RendererUtils.getInstance().writeScript(facesContext, component, messageObject); javaScriptService.addPageReadyScript(facesContext, messageObject); }
public Map<String, String> getSettings(ObmUser user) { Builder<String, String> mapBuilder = new Builder<String, String>(); String domain = user.getDomain().getName(); String userLogin = user.getLogin(); Connection con = null; PreparedStatement ps = null; ResultSet rs = null; try { con = obmHelper.getConnection(); String q = "select userobmpref_option, userobmpref_value from UserObmPref " + "where userobmpref_user_id is null " + "and userobmpref_option not in " + "(select userobmpref_option from UserObmPref where userobmpref_user_id=(select userobm_id from UserObm " + "where userobm_login=? " + "and userobm_domain_id=(select domain_id from Domain where domain_name=?) " + ")) " + "union " + "select userobmpref_option, userobmpref_value from UserObmPref " + "where userobmpref_user_id=(select userobm_id from UserObm " + "where userobm_login=? " + "and userobm_domain_id=(select domain_id from Domain where domain_name=?) " + " )"; ps = con.prepareStatement(q); int idx = 1; ps.setString(idx++, userLogin); ps.setString(idx++, domain); ps.setString(idx++, userLogin); ps.setString(idx++, domain); rs = ps.executeQuery(); while (rs.next()) { mapBuilder.put(rs.getString(1), rs.getString(2)); } } catch (SQLException se) { logger.error("Error fetching preferences for " + user + " at " + domain, se); } finally { obmHelper.cleanup(con, ps, rs); } ImmutableMap<String, String> data = mapBuilder.build(); logger.info("return " + data.size() + " settings for userid: " + user + " at " + domain); return data; }
@Override protected LrsObject getLrsObject(PortalEvent event) { final String targetedLayoutNodeId = ((PortalRenderEvent) event).getTargetedLayoutNodeId(); final AggregatedTabMapping aggregatedTabMapping = aggregatedTabLookupDao.getMappedTabForLayoutId(targetedLayoutNodeId); final Builder<String, LocalizedString> definitionBuilder = ImmutableMap.builder(); definitionBuilder.put( "name", new LocalizedString(Locale.US, aggregatedTabMapping.getDisplayString())); return new LrsObject( buildUrn("tab", aggregatedTabMapping.getFragmentName()), getDefaultObjectType(), definitionBuilder.build()); }
@Override Builder<String, Object> serialize(Builder<String, Object> builder) { super.serialize(builder); if (hasTitle()) { builder.put(BOOK_TITLE.BUKKIT, title); } if (hasAuthor()) { builder.put(BOOK_AUTHOR.BUKKIT, author); } if (hasPages()) { builder.put(BOOK_PAGES.BUKKIT, pages); } return builder; }
private void saveMigratorSequence( SessionImpl session, DependencySequence migratorDependencySequence) throws AccessDeniedException, StorageClientException { Content runMigrators = session.getContentManager().get(SYSTEM_MIGRATION_CONTENT_ITEM); String ts = String.valueOf(System.currentTimeMillis()); int i = 0; if (runMigrators == null) { Builder<String, Object> b = ImmutableMap.builder(); for (PropertyMigrator pm : migratorDependencySequence) { b.put(pm.getName(), ts + ";" + i); } runMigrators = new Content(SYSTEM_MIGRATION_CONTENT_ITEM, b.build()); } else { for (PropertyMigrator pm : migratorDependencySequence) { runMigrators.setProperty(pm.getName(), ts + ";" + i); } } session.getContentManager().update(runMigrators); }
@SuppressWarnings("unchecked") @Override public <R extends HttpRequest> R bindToRequest(R request, Object input) { checkNotNull(input, "tags"); Map<String, String> tagValues; if (input instanceof Iterable) { Builder<String, String> builder = ImmutableMap.<String, String>builder(); for (String key : (Iterable<String>) input) { builder.put(key, ""); } tagValues = builder.build(); } else if (input instanceof Map) { tagValues = Map.class.cast(input); } else { throw new IllegalArgumentException( "This binder is only valid for Map<String,String> or Iterable<String>"); } return indexMapToFormValuesWithPrefix(request, "Tag", "Key", "Value", tagValues); }
@Override Builder<String, Object> serialize(Builder<String, Object> builder) { super.serialize(builder); if (hasCustomEffects()) { builder.put(POTION_EFFECTS.BUKKIT, ImmutableList.copyOf(this.customEffects)); } return builder; }
@Before public void setUp() { mockRefDb = mock(RefDatabase.class); Builder<String, String> builder = ImmutableMap.builder(); Map<String, String> allRefs = builder // .put("refs/heads/master", forString("refs/heads/master").toString()) // .put("refs/heads/branch1", forString("refs/heads/branch1").toString()) // .put("refs/heads/v1.1", forString("refs/heads/v1.1").toString()) // .put("refs/tags/tag1", forString("refs/tags/tag1").toString()) // .put("refs/tags/v1.1", forString("refs/tags/v1.1").toString()) // .put( "refs/remotes/origin/master", forString("refs/remotes/origin/master").toString()) // .put( "refs/remotes/origin/branch1", forString("refs/remotes/origin/branch1").toString()) // .put("refs/remotes/juan/master", forString("refs/remotes/juan/master").toString()) // .put("refs/remotes/juan/v1.1", forString("refs/remotes/juan/v1.1").toString()) // .build(); when(mockRefDb.getAll()).thenReturn(allRefs); command = new RefParse(); for (String name : allRefs.keySet()) { when(mockRefDb.getRef(eq(name))).thenReturn(allRefs.get(name)); } CommandLocator mockCommandLocator = mock(CommandLocator.class); when(mockCommandLocator.getRefDatabase()).thenReturn(mockRefDb); command.setCommandLocator(mockCommandLocator); ResolveObjectType mockResolveObjectType = mock(ResolveObjectType.class); when(mockCommandLocator.command(eq(ResolveObjectType.class))).thenReturn(mockResolveObjectType); when(mockResolveObjectType.setObjectId((ObjectId) anyObject())) .thenReturn(mockResolveObjectType); when(mockResolveObjectType.call()).thenReturn(TYPE.COMMIT); }