Search in sources :

Example 81 with LinkedHashMap

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);
    }
}
Also used : Closer(com.google.common.io.Closer) Path(java.nio.file.Path) FileSystem(java.nio.file.FileSystem) LinkedHashMap(java.util.LinkedHashMap)

Example 82 with LinkedHashMap

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).");
    }
}
Also used : BigInteger(java.math.BigInteger) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MessageDigest(java.security.MessageDigest) LinkedHashMap(java.util.LinkedHashMap)

Example 83 with LinkedHashMap

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);
}
Also used : ProtoType(com.squareup.wire.schema.ProtoType) ClassName(com.squareup.javapoet.ClassName) ProtoFile(com.squareup.wire.schema.ProtoFile) Service(com.squareup.wire.schema.Service) ByteString(okio.ByteString) LinkedHashMap(java.util.LinkedHashMap)

Example 84 with LinkedHashMap

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);
}
Also used : Argument(com.lexicalscope.jewel.cli.validation.Argument) ParsedOptionSpecification(com.lexicalscope.jewel.cli.specification.ParsedOptionSpecification) LinkedHashMap(java.util.LinkedHashMap) UnparsedOptionSpecification(com.lexicalscope.jewel.cli.specification.UnparsedOptionSpecification)

Example 85 with LinkedHashMap

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;
}
Also used : ArrayList(java.util.ArrayList) File(java.io.File) LinkedHashMap(java.util.LinkedHashMap) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

LinkedHashMap (java.util.LinkedHashMap)2398 Map (java.util.Map)691 ArrayList (java.util.ArrayList)675 HashMap (java.util.HashMap)439 Test (org.junit.Test)317 List (java.util.List)298 IOException (java.io.IOException)152 HashSet (java.util.HashSet)128 Set (java.util.Set)110 LinkedHashSet (java.util.LinkedHashSet)100 File (java.io.File)93 LinkedList (java.util.LinkedList)75 TreeMap (java.util.TreeMap)72 Node (org.apache.hadoop.hive.ql.lib.Node)70 NodeProcessor (org.apache.hadoop.hive.ql.lib.NodeProcessor)68 Rule (org.apache.hadoop.hive.ql.lib.Rule)68 GraphWalker (org.apache.hadoop.hive.ql.lib.GraphWalker)66 Dispatcher (org.apache.hadoop.hive.ql.lib.Dispatcher)65 Iterator (java.util.Iterator)64 DefaultRuleDispatcher (org.apache.hadoop.hive.ql.lib.DefaultRuleDispatcher)64