Java Code Examples for java.util.Map.toString()

The following are Jave code examples for showing how to use toString() of the java.util.Map class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: neoscada   File: DiffEntryLabelProvider.java   View Source Code Vote up 8 votes
private String formatData ( final Map<String, String> data, final int maxLen )
{
    if ( data == null )
    {
        return null;
    }

    final String str = data.toString ();
    if ( maxLen > 0 && str.length () > maxLen )
    {
        return str.substring ( 0, maxLen ) + "…";
    }
    else
    {
        return str;
    }
}
 
Example 2
Project: strongbox   File: GenericDynamoDB.java   View Source Code Vote up 7 votes
@Override
public void update(Entry entry, Entry existingEntry) {
    readWriteLock.writeLock().lock();

    try {
        Map<String, AttributeValue> keys = createKey(entry);
        Map<String, AttributeValueUpdate> attributes = createAttributes(entry);
        Map<String, ExpectedAttributeValue> expected = expectExists(existingEntry);

        try {
            executeUpdate(keys, attributes, expected);
        } catch (ConditionalCheckFailedException e) {
            throw new DoesNotExistException("Precondition to update entry in DynamoDB failed:" + keys.toString());
        }
    } finally {
        readWriteLock.writeLock().unlock();
    }

}
 
Example 3
Project: strongbox   File: GenericDynamoDB.java   View Source Code Vote up 6 votes
@Override
public void create(Entry entry) {
    readWriteLock.writeLock().lock();

    try {
        Map<String, AttributeValue> keys = createKey(entry);
        Map<String, AttributeValueUpdate> attributes = createAttributes(entry);
        Map<String, ExpectedAttributeValue> expected = expectNotExists();

        try {
            executeUpdate(keys, attributes, expected);
        } catch (ConditionalCheckFailedException e) {
            throw new AlreadyExistsException("DynamoDB store entry already exists:" + keys.toString());
        }
    } finally {
        readWriteLock.writeLock().unlock();
    }
}
 
Example 4
Project: lams   File: ComponentType.java   View Source Code Vote up 6 votes
@Override
public String toLoggableString(Object value, SessionFactoryImplementor factory)
		throws HibernateException {
	if ( value == null ) {
		return "null";
	}

	if ( entityMode == null ) {
		throw new ClassCastException( value.getClass().getName() );
	}
	Map<String,String> result = new HashMap<String, String>();
	Object[] values = getPropertyValues( value, entityMode );
	for ( int i = 0; i < propertyTypes.length; i++ ) {
		result.put( propertyNames[i], propertyTypes[i].toLoggableString( values[i], factory ) );
	}
	return StringHelper.unqualify( getName() ) + result.toString();
}
 
Example 5
Project: parabuild-ci   File: Printer.java   View Source Code Vote up 5 votes
public String toString(Map namedTypedValues) throws HibernateException {
	Map result = new HashMap();
	Iterator iter = namedTypedValues.entrySet().iterator();
	while ( iter.hasNext() ) {
		Map.Entry me = (Map.Entry) iter.next();
		TypedValue tv = (TypedValue) me.getValue();
		result.put( me.getKey(), tv.getType().toString( tv.getValue(), factory ) );
	}
	return result.toString();
}
 
Example 6
Project: googles-monorepo-demo   File: MapToStringTester.java   View Source Code Vote up 5 votes
private String expectedToString(Set<Entry<K, V>> entries) {
  Map<K, V> reference = new LinkedHashMap<K, V>();
  for (Map.Entry<K, V> entry : entries) {
    reference.put(entry.getKey(), entry.getValue());
  }
  return reference.toString();
}
 
