use of java.util.LinkedHashMap in project wire by square.
the class SchemaLoader method load.
public Schema load() throws IOException {
if (sources.isEmpty()) {
throw new IllegalStateException("No sources added.");
}
try (Closer closer = Closer.create()) {
// Map the physical path to the file system root. For regular directories the key and the
// value are equal. For ZIP files the key is the path to the .zip, and the value is the root
// of the file system within it.
Map<Path, Path> directories = new LinkedHashMap<>();
for (Path source : sources) {
if (Files.isRegularFile(source)) {
FileSystem sourceFs = FileSystems.newFileSystem(source, getClass().getClassLoader());
closer.register(sourceFs);
directories.put(source, getOnlyElement(sourceFs.getRootDirectories()));
} else {
directories.put(source, source);
}
}
return loadFromDirectories(directories);
}
}
use of java.util.LinkedHashMap in project spring-security-oauth by spring-projects.
the class DefaultClientKeyGenerator method extractKey.
public String extractKey(OAuth2ProtectedResourceDetails resource, Authentication authentication) {
Map<String, String> values = new LinkedHashMap<String, String>();
if (authentication != null) {
values.put(USERNAME, authentication.getName());
}
values.put(CLIENT_ID, resource.getClientId());
if (resource.getScope() != null) {
values.put(SCOPE, OAuth2Utils.formatParameterList(resource.getScope()));
}
MessageDigest digest;
try {
digest = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
throw new IllegalStateException("MD5 algorithm not available. Fatal (should be in the JDK).");
}
try {
byte[] bytes = digest.digest(values.toString().getBytes("UTF-8"));
return String.format("%032x", new BigInteger(1, bytes));
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException("UTF-8 encoding not available. Fatal (should be in the JDK).");
}
}
use of java.util.LinkedHashMap in project wire by square.
the class JavaGenerator method get.
public static JavaGenerator get(Schema schema) {
Map<ProtoType, ClassName> nameToJavaName = new LinkedHashMap<>();
nameToJavaName.putAll(BUILT_IN_TYPES_MAP);
for (ProtoFile protoFile : schema.protoFiles()) {
String javaPackage = javaPackage(protoFile);
putAll(nameToJavaName, javaPackage, null, protoFile.types());
for (Service service : protoFile.services()) {
ClassName className = ClassName.get(javaPackage, service.type().simpleName());
nameToJavaName.put(service.type(), className);
}
}
return new JavaGenerator(schema, nameToJavaName, new Profile(), false, false);
}
use of java.util.LinkedHashMap in project jewelcli by lexicalscope.
the class ArgumentPresenterImpl method presentArguments.
@Option
public O presentArguments(final OptionCollection validatedArguments) throws ArgumentValidationException {
final Map<String, Object> argumentMap = new LinkedHashMap<String, Object>();
final ValidationErrorBuilder validationErrorBuilder = new ValidationErrorBuilderImpl();
for (final ParsedOptionSpecification optionSpecification : specification) {
final ConvertTypeOfObject<?> convertTypeOfObject = converterTo(validationErrorBuilder, optionSpecification, optionSpecification.getMethod());
putDefaultInMap(argumentMap, optionSpecification, convertTypeOfObject);
final Argument argument = validatedArguments.getArgument(optionSpecification);
if (argument != null) {
putValuesInMap(argumentMap, optionSpecification, convertTypeOfObject, argument.getValues());
}
}
if (specification.hasUnparsedSpecification()) {
final UnparsedOptionSpecification unparsedSpecification = specification.getUnparsedSpecification();
final ConvertTypeOfObject<?> convertTypeOfObject = converterTo(validationErrorBuilder, unparsedSpecification, unparsedSpecification.getMethod());
putDefaultInMap(argumentMap, unparsedSpecification, convertTypeOfObject);
if (!validatedArguments.getUnparsed().isEmpty()) {
putValuesInMap(argumentMap, unparsedSpecification, convertTypeOfObject, validatedArguments.getUnparsed());
}
}
validationErrorBuilder.validate();
return argumentPresentingStrategy.presentArguments(argumentMap);
}
use of java.util.LinkedHashMap in project libgdx by libgdx.
the class FileProcessor method process.
/** Processes the specified input files.
* @param outputRoot May be null if there is no output from processing the files.
* @return the processed files added with {@link #addProcessedFile(Entry)}. */
public ArrayList<Entry> process(File[] files, File outputRoot) throws Exception {
if (outputRoot == null)
outputRoot = new File("");
outputFiles.clear();
LinkedHashMap<File, ArrayList<Entry>> dirToEntries = new LinkedHashMap();
process(files, outputRoot, outputRoot, dirToEntries, 0);
ArrayList<Entry> allEntries = new ArrayList();
for (java.util.Map.Entry<File, ArrayList<Entry>> mapEntry : dirToEntries.entrySet()) {
ArrayList<Entry> dirEntries = mapEntry.getValue();
if (comparator != null)
Collections.sort(dirEntries, entryComparator);
File inputDir = mapEntry.getKey();
File newOutputDir = null;
if (flattenOutput)
newOutputDir = outputRoot;
else if (//
!dirEntries.isEmpty())
newOutputDir = dirEntries.get(0).outputDir;
String outputName = inputDir.getName();
if (outputSuffix != null)
outputName = outputName.replaceAll("(.*)\\..*", "$1") + outputSuffix;
Entry entry = new Entry();
entry.inputFile = mapEntry.getKey();
entry.outputDir = newOutputDir;
if (newOutputDir != null)
entry.outputFile = newOutputDir.length() == 0 ? new File(outputName) : new File(newOutputDir, outputName);
try {
processDir(entry, dirEntries);
} catch (Exception ex) {
throw new Exception("Error processing directory: " + entry.inputFile.getAbsolutePath(), ex);
}
allEntries.addAll(dirEntries);
}
if (comparator != null)
Collections.sort(allEntries, entryComparator);
for (Entry entry : allEntries) {
try {
processFile(entry);
} catch (Exception ex) {
throw new Exception("Error processing file: " + entry.inputFile.getAbsolutePath(), ex);
}
}
return outputFiles;
}
Aggregations