All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.dslplatform.json.runtime.ReadPropertyInfo Maven / Gradle / Ivy

There is a newer version: 1.10.0
Show newest version
package com.dslplatform.json.runtime;

import java.util.HashSet;

class ReadPropertyInfo {
	public final String name;
	public final int hash;
	public final boolean exactName;
	public final T value;

	ReadPropertyInfo(String name, boolean exactName, T value) {
		this.name = name;
		this.exactName = exactName;
		this.value = value;
		long hash = 0x811c9dc5;
		for (int x = 0; x < name.length(); x++) {
			hash ^= (byte) name.charAt(x);
			hash *= 0x1000193;
		}
		this.hash = (int) hash;
	}

	static  ReadPropertyInfo[] prepareReaders(ReadPropertyInfo[] initial) {
		final ReadPropertyInfo[] readers = initial.clone();
		final HashSet hashes = new HashSet();
		for (final ReadPropertyInfo ri : readers) {
			if (!hashes.add(ri.hash)) {
				for (int j = 0; j < readers.length; j++) {
					final ReadPropertyInfo si = readers[j];
					if (si.hash == ri.hash && !si.exactName) {
						readers[j] = new ReadPropertyInfo<>(ri.name, true, ri.value);
					}
				}
			}
		}
		return readers;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy