Example usage for com.google.common.collect Maps newHashMap

List of usage examples for com.google.common.collect Maps newHashMap

Introduction

In this page you can find the example usage for com.google.common.collect Maps newHashMap.

Prototype

public static <K, V> HashMap<K, V> newHashMap() 

Source Link

Document

Creates a mutable, empty HashMap instance.

Usage

From source file:org.springside.modules.log.AppenderUtils.java

/**
 * ?Map, MapKey???./*from ww  w  . java 2  s . c o m*/
 */
public static Map<String, Object> convertEventToMap(LoggingEvent event) {
    Map<String, Object> map = Maps.newHashMap();
    map.put(MESSAGE, event.getMessage());
    map.put(LEVEL, event.getLevel().toString());
    map.put(LOGGER_NAME, event.getLoggerName());
    map.put(THREAD_NAME, event.getThreadName());
    map.put(TIMESTAMP, new Date(event.getTimeStamp()));
    return map;
}

From source file:org.apache.kylin.engine.mr.common.CuboidShardUtil.java

public static void saveCuboidShards(CubeSegment segment, Map<Long, Short> cuboidShards, int totalShards)
        throws IOException {
    CubeManager cubeManager = CubeManager.getInstance(segment.getConfig());

    Map<Long, Short> filtered = Maps.newHashMap();
    for (Map.Entry<Long, Short> entry : cuboidShards.entrySet()) {
        if (entry.getValue() > 1) {
            filtered.put(entry.getKey(), entry.getValue());
        }/*from   w ww  .ja v a 2  s  .co m*/
    }

    segment.setCuboidShardNums(filtered);
    segment.setTotalShards(totalShards);

    CubeUpdate cubeBuilder = new CubeUpdate(segment.getCubeInstance());
    cubeBuilder.setToUpdateSegs(segment);
    cubeManager.updateCube(cubeBuilder);
}

From source file:com.noorq.casser.support.Transformers.java

public static <I, O, V> Map<O, V> transformMapKey(Map<I, V> inputMap, Function<I, O> func) {
    Map<O, V> map = Maps.newHashMap();
    for (Map.Entry<I, V> e : inputMap.entrySet()) {
        map.put(func.apply(e.getKey()), e.getValue());
    }//from w w w. j  av  a 2s  . co  m
    return map;
}

From source file:org.atlasapi.content.criteria.operator.Operators.java

private static Map<String, Operator> createLookup() {
    Map<String, Operator> table = Maps.newHashMap();
    table.put(EQUALS.name(), EQUALS);//  w w  w . ja  va  2  s  . c  om
    table.put(BEGINNING.name(), BEGINNING);
    table.put(LESS_THAN.name(), LESS_THAN);
    table.put(GREATER_THAN.name(), GREATER_THAN);
    table.put(BEFORE.name(), BEFORE);
    table.put(AFTER.name(), AFTER);
    return table;
}

From source file:lyonlancer5.xatrocore.utils.XatroLoader.java

/**Loads a given ModLoader-rewritten mod using the given class path
 * @deprecated Not yet implemented// www . j  a  v  a  2s  .c  o  m
 * @param className the full class name that loads the mod
 * @return True if it found the class and will start loading the mod, false otherwise*/
public static boolean loadModLoaderMod(String className) {
    if (className.contains("mod_")) {
        try {

            @SuppressWarnings("unchecked")
            Class<? extends MLMod> clazz = (Class<? extends MLMod>) Class.forName(className);
            MLMod theMod = clazz.getConstructor().newInstance();

            HashMap<String, Object> map = Maps.newHashMap();
            map.put("modid", theMod.getModID());
            map.put("name", theMod.getName());
            map.put("version", theMod.getVersion());

            //FMLModContainer container = new FMLModContainer("lyonlancer5.xatrocore.lib.XatroMod", new ModCandidate(file, file, file.isDirectory() ? ContainerType.DIR : ContainerType.JAR), map);
            //container.bindMetadata(MetadataCollection.from(null, ""));
            //FMLClientHandler.instance().addModAsResource(container);

            //theMod.load();

        } catch (ClassNotFoundException e) {
            modLoader.error("No class found with name %s", className);
            return false;
        } catch (IllegalAccessException e) {
            modLoader.error("Unable to access class %s", className);
            return false;
        } catch (IllegalArgumentException e) {
            modLoader.error("Invalid parameter given to class %s", className);
            return false;
        } catch (InvocationTargetException e) {
            modLoader.error("Load method error on class %s", className);
            return false;
        } catch (NoSuchMethodException e) {
            modLoader.error("No load method found on class %s", className);
            return false;
        } catch (SecurityException e) {
            modLoader.error("Security error on class %s", className);
            return false;
        } catch (InstantiationException e) {
            modLoader.error("Unable to instantiate class %s", className);
        }
        return true;
    }
    return false;
}

From source file:org.eclipse.viatra.query.runtime.localsearch.planner.util.CompilerHelper.java

public static Map<PVariable, Integer> createVariableMapping(SubPlan plan) {
    Map<PVariable, Integer> variableMapping = Maps.newHashMap();

    int variableNumber = 0;

    // Important note: this list might contain duplications when parameters are made equal inside the pattern
    // This is the expected and normal behavior
    List<PVariable> symbolicParameterVariables = plan.getBody().getSymbolicParameterVariables();
    for (PVariable pVariable : symbolicParameterVariables) {
        if (!variableMapping.containsKey(pVariable)) {
            variableMapping.put(pVariable, variableNumber++);
        }/*www. j  a v  a  2 s  .c o m*/
    }

    // Reason for complexity here: not all variables were given back for call plan.getAllDeducedVariables();
    Set<PVariable> allVariables = Sets.newHashSet();
    Set<PConstraint> allEnforcedConstraints = plan.getAllEnforcedConstraints();
    for (PConstraint pConstraint : allEnforcedConstraints) {
        allVariables.addAll(pConstraint.getAffectedVariables());
    }
    for (PVariable pVariable : allVariables) {
        if (!variableMapping.containsKey(pVariable)) {
            variableMapping.put(pVariable, variableNumber++);
        }
    }

    return variableMapping;
}

From source file:com.doctusoft.bean.Properties.java

/**
 * Creates a {@link HashMap} of the elements. The keys are determined by the keyAttribute parameter,
 * the values are the elements themselves. 
 *///from ww  w . ja  v  a  2  s  . co m
public static <T, Key> Map<Key, T> map(Iterable<T> elements, Property<? super T, Key> keyAttribute) {
    Map<Key, T> result = Maps.newHashMap();
    for (T element : elements) {
        result.put(keyAttribute.getValue(element), element);
    }
    return result;
}

From source file:org.apache.druid.query.select.PagingSpec.java

public static Map<String, Integer> merge(Iterable<Map<String, Integer>> cursors) {
    Map<String, Integer> next = Maps.newHashMap();
    for (Map<String, Integer> cursor : cursors) {
        for (Map.Entry<String, Integer> entry : cursor.entrySet()) {
            next.put(entry.getKey(), entry.getValue());
        }// w  ww .  ja va 2s.  c  o m
    }
    return next;
}

From source file:com.cloudera.exhibit.avro.AvroExhibit.java

public static ExhibitDescriptor createDescriptor(Schema schema) {
    List<ObsDescriptor.Field> fields = Lists.newArrayList();
    Map<String, ObsDescriptor> frames = Maps.newHashMap();
    for (int i = 0; i < schema.getFields().size(); i++) {
        Schema.Field f = schema.getFields().get(i);
        Schema unwrapped = AvroObsDescriptor.unwrap(f.schema());
        if (unwrapped.getType() == Schema.Type.ARRAY) {
            //TODO be careful
            frames.put(f.name(), new AvroObsDescriptor(getRecordElement(unwrapped.getElementType())));
        } else {/*  w  w  w.ja va  2  s . co m*/
            ObsDescriptor.FieldType ft = AvroObsDescriptor.getFieldType(unwrapped);
            if (ft != null) {
                fields.add(new ObsDescriptor.Field(f.name(), ft));
            }
        }
    }
    return new ExhibitDescriptor(new SimpleObsDescriptor(fields), frames);
}

From source file:org.apache.pulsar.broker.service.schema.SchemaRegistryService.java

static Map<SchemaType, SchemaCompatibilityCheck> getCheckers(Set<String> checkerClasses) throws Exception {
    Map<SchemaType, SchemaCompatibilityCheck> checkers = Maps.newHashMap();
    for (String className : checkerClasses) {
        final Class<?> checkerClass = Class.forName(className);
        SchemaCompatibilityCheck instance = (SchemaCompatibilityCheck) checkerClass.newInstance();
        checkers.put(instance.getSchemaType(), instance);
    }//ww w. j  a v  a2 s. co m
    return checkers;
}