Example 7
Project: incubator-netbeans   File: Pre90403Phase1CompatibilityTest.java   View Source Code Vote up 5 votes
public void testKeybindings() {
    MimeTypesTracker tracker = MimeTypesTracker.get(KeyMapsStorage.ID, "Editors");
    Set<String> mimeTypes = new HashSet<String>(tracker.getMimeTypes());
    Set<String> profiles = EditorSettings.getDefault().getKeyMapProfiles();
    
    for(String profile : profiles) {
        List<MultiKeyBinding> commonKeybindings = EditorSettings.getDefault().getKeyBindingSettings(new String[0]).getKeyBindings(profile);
        Map<String, String> commonNorm = normalize(commonKeybindings);

        String commonCurrent = commonNorm.toString();
        String commonGolden = fromFile("KB--" + profile);

        assertEquals("Wrong keybindings for '', profile '" + profile + "'", commonGolden, commonCurrent);

        for(String mimeType : mimeTypes) {
            List<MultiKeyBinding> keybindings = EditorSettings.getDefault().getKeyBindingSettings(mimeType.length() == 0 ? new String[0] : new String [] { mimeType }).getKeyBindings(profile);

            Map<String, String> mimeTypeNorm = new TreeMap<String, String>();
            Map<String, String> norm = normalize(keybindings);
            
            mimeTypeNorm.putAll(commonNorm);
            mimeTypeNorm.putAll(norm);
            
            String current = mimeTypeNorm.toString();
            String golden = fromFile("KB-" + mimeType.replace("/", "-") + "-" + profile);
            
            assertEquals("Wrong keybindings for '" + mimeType + "', profile '" + profile + "'", golden, current);
        }
    }
}
 
Example 8
Project: heat   File: DataExtractionSupport.java   View Source Code Vote up 5 votes
/**
 * This method is used when "actualValue" or "expectedValue" are json object and not simple strings.
 * In particular it can manage:
 * - regular expression extraction
 * - occurrence of a given string in another string
 * - ... TBD
 * @param map it is the map representing the json object of the "actualValue" or "expectedValue"
 * @param response is the response retrieved from the service under test.
 * @return the final string to use for the verification step
 */
private String processMap(Map map, Response response) {
    String outputStr = "";
    if (map.containsKey(REGEXP_JSON_ELEMENT) && map.containsKey(STRING_TO_PARSE_JSON_ELEMENT)) {
        outputStr = regexpExtractorProcessing(map, response);
    } else if (map.containsKey(REGEXP_MATCH_JSON_ELEMENT) && map.containsKey(STRING_TO_PARSE_JSON_ELEMENT)) {
        outputStr = regexpMatchExtractorProcessing(map, response);
    } else if (map.containsKey(OCCURRENCE_JSON_ELEMENT) && map.containsKey(STRING_TO_PARSE_JSON_ELEMENT)) {
        outputStr = occurrenceOfProcessing(map, response);
    } else {
        throw new HeatException(logUtils.getExceptionDetails() + "configuration " + map.toString() + " not supported");
    }
    return outputStr;
}
 
Example 9
Project: YiDu-Novel   File: WeixinUtils.java   View Source Code Vote up 5 votes
public static String getAccessTokenFromWeixin() throws Exception {
    String body = HttpRequest.get("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" +
            Const.WX_APP_ID + "&secret=" + Const.WX_APP_SECRET).body();
    Map result = JSON.parseObject(body, Map.class);
    String accessToken = (String) result.get("access_token");
    if (accessToken == null) {
        throw new Exception(result.toString());
    }
    return accessToken;
}
 
Example 10
Project: guava-mock   File: MapToStringTester.java   View Source Code Vote up 5 votes
private String expectedToString(Set<Entry<K, V>> entries) {
  Map<K, V> reference = new LinkedHashMap<K, V>();
  for (Map.Entry<K, V> entry : entries) {
    reference.put(entry.getKey(), entry.getValue());
  }
  return reference.toString();
}
 
Example 11
Project: JavaGraph   File: Options.java   View Source Code Vote up 5 votes
/** Returns a map from option keys to the enabled status of the option. */
@Override
public String toString() {
    Map<String,Boolean> result = new HashMap<>();
    for (Map.Entry<String,JMenuItem> entry : this.itemMap.entrySet()) {
        result.put(entry.getKey(), entry.getValue()
            .isSelected());
    }
    return result.toString();
}
 
Example 12
Project: lams   File: EntityPrinter.java   View Source Code Vote up 5 votes
/**
 * Renders an entity to a string.
 *
 * @param entityName the entity name
 * @param entity an actual entity object, not a proxy!
 * @return the entity rendered to a string
 */
public String toString(String entityName, Object entity) throws HibernateException {
	EntityPersister entityPersister = factory.getEntityPersister( entityName );

	if ( entityPersister == null ) {
		return entity.getClass().getName();
	}

	Map<String,String> result = new HashMap<String,String>();

	if ( entityPersister.hasIdentifierProperty() ) {
		result.put(
			entityPersister.getIdentifierPropertyName(),
			entityPersister.getIdentifierType().toLoggableString( entityPersister.getIdentifier( entity ), factory )
		);
	}

	Type[] types = entityPersister.getPropertyTypes();
	String[] names = entityPersister.getPropertyNames();
	Object[] values = entityPersister.getPropertyValues( entity );
	for ( int i=0; i<types.length; i++ ) {
		if ( !names[i].startsWith("_") ) {
			String strValue = values[i]==LazyPropertyInitializer.UNFETCHED_PROPERTY ?
				values[i].toString() :
				types[i].toLoggableString( values[i], factory );
			result.put( names[i], strValue );
		}
	}
	return entityName + result.toString();
}
 
