/** * Private constructor that can create read-only {@code HttpHeader} instances. */ private HttpHeaders(Map<String, List<String>> headers, boolean readOnly) { Assert.notNull(headers, "'headers' must not be null"); if (readOnly) { Map<String, List<String>> map = new LinkedCaseInsensitiveMap<List<String>>(headers.size(), Locale.ENGLISH); for (Entry<String, List<String>> entry : headers.entrySet()) { List<String> values = Collections.unmodifiableList(entry.getValue()); map.put(entry.getKey(), values); } this.headers = Collections.unmodifiableMap(map); } else { this.headers = headers; } }
/** * Create a new {@code MediaType} for the given type, subtype, and parameters. * @param type the primary type * @param subtype the subtype * @param parameters the parameters, may be <code>null</code> * @throws IllegalArgumentException if any of the parameters contain illegal characters */ public MediaType(String type, String subtype, Map<String, String> parameters) { Assert.hasLength(type, "'type' must not be empty"); Assert.hasLength(subtype, "'subtype' must not be empty"); checkToken(type); checkToken(subtype); this.type = type.toLowerCase(Locale.ENGLISH); this.subtype = subtype.toLowerCase(Locale.ENGLISH); if (!CollectionUtils.isEmpty(parameters)) { Map<String, String> m = new LinkedCaseInsensitiveMap<String>(parameters.size(), Locale.ENGLISH); for (Map.Entry<String, String> entry : parameters.entrySet()) { String attribute = entry.getKey(); String value = entry.getValue(); checkParameters(attribute, value); m.put(attribute, value); } this.parameters = Collections.unmodifiableMap(m); } else { this.parameters = Collections.emptyMap(); } }
/** * Create a new {@code ContentCodingType} for the given type, and parameters. * @param type the primary type * @param parameters the parameters, may be <code>null</code> * @throws IllegalArgumentException if any of the parameters contain illegal characters */ public ContentCodingType(String type, Map<String, String> parameters) { Assert.hasLength(type, "'type' must not be empty"); checkToken(type); this.type = type.toLowerCase(Locale.ENGLISH); if (!CollectionUtils.isEmpty(parameters)) { Map<String, String> m = new LinkedCaseInsensitiveMap<String>(parameters.size(), Locale.ENGLISH); for (Map.Entry<String, String> entry : parameters.entrySet()) { String attribute = entry.getKey(); String value = entry.getValue(); checkParameters(attribute, value); m.put(attribute, unquote(value)); } this.parameters = Collections.unmodifiableMap(m); } else { this.parameters = Collections.emptyMap(); } }
/** * Create a new {@code MediaType} for the given type, subtype, and parameters. * @param type the primary type * @param subtype the subtype * @param parameters the parameters, may be {@code null} * @throws IllegalArgumentException if any of the parameters contain illegal characters */ public MediaType(String type, String subtype, Map<String, String> parameters) { Assert.hasLength(type, "type must not be empty"); Assert.hasLength(subtype, "subtype must not be empty"); checkToken(type); checkToken(subtype); this.type = type.toLowerCase(Locale.ENGLISH); this.subtype = subtype.toLowerCase(Locale.ENGLISH); if (!CollectionUtils.isEmpty(parameters)) { Map<String, String> m = new LinkedCaseInsensitiveMap<String>(parameters.size(), Locale.ENGLISH); for (Map.Entry<String, String> entry : parameters.entrySet()) { String attribute = entry.getKey(); String value = entry.getValue(); checkParameters(attribute, value); m.put(attribute, value); } this.parameters = Collections.unmodifiableMap(m); } else { this.parameters = Collections.emptyMap(); } }
private Map<String, Integer> toColNamesMap(Row headerRow) { if (headerRow == null) return null; Map<String, Integer> columnIdx = new LinkedCaseInsensitiveMap<>(); int i = 0; for (Iterator<Cell> it = headerRow.cellIterator(); it.hasNext(); ) { try { String header = AbstractCellProcessor.processCell(ExcelUtils.toValue(it.next()), true, cellProcessors); if (null != header) columnIdx.put(header, i++); } catch (final IllegalStateException ex) { final int row = headerRow.getRowNum(); final String column = CellReference.convertNumToColString(i); throw new IllegalStateException("Invalid value at [" + sheet.getSheetName() + "] " + column + row + 1, ex); } } return columnIdx; }
/** * 获得属性和注解map * * @param clazz * class * @return key属性 value注解 */ public static Map<String, String> getEntityFiledColumnMap(Class<?> clazz) { String kname = clazz.getName(); String k = kname + "#filedColMap#"; if (mapCache.containsKey(k)) { return (Map<String, String>) mapCache.get(k); } Map<String, String> mp = new LinkedCaseInsensitiveMap<>(); List<Field> lsField = JkBeanUtils.getAllFields(clazz); for (Field field : lsField) { // 排除静态 if (Modifier.isStatic(field.getModifiers())) { continue; } String fieldName = field.getName(); if (fieldName.indexOf("CGLIB") > -1) { continue; } Sql Sql = getAnnotation(field,Sql.class); if (Sql != null) { continue; } String columnString; Column column = getAnnotation(field,Column.class); if (column != null) { columnString = column.value(); } else { columnString = JkBeanUtils.columnToHumpReversal(field.getName()); } mp.put(field.getName(), columnString); } mapCache.put(k, mp); return mp; }
/** * 获得属性和注解map * * @param clazz * class * @return key属性 value注解 */ public static Map<String, String> getEntityColumnFiledMap(Class<?> clazz) { String k = clazz.getName() + "#colFiledMap#"; if (mapCache.containsKey(k)) { return (Map<String, String>) mapCache.get(k); } Map<String, String> mp = new LinkedCaseInsensitiveMap<>(); Map<String, String> filedCol = getEntityFiledColumnMap(clazz); for (String key : filedCol.keySet()) { mp.put(filedCol.get(key), key); } mapCache.put(k, mp); return mp; }
/** * Create a Map instance to be used as results map. * <p>If "isResultsMapCaseInsensitive" has been set to true, * a linked case-insensitive Map will be created. * @return the results Map instance * @see #setResultsMapCaseInsensitive */ protected Map<String, Object> createResultsMap() { if (isResultsMapCaseInsensitive()) { return new LinkedCaseInsensitiveMap<Object>(); } else { return new LinkedHashMap<String, Object>(); } }
@Test public void testCaseInsensitiveResultsMap() throws Exception { given(this.callableStatement.execute()).willReturn(false); given(this.callableStatement.getUpdateCount()).willReturn(-1); given(this.callableStatement.getObject(1)).willReturn("X"); assertTrue("default should have been NOT case insensitive", !this.template.isResultsMapCaseInsensitive()); this.template.setResultsMapCaseInsensitive(true); assertTrue("now it should have been set to case insensitive", this.template.isResultsMapCaseInsensitive()); List<SqlParameter> params = new ArrayList<SqlParameter>(); params.add(new SqlOutParameter("a", 12)); Map<String, Object> out = this.template.call(new CallableStatementCreator() { @Override public CallableStatement createCallableStatement(Connection conn) throws SQLException { return conn.prepareCall("my query"); } }, params); assertThat(out, instanceOf(LinkedCaseInsensitiveMap.class)); assertNotNull("we should have gotten the result with upper case", out.get("A")); assertNotNull("we should have gotten the result with lower case", out.get("a")); verify(this.callableStatement).close(); verify(this.connection).close(); }
private static Map<String, String> initParameters(Extension extension) { List<Extension.Parameter> parameters = extension.getParameters(); Map<String, String> result = new LinkedCaseInsensitiveMap<String>(parameters.size(), Locale.ENGLISH); for (Extension.Parameter parameter : parameters) { result.put(parameter.getName(), parameter.getValue()); } return result; }
/** * Create a WebSocketExtension with the given name and parameters. * @param name the name of the extension * @param parameters the parameters */ public WebSocketExtension(String name, Map<String, String> parameters) { Assert.hasLength(name, "extension name must not be empty"); this.name = name; if (!CollectionUtils.isEmpty(parameters)) { Map<String, String> m = new LinkedCaseInsensitiveMap<String>(parameters.size(), Locale.ENGLISH); m.putAll(parameters); this.parameters = Collections.unmodifiableMap(m); } else { this.parameters = Collections.emptyMap(); } }
/** * Constructs the map for triple based on the triple and the rowNum * @param tripleRow * @param rowNum * @return the map with a key and the triple data */ private Map<String, Object> mapTripleRow(T tripleRow, int rowNum) { Map<String, Object> mapOfTriples = new LinkedCaseInsensitiveMap<Object>(1); String key = "triple-" + rowNum; mapOfTriples.put(key, tripleRow); return mapOfTriples; }
@Test public void testCaseInsensitiveResultsMap() throws Exception { given(this.callableStatement.execute()).willReturn(false); given(this.callableStatement.getUpdateCount()).willReturn(-1); given(this.callableStatement.getObject(1)).willReturn("X"); assertTrue("default should have been NOT case insensitive", !this.template.isResultsMapCaseInsensitive()); this.template.setResultsMapCaseInsensitive(true); assertTrue("now it should have been set to case insensitive", this.template.isResultsMapCaseInsensitive()); List<SqlParameter> params = new ArrayList<SqlParameter>(); params.add(new SqlOutParameter("a", 12)); Map out = this.template.call(new CallableStatementCreator() { @Override public CallableStatement createCallableStatement(Connection conn) throws SQLException { return conn.prepareCall("my query"); } }, params); assertThat(out, instanceOf(LinkedCaseInsensitiveMap.class)); assertNotNull("we should have gotten the result with upper case", out.get("A")); assertNotNull("we should have gotten the result with lower case", out.get("a")); verify(this.callableStatement).close(); verify(this.connection).close(); }
@Override public Map<String, String> mapRow(ResultSet rs, int rowNum) throws SQLException { ResultSetMetaData rsmd = rs.getMetaData(); int columnCount = rsmd.getColumnCount(); Map<String, String> mapOfColValues = new LinkedCaseInsensitiveMap<>(columnCount); for (int i = 1; i <= columnCount; i++) { String key = getColumnKey(JdbcUtils.lookupColumnName(rsmd, i)); String obj = formatString(key, getColumnValue(rs, i)); mapOfColValues.put(key, obj); } return mapOfColValues; }
/** * Gets an Attribute (Cell value). * <p> * All values are retrieved as String, returns null if the attributeName is unknown */ @Override public Object get(String attributeName) { if (cachedValueMap == null) { cachedValueMap = new LinkedCaseInsensitiveMap<>(); } Object value; if (cachedValueMap.containsKey(attributeName)) { value = cachedValueMap.get(attributeName); } else { Integer col = colNamesMap.get(attributeName); if (col != null) { Cell cell = row.getCell(col); if (cell != null) { value = ExcelUtils.toValue(cell, cellProcessors); } else { value = null; } } else { value = null; } cachedValueMap.put(attributeName, value); } return value; }
@Override public void set(String attributeName, Object value) { if (cachedValueMap == null) { cachedValueMap = new LinkedCaseInsensitiveMap<>(); } cachedValueMap.put(attributeName, value); }
/** * 初始化 * * @param clazz * class */ private static void initData(Class<?> clazz) { String k = clazz.getName(); List<String> attrs = new ArrayList<>(); List<String> columns = new ArrayList<>(); Map<String, String> cmsql = new LinkedCaseInsensitiveMap<>(); List<Field> listField = JkBeanUtils.getAllFields(clazz); for (Field field : listField) { // 排除静态 if (Modifier.isStatic(field.getModifiers())) { continue; } String fieldName = field.getName(); if (fieldName.contains("CGLIB")) { continue; } Transient tr = getAnnotation(field,Transient.class); if (tr != null) { continue; } Column column = getAnnotation(field,Column.class); String columnString = JkBeanUtils.columnToHumpReversal(fieldName); // 注解字段 if (column != null) { columnString = column.value(); } String KeyMappingColumn = k + "." + fieldName; // 注解sql Sql Sql = getAnnotation(field,Sql.class); if (Sql != null) { cmsql.put(fieldName, Sql.value()); sqlforce.put(KeyMappingColumn, Sql.force()); } else { attrs.add(fieldName); columns.add(columnString); } } entityAttrMp.put(k, attrs); entityColumnMp.put(k, columns); columnSqlMp.put(k, cmsql); }
/** * Constructs a new, empty instance of the {@code HttpHeaders} object. */ public HttpHeaders() { this(new LinkedCaseInsensitiveMap<List<String>>(8, Locale.ENGLISH), false); }
@Override public HttpHeaders getHeaders() { if (this.headers == null) { this.headers = new HttpHeaders(); for (Enumeration<?> headerNames = this.servletRequest.getHeaderNames(); headerNames.hasMoreElements();) { String headerName = (String) headerNames.nextElement(); for (Enumeration<?> headerValues = this.servletRequest.getHeaders(headerName); headerValues.hasMoreElements();) { String headerValue = (String) headerValues.nextElement(); this.headers.add(headerName, headerValue); } } // HttpServletRequest exposes some headers as properties: we should include those if not already present MediaType contentType = this.headers.getContentType(); if (contentType == null) { String requestContentType = this.servletRequest.getContentType(); if (StringUtils.hasLength(requestContentType)) { contentType = MediaType.parseMediaType(requestContentType); this.headers.setContentType(contentType); } } if (contentType != null && contentType.getCharSet() == null) { String requestEncoding = this.servletRequest.getCharacterEncoding(); if (StringUtils.hasLength(requestEncoding)) { Charset charSet = Charset.forName(requestEncoding); Map<String, String> params = new LinkedCaseInsensitiveMap<String>(); params.putAll(contentType.getParameters()); params.put("charset", charSet.toString()); MediaType newContentType = new MediaType(contentType.getType(), contentType.getSubtype(), params); this.headers.setContentType(newContentType); } } if (this.headers.getContentLength() == -1) { int requestContentLength = this.servletRequest.getContentLength(); if (requestContentLength != -1) { this.headers.setContentLength(requestContentLength); } } } return this.headers; }
@Test public void testMapWithTypes() { Map map = (Map) this.beanFactory.getBean("mapWithTypes"); assertTrue(map instanceof LinkedCaseInsensitiveMap); assertEquals(this.beanFactory.getBean("testBean"), map.get("bean")); }
/** * Выполняет формирование коллекции МЕТА-полей из {@link ResultSet}-а * * @param rs {@link ResultSet} формирования записей * @return Возвращает коллекцию сформированных МЕТА-полей */ private Map<String, MetaField> extractMetaFields(ResultSet rs) throws SQLException { final ResultSetMetaData rsmd = rs.getMetaData(); final int columnCount = rsmd.getColumnCount(); MetaField primaryMetaField = null; Map<String, MetaField> metaFields = new LinkedCaseInsensitiveMap<>(columnCount); for (int i = 1; i <= columnCount; i++) { // Формируем МЕТА-поле String name = FormatUtil.parseString(JdbcUtils.lookupColumnName(rsmd, i)); MetaField metaField = new MetaField(); { metaField = injectName(metaField, name); metaField.setOrdinal(i - 1); } // Проверяем, что МЕТА-поле является первичным if (EqualsUtil.lowerCaseEquals(primaryMetaFieldName, name)) { metaField.establishFlags(MetaField.FLAG_PRIMARY); Assert.isNull( primaryMetaField, String.format("Duplicate primary meta field name '%s'", metaField.getName()), DuplicateNameException.class ); primaryMetaField = metaField; } // Сохраняем сформированное МЕТА-поле Assert.isNull( metaFields.put(name, metaField), String.format("Duplicate meta field name '%s'", metaField.getName()), DuplicateNameException.class ); } // Проверяем, что первичное МЕТА-поле задано Assert.notNull( primaryMetaField, String.format("Missing primary meta field with name '%s'", primaryMetaFieldName), IncompleteDataException.class ); return metaFields; }
/** * Create a Map instance to be used as the results map. * <p>If {@link #resultsMapCaseInsensitive} has been set to true, * a {@link LinkedCaseInsensitiveMap} will be created; otherwise, a * {@link LinkedHashMap} will be created. * @return the results Map instance * @see #setResultsMapCaseInsensitive * @see #isResultsMapCaseInsensitive */ protected Map<String, Object> createResultsMap() { if (isResultsMapCaseInsensitive()) { return new LinkedCaseInsensitiveMap<Object>(); } else { return new LinkedHashMap<String, Object>(); } }
/** * Create a Map instance to be used as column map. * <p>By default, a linked case-insensitive Map will be created. * @param columnCount the column count, to be used as initial * capacity for the Map * @return the new Map instance * @see org.springframework.util.LinkedCaseInsensitiveMap */ protected Map<String, Object> createColumnMap(int columnCount) { return new LinkedCaseInsensitiveMap<Object>(columnCount); }
/** * Create a linked case-insensitive Map if possible: This implementation * always returns a {@link org.springframework.util.LinkedCaseInsensitiveMap}. * @param initialCapacity the initial capacity of the Map * @return the new Map instance * @deprecated as of Spring 3.0, for usage on JDK 1.5 or higher */ @Deprecated public static Map createLinkedCaseInsensitiveMapIfPossible(int initialCapacity) { return new LinkedCaseInsensitiveMap(initialCapacity); }