/** * Looks up the given key in the given map, converting the result into * a string, using the default value if the the conversion fails. * * @param map the map whose value to look up * @param key the key of the value to look up in that map * @param defaultValue what to return if the value is null or if the * conversion fails * @return the value in the map as a string, or defaultValue if the * original value is null, the map is null or the string conversion * fails */ public static String getString( Map map, Object key, String defaultValue ) { String answer = getString( map, key ); if ( answer == null ) { answer = defaultValue; } return answer; }
public String getStringProperty( String name ) { return getString( properties, name ); }
public String getStringProperty( String name ) { return getString( properties, name ); }
/** * Looks up the given key in the given map, converting the result into * a string, using the default value if the the conversion fails. * * @param map the map whose value to look up * @param key the key of the value to look up in that map * @param defaultValue what to return if the value is null or if the * conversion fails * @return the value in the map as a string, or defaultValue if the * original value is null, the map is null or the string conversion * fails */ public static String getString( Map map, Object key, String defaultValue ) { String answer = getString( map, key ); if ( answer == null ) { answer = defaultValue; } return answer; }
@JsonIgnore public String getType() { return getString( properties, MESSAGE_TYPE ); }
@JsonIgnore public String getPath() { return getString( properties, QUEUE_PATH ); }
@JsonIgnore public String getCategory() { return getString( properties, MESSAGE_CATEGORY ); }
@JsonIgnore public String getCorrelationID() { return getString( properties, MESSAGE_CORRELATION_ID ); }
@JsonIgnore public Queue getReplyTo() { return Queue.getDestination( getString( properties, MESSAGE_REPLY_TO ) ); }
@JsonIgnore public Queue getDestination() { return Queue.getDestination( getString( properties, MESSAGE_DESTINATION ) ); }
private String replaceDefaultKeywordForMerge(String valueClause, Table table, ASTNode columnListNode) throws SemanticException { if (!valueClause.toLowerCase().contains("`default`")) { return valueClause; } Map<String, String> colNameToDefaultConstraint = getColNameToDefaultValueMap(table); String[] values = valueClause.trim().split(","); String[] replacedValues = new String[values.length]; // the list of the column names may be set in the query String[] columnNames = columnListNode == null ? table.getAllCols().stream().map(f -> f.getName()).toArray(size -> new String[size]) : columnListNode.getChildren().stream().map(n -> ((ASTNode)n).toString()).toArray(size -> new String[size]); for (int i = 0; i < values.length; i++) { if (values[i].trim().toLowerCase().equals("`default`")) { replacedValues[i] = MapUtils.getString(colNameToDefaultConstraint, columnNames[i], "null"); } else { replacedValues[i] = values[i]; } } return StringUtils.join(replacedValues, ','); }
/** Create the keyspace */ private void createKeySpace( String keyspace ) { logger.info( "Creating keyspace: {}", keyspace ); String strategy_class = getString( properties, "cassandra.keyspace.strategy", "org.apache.cassandra.locator.SimpleStrategy" ); logger.info( "Using strategy: {}", strategy_class ); int replication_factor = getIntValue( properties, "cassandra.keyspace.replication", 1 ); logger.info( "Using replication (may be overriden by strategy options): {}", replication_factor ); // try { ThriftKsDef ks_def = ( ThriftKsDef ) HFactory .createKeyspaceDefinition( keyspace, strategy_class, replication_factor, new ArrayList<ColumnFamilyDefinition>() ); @SuppressWarnings({ "unchecked", "rawtypes" }) Map<String, String> strategy_options = filter( ( Map ) properties, "cassandra.keyspace.strategy.options.", true ); if ( strategy_options.size() > 0 ) { logger.info( "Strategy options: {}", mapToFormattedJsonString( strategy_options ) ); ks_def.setStrategyOptions( strategy_options ); } cluster.addKeyspace( ks_def ); waitForCreation( keyspace ); logger.info( "Created keyspace {}", keyspace ); }
@Test public void testRemoveNamespaces() throws Exception { Map props = new HashMap(); props.put("blah.booleanProperty", "true"); props.put("blah.blah.doubleProperty", NumberFormat.getInstance().format(0.124)); props.put("blah.blah.Blah.intProperty", "14"); props.put("longProperty", "999999999"); props.put("3456.stringProperty", "string"); props = PropertiesUtils.removeNamespaces(props); assertTrue(getBooleanValue(props, "booleanProperty", false)); assertEquals(0.124, 0, getDoubleValue(props, "doubleProperty", 0)); assertEquals(14, getIntValue(props, "intProperty", 0)); assertEquals(999999999, 0, getLongValue(props, "longProperty", 0)); assertEquals("string", getString(props, "stringProperty", "")); }
@Override public Map<String, String> handlePropertyIsEqualToNumber( String propertyName, double literal ) { Map<String, String> filterContainer = new HashMap<String, String>(); filterContainer.put( MapUtils.getString( propertyMap, propertyName, propertyName ), String.valueOf( literal ) ); return filterContainer; }
@Override public Map<String, String> handleTimeAfter( String propertyName, Date start, boolean inclusive ) { Map<String, String> filterContainer = new HashMap<String, String>(); filterContainer.put( SearchConstants.STARTDATE_PARAMETER, DATE_FORMATTER.print( start.getTime() ) ); filterContainer.put( SearchConstants.DATETYPE_PARAMETER, MapUtils.getString( dateTypeMap, propertyName, propertyName ) ); return filterContainer; }
@Override public Map<String, String> handleTimeBefore( String propertyName, Date end, boolean inclusive ) { Map<String, String> filterContainer = new HashMap<String, String>(); filterContainer.put( SearchConstants.ENDDATE_PARAMETER, DATE_FORMATTER.print( end.getTime() ) ); filterContainer.put( SearchConstants.DATETYPE_PARAMETER, MapUtils.getString( dateTypeMap, propertyName, propertyName ) ); return filterContainer; }
@Override public Map<String, String> handleTimeDuring( String propertyName, Date start, Date end ) { Map<String, String> filterContainer = new HashMap<String, String>(); filterContainer.put( SearchConstants.STARTDATE_PARAMETER, DATE_FORMATTER.print( start.getTime() ) ); filterContainer.put( SearchConstants.ENDDATE_PARAMETER, DATE_FORMATTER.print( end.getTime() ) ); filterContainer.put( SearchConstants.DATETYPE_PARAMETER, MapUtils.getString( dateTypeMap, propertyName, propertyName ) ); return filterContainer; }
public CannedAccessControlList getCannedAcl() { String cannedAcl = MapUtils.getString(copierOptions, Keys.CANNED_ACL.keyName(), null); if (cannedAcl != null) { return CannedAclUtils.toCannedAccessControlList(cannedAcl); } return null; }
@Override public String render(Renderable subject, Map<String, Object> properties) { final String contextPath = MapUtils.getString(properties, RenderPropertyConstants.CONTEXT_PATH, ""); NotificationLink linkData = (NotificationLink) subject; return "<a href='" + contextPath + "/" + linkData.getType().getType() + "/" + linkData.getId() + "' class='" + linkClass + "'>" + StringEscapeUtils.escapeHtml(linkData.getName()) + "</a>"; }
@SuppressWarnings("rawtypes") public static Object getString(ActionContext actionContext){ Thing self = actionContext.getObject("self"); Map map = (Map) self.doAction("getMap", actionContext); Object key = self.doAction("getKey", actionContext); Object result = MapUtils.getString(map, key); if(result == null){ return self.doAction("getDefaultValue", actionContext); }else{ return result; } }