List of usage examples for com.google.common.collect Maps newHashMap
public static <K, V> HashMap<K, V> newHashMap()
From source file:org.graylog2.plugin.RadioMessage.java
public static byte[] serialize(MessagePack pack, Message msg) throws IOException { Map<String, Long> longs = Maps.newHashMap(); Map<String, String> strings = Maps.newHashMap(); Map<String, Double> doubles = Maps.newHashMap(); for (Map.Entry<String, Object> field : msg.getFieldsEntries()) { if (field.getValue() instanceof String) { strings.put(field.getKey(), (String) field.getValue()); } else if (field.getValue() instanceof Long || field.getValue() instanceof Integer) { longs.put(field.getKey(), ((Number) field.getValue()).longValue()); } else if (field.getValue() instanceof Double || field.getValue() instanceof Float) { doubles.put(field.getKey(), ((Number) field.getValue()).doubleValue()); } else if (field.getValue() instanceof Boolean) { strings.put(field.getKey(), field.getValue().toString()); } else if (field.getValue() instanceof Character) { strings.put(field.getKey(), String.valueOf(field.getValue())); }/* w w w . ja v a 2s.c om*/ } RadioMessage radioMessage = new RadioMessage(); radioMessage.strings = strings; radioMessage.longs = longs; radioMessage.doubles = doubles; radioMessage.timestamp = ((DateTime) msg.getField("timestamp")).getMillis(); return pack.write(radioMessage); }
From source file:org.auraframework.throwable.quickfix.RemoveAttributeQuickFix.java
private static Map<String, Object> createMap(DefDescriptor<?> descriptor, String attName, String query) { Map<String, Object> ret = Maps.newHashMap(); ret.put("descriptor", String.format(descriptor.getQualifiedName())); ret.put("attName", attName); ret.put("query", query); return ret;/*from www . ja v a 2 s . co m*/ }
From source file:com.getbase.forger.tests.EchoContentResolver.java
public static ContentResolver get() { final ContentResolver resolverMock = mock(ContentResolver.class); final Map<Uri, ContentValues> storedData = Maps.newHashMap(); when(resolverMock.insert(any(Uri.class), any(ContentValues.class))).thenAnswer(new Answer<Uri>() { @Override//from w w w.j a v a2s .c o m public Uri answer(InvocationOnMock invocation) throws Throwable { final Object[] args = invocation.getArguments(); Uri uri = (Uri) args[0]; ContentValues values = (ContentValues) args[1]; for (String key : getKeysOf(values)) { Object value = values.get(key); if (value instanceof Boolean) { values.put(key, ((Boolean) value) ? 1 : 0); } } Uri result = generateUri(uri); values.put(BaseColumns._ID, sId); if (!values.containsKey("updated_at")) { values.put("updated_at", "now"); } storedData.put(result, values); return result; } }); when(resolverMock.query(any(Uri.class), any(String[].class), anyString(), any(String[].class), anyString())) .thenAnswer(new Answer<Cursor>() { @Override public Cursor answer(InvocationOnMock invocation) throws Throwable { final Object[] args = invocation.getArguments(); Uri uri = (Uri) args[0]; String[] projection = (String[]) args[1]; Preconditions.checkState(storedData.containsKey(uri)); final ContentValues values = storedData.get(uri); Set<String> storedColumns = Sets.newHashSet(getKeysOf(values)); Preconditions.checkState(storedColumns.containsAll(Sets.newHashSet(projection))); MatrixCursor cursor = new MatrixCursor(projection, 1); cursor.addRow( Lists.transform(Lists.newArrayList(projection), new Function<String, Object>() { @Override public Object apply(String key) { return values.get(key); } }).toArray()); return cursor; } }); return resolverMock; }
From source file:io.druid.indexing.common.TaskReport.java
static Map<String, TaskReport> buildTaskReports(TaskReport... taskReports) { Map<String, TaskReport> taskReportMap = Maps.newHashMap(); for (TaskReport taskReport : taskReports) { taskReportMap.put(taskReport.getReportKey(), taskReport); }/*from www .jav a 2s.co m*/ return taskReportMap; }
From source file:com.collective.celos.ci.testing.fixtures.deploy.hive.StringArrayFixTableCreator.java
public static FixTable createFixTable(String[] columnNames, List<String[]> data) { List<FixTable.FixRow> fixRows = Lists.newArrayList(); for (String[] rowData : data) { Map<String, String> rowContent = Maps.newHashMap(); for (int i = 0; i < columnNames.length; i++) { rowContent.put(columnNames[i], rowData[i]); }//from ww w . j av a 2 s . c o m fixRows.add(new FixTable.FixRow(rowContent)); } FixTable fixTable = new FixTable(Lists.newArrayList(columnNames), fixRows); return fixTable; }
From source file:io.druid.sql.calcite.expression.ExpressionConverter.java
public static ExpressionConverter create(final List<ExpressionConversion> conversions) { final Map<SqlKind, ExpressionConversion> kindMap = Maps.newHashMap(); final Map<String, ExpressionConversion> otherFunctionMap = Maps.newHashMap(); for (final ExpressionConversion conversion : conversions) { if (conversion.sqlKind() != SqlKind.OTHER_FUNCTION) { if (kindMap.put(conversion.sqlKind(), conversion) != null) { throw new ISE("Oops, can't have two conversions for sqlKind[%s]", conversion.sqlKind()); }/* www.ja v a 2 s . com*/ } else { // kind is OTHER_FUNCTION if (otherFunctionMap.put(conversion.operatorName(), conversion) != null) { throw new ISE("Oops, can't have two conversions for sqlKind[%s], operatorName[%s]", conversion.sqlKind(), conversion.operatorName()); } } } return new ExpressionConverter(kindMap, otherFunctionMap); }
From source file:org.apache.apex.engine.security.ACLManager.java
public static void setupUserACLs(ContainerLaunchContext launchContext, String userName, Configuration conf) throws IOException { logger.debug("Setup login acls {}", userName); if (areACLsRequired(conf)) { logger.debug("Configuring ACLs for {}", userName); Map<ApplicationAccessType, String> acls = Maps.newHashMap(); acls.put(ApplicationAccessType.VIEW_APP, userName); acls.put(ApplicationAccessType.MODIFY_APP, userName); launchContext.setApplicationACLs(acls); }// ww w .ja v a 2 s . c om }
From source file:org.openqa.grid.web.utils.BrowserNameUtils.java
public static Map<String, Object> parseGrid2Environment(String environment) { Map<String, Object> ret = Maps.newHashMap(); String[] details = environment.split(" "); if (details.length == 1) { // simple browser string ret.put(RegistrationRequest.BROWSER, details[0]); } else {// w w w .j a v a 2 s . c om // more complex. Only case handled so far = X on Y // where X is the browser string, Y the OS ret.put(RegistrationRequest.BROWSER, details[0]); if (details.length == 3) { ret.put(RegistrationRequest.PLATFORM, Platform.extractFromSysProperty(details[2])); } } return ret; }
From source file:com.enonic.cms.core.portal.datasource.executor.DataSourceInvokerImpl.java
public DataSourceInvokerImpl() { this.handlers = Maps.newHashMap(); }
From source file:com.cloudera.exhibit.core.composite.CompositeExhibit.java
public static CompositeExhibit create(ExhibitDescriptor descriptor, List<Exhibit> components) { Map<String, Frame> frames = Maps.newHashMap(); List<Obs> attrs = Lists.newArrayList(); for (Exhibit e : components) { attrs.add(e.attributes());/*ww w .java 2 s . co m*/ frames.putAll(e.frames()); } CompositeObsDescriptor cod = (CompositeObsDescriptor) descriptor.attributes(); return new CompositeExhibit(descriptor, new CompositeObs(cod, attrs), frames); }