Example 13
Project: errorest-spring-boot-starter   File: HttpUtils.java   View Source Code Vote up 5 votes
public static String getHeadersAsText(HttpServletRequest request) {
    Map<String, String> headers = new HashMap<>();
    Enumeration<String> names = request.getHeaderNames();
    while (names.hasMoreElements()) {
        String name = names.nextElement();
        if (!name.equals(AUTHORIZATION)) {
            headers.put(name, request.getHeader(name));
        }
    }
    return headers.toString();
}
 
Example 14
Project: Project-SADS   File: CommandResponse.java   View Source Code Vote up 5 votes
public CommandResponse(Map<String, Integer> input) {
	responseType = "WordCount";
	this.returnVal = input.toString();
}
 
Example 15
Project: Reer   File: ImmutableAttributes.java   View Source Code Vote up 4 votes
@Override
public String toString() {
    Map<Attribute<?>, Object> sorted = new TreeMap<Attribute<?>, Object>(ATTRIBUTE_NAME_COMPARATOR);
    sorted.putAll(attributes);
    return sorted.toString();
}
 
Example 16
Project: echo   File: EdgentFilter_RBI.java   View Source Code Vote up 4 votes
private void update(Map<String, String> tuple) {
	// TODO Auto-generated method stub
	//System.out.println("String" + tuple);
	resultString += tuple.toString()+ "\n";
}
 
Example 17
Project: echo   File: EdgentFilter_RBI.java   View Source Code Vote up 4 votes
private void update(Map<String, String> tuple) {
	// TODO Auto-generated method stub
	//System.out.println("String" + tuple);
	resultString += tuple.toString()+ "\n";
}
 
Example 18
Project: elasticsearch_my   File: DynamicTemplate.java   View Source Code Vote up 4 votes
public static DynamicTemplate parse(String name, Map<String, Object> conf,
        Version indexVersionCreated) throws MapperParsingException {
    String match = null;
    String pathMatch = null;
    String unmatch = null;
    String pathUnmatch = null;
    Map<String, Object> mapping = null;
    String matchMappingType = null;
    String matchPattern = MatchType.SIMPLE.toString();

    for (Map.Entry<String, Object> entry : conf.entrySet()) {
        String propName = entry.getKey();
        if ("match".equals(propName)) {
            match = entry.getValue().toString();
        } else if ("path_match".equals(propName)) {
            pathMatch = entry.getValue().toString();
        } else if ("unmatch".equals(propName)) {
            unmatch = entry.getValue().toString();
        } else if ("path_unmatch".equals(propName)) {
            pathUnmatch = entry.getValue().toString();
        } else if ("match_mapping_type".equals(propName)) {
            matchMappingType = entry.getValue().toString();
        } else if ("match_pattern".equals(propName)) {
            matchPattern = entry.getValue().toString();
        } else if ("mapping".equals(propName)) {
            mapping = (Map<String, Object>) entry.getValue();
        } else if (indexVersionCreated.onOrAfter(Version.V_5_0_0_alpha1)) {
            // unknown parameters were ignored before but still carried through serialization
            // so we need to ignore them at parsing time for old indices
            throw new IllegalArgumentException("Illegal dynamic template parameter: [" + propName + "]");
        }
    }

    if (match == null && pathMatch == null && matchMappingType == null) {
        throw new MapperParsingException("template must have match, path_match or match_mapping_type set " + conf.toString());
    }
    if (mapping == null) {
        throw new MapperParsingException("template must have mapping set");
    }

    XContentFieldType xcontentFieldType = null;
    if (matchMappingType != null && matchMappingType.equals("*") == false) {
        try {
            xcontentFieldType = XContentFieldType.fromString(matchMappingType);
        } catch (IllegalArgumentException e) {
            if (indexVersionCreated.onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED)) {
                throw e;
            } else {
                DEPRECATION_LOGGER.deprecated("match_mapping_type [" + matchMappingType + "] is invalid and will be ignored: "
                        + e.getMessage());
                // this template is on an unknown type so it will never match anything
                // null indicates that the template should be ignored
                return null;
            }
        }
    }
    return new DynamicTemplate(name, pathMatch, pathUnmatch, match, unmatch, xcontentFieldType, MatchType.fromString(matchPattern), mapping);
}
 
Example 19
Project: intfocus_coding   File: 王义飞-storeLevel.java   View Source Code Vote up 4 votes
@SuppressWarnings("unchecked")
public void testStore(Integer[][] twoDimensional){

	Map<Integer , Object> root = new HashMap<Integer,Object>() ;
	Map<Integer , Object> parentMap = null ;
	Map<Integer , Object> parentMapTmp = null ;
	Integer parentValue = null;
	String tree = "" ;

	for(int i = 0 ; i < twoDimensional.length ; i ++){
		parentMap = null ;
		for(int j = 0 ; j < twoDimensional[i].length; j ++){
			if(null == twoDimensional[i][j]){
				continue;
			}
			if( null == parentMap){
				// parentMap 为空说明是第一层遍历是森林中每棵树的根节点
				if(!root.containsKey(twoDimensional[i][j])){
					root.put(twoDimensional[i][j], null);
				}
				parentValue = twoDimensional[i][j];
				parentMap = root;
			}else{
				if(null ==parentMap.get(parentValue)){
					// n 节点下没有孩子的情况
					parentMapTmp = new HashMap<Integer,Object>();
					parentMapTmp.put(twoDimensional[i][j], null);
					parentMap.put(parentValue, parentMapTmp);
					parentValue = twoDimensional[i][j];
					parentMap = parentMapTmp;
				}else{
					// n 节点下有孩子的情况
					parentMap = (HashMap<Integer,Object>)parentMap.get(parentValue);
					parentValue = twoDimensional[i][j];
					if(!parentMap.containsKey(parentValue)){
						parentMap.put(parentValue,null);
					}
				}
			  }
			}
		}
	System.out.println("------------森林结构-----------");
	tree = root.toString();
	System.out.println(tree.replace("=", ":"));
}
 
Example 20
Project: monarch   File: MTableScanServerFailureDUnitTest.java   View Source Code Vote up 4 votes
public void testInProgressScanWithServerDown(boolean batchMode, String tableName) {
  // create table from client-1
  int totalSplits = 1;
  // createTableFromClient(this.client1);
  createSingleBucketTableFromClient(this.client1, 1, 0, tableName);
  /* put from client 2 */
  MClientCache cache = MClientCacheFactory.getAnyInstance();
  assertNotNull(cache);
  MTable table = cache.getTable(tableName);
  assertNotNull(table);
  int expectedTotalRows = 500000;
  doPuts2(expectedTotalRows, tableName);

  Scan scan = new Scan();
  if (batchMode) {
    scan.enableBatchMode();
  }
  Scanner scanner = table.getScanner(scan);
  int totalRecordsScaned = validateScan(scanner);
  assertEquals(expectedTotalRows, totalRecordsScaned);
  System.out.println("TEST  :: number of rows Scanned: " + totalRecordsScaned);

  Map<Integer, ServerLocation> primaryBucketMap = new HashMap<>(113);
  MTableUtils.getLocationMap(table, null, primaryBucketMap, null, AmpoolOpType.SCAN_OP);
  String locationString = primaryBucketMap.toString();
  System.out.println("TEST primaryBucketMap = " + locationString);
  String requiredString =
      locationString.substring(locationString.indexOf(":") + 1, locationString.indexOf("}"));

  // Iterate over vmToPortMap and find the targeted server
  Map<Integer, String> portToVMMap = new HashMap<>();
  for (Map.Entry<String, Integer> nodeEntry : vmToPortMap.entrySet()) {
    portToVMMap.put(nodeEntry.getValue(), nodeEntry.getKey());
  }
  String node = portToVMMap.get(Integer.valueOf(requiredString));
  System.out.println("TEST Targetted node to down = " + node);

  scan = new Scan();
  if (batchMode) {
    scan.enableBatchMode();
  }
  scanner = table.getScanner(scan);
  boolean caughtException = false;
  try {
    validateBucketScanWithServerDown(scanner, expectedTotalRows, node);
  } catch (MScanSplitUnavailableException ex) {
    // This is excepted exception
    caughtException = true;
  }
  assertTrue(caughtException);
  deleteTable(tableName);
}