Java Code Examples for com.google.common.collect.Maps

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project agorava-facebook, under directory /agorava-facebook-cdi/src/main/java/org/agorava/facebook/impl/.

Source file: UserServiceImpl.java

  46 
vote

@Override public List<Reference> search(String query){
  Map<String,String> queryMap=Maps.newHashMap();
  queryMap.put("q",query);
  queryMap.put("type","user");
  return graphApi.fetchConnections("search",null,Reference.class,queryMap);
}
 

Example 2

From project atlas, under directory /src/main/java/com/ning/atlas/components/aws/.

Source file: EC2SecurityGroupProvisioner.java

  18 
vote

private void updateGroup(Uri<? extends Component> uri,AWSEC2Client ec2,IAMApi iam,SecurityGroup group){
  String user_id=iam.getCurrentUser().getId();
  Set<String> raw_rules=Sets.newHashSet();
  for (  Map.Entry<String,Collection<String>> entry : uri.getFullParams().entrySet()) {
    raw_rules.addAll(entry.getValue());
  }
  Set<IpRule> rules=Sets.newHashSet();
  for (  String raw_thing : raw_rules) {
    rules.add(IpRule.parse(user_id,raw_thing));
  }
  Map<IpRule,IpPermission> map=Maps.newHashMap();
  Set<IpRule> existing_rules=Sets.newHashSet();
  for (  IpPermission permission : group.getIpPermissions()) {
    IpRule r=IpRule.fromPermission(permission);
    existing_rules.add(r);
    map.put(r,permission);
  }
  Set<IpRule> to_remove=Sets.difference(existing_rules,rules);
  Set<IpRule> to_add=Sets.difference(rules,existing_rules);
  List<IpPermission> adds=Lists.newArrayListWithExpectedSize(to_add.size());
  for (  IpRule rule : to_add) {
    adds.add(rule.toIpPermission());
  }
  if (!adds.isEmpty()) {
    ec2.getSecurityGroupServices().authorizeSecurityGroupIngressInRegion(null,group.getName(),adds);
  }
  List<IpPermission> removals=Lists.newArrayListWithExpectedSize(to_remove.size());
  for (  IpRule rule : to_remove) {
    removals.add(map.get(rule));
  }
}
 

Example 3

From project aim3-tu-berlin, under directory /seminar/exercises/datamining/core/src/test/java/de/tuberlin/dima/aim/exercises/one/.

Source file: AverageTemperaturePerMonthTest.java

  15 
vote

private Map<YearAndMonth,Double> readResults(File outputFile) throws IOException {
  Pattern separator=Pattern.compile("\t");
  Map<YearAndMonth,Double> averageTemperatures=Maps.newHashMap();
  for (  String line : new FileLineIterable(outputFile)) {
    String[] tokens=separator.split(line);
    int year=Integer.parseInt(tokens[0]);
    int month=Integer.parseInt(tokens[1]);
    double temperature=Double.parseDouble(tokens[2]);
    averageTemperatures.put(new YearAndMonth(year,month),temperature);
  }
  return averageTemperatures;
}
 

Example 4

From project airlift, under directory /configuration/src/main/java/io/airlift/configuration/.

Source file: ConfigurationLoader.java

  15 
vote

public Map<String,String> loadProperties() throws IOException {
  Map<String,String> result=Maps.newTreeMap();
  String configFile=System.getProperty("config");
  if (configFile != null) {
    result.putAll(loadPropertiesFrom(configFile));
  }
  result.putAll(getSystemProperties());
  return ImmutableSortedMap.copyOf(result);
}
 

Example 5

From project artifactory-plugin, under directory /src/main/java/org/jfrog/hudson/.

Source file: ArtifactoryRedeployPublisher.java

  15 
vote

@Override public ArtifactoryRedeployPublisher newInstance(StaplerRequest req,JSONObject formData) throws FormException {
  ArtifactoryRedeployPublisher publisher=req.bindJSON(ArtifactoryRedeployPublisher.class,formData);
  if (formData.has("details")) {
    JSONObject serverDetails=formData.getJSONObject("details");
    if (serverDetails.has("stagingPlugin")) {
      PluginSettings settings=new PluginSettings();
      Map<String,String> paramMap=Maps.newHashMap();
      JSONObject pluginSettings=serverDetails.getJSONObject("stagingPlugin");
      String pluginName=pluginSettings.getString("pluginName");
      settings.setPluginName(pluginName);
      Map<String,Object> filteredPluginSettings=Maps.filterKeys(pluginSettings,new Predicate<String>(){
        public boolean apply(        String input){
          return StringUtils.isNotBlank(input) && !"pluginName".equals(input);
        }
      }
);
      for (      Map.Entry<String,Object> settingsEntry : filteredPluginSettings.entrySet()) {
        String key=settingsEntry.getKey();
        paramMap.put(key,pluginSettings.getString(key));
      }
      if (!paramMap.isEmpty()) {
        settings.setParamMap(paramMap);
      }
      publisher.details.setStagingPlugin(settings);
    }
  }
  return publisher;
}
 

Example 6

From project astyanax, under directory /src/main/java/com/netflix/astyanax/connectionpool/impl/.

Source file: AbstractHostPartitionConnectionPool.java

  15 
vote

@Override public void start(){
  ConnectionPoolMBeanManager.getInstance().registerMonitor(config.getName(),this);
  String seeds=config.getSeeds();
  if (seeds != null && !seeds.isEmpty()) {
    Map<BigInteger,List<Host>> ring=Maps.newHashMap();
    ring.put(new BigInteger("0"),config.getSeedHosts());
    setHosts(ring);
  }
  latencyScoreStrategy.start(new Listener(){
    @Override public void onUpdate(){
      rebuildPartitions();
    }
    @Override public void onReset(){
      rebuildPartitions();
    }
  }
);
}
 

Example 7

From project atlassian-rest-cli, under directory /rest-cli-runner/src/main/java/com/galeoconsulting/leonardinius/servlet/.

Source file: ScriptRunnerSessionServlet.java

  15 
vote

private Map<String,String> getConfiguredTemplates(){
  if (configuredTemplates == null) {
    String parameterValue=checkNotNull(getInitParameter(VELOCITY_TEMPLATES_CONFIG_PARAMETER),VELOCITY_TEMPLATES_CONFIG_PARAMETER + " servlet configuration parameter");
    Collection<String> entries=new LinkedHashSet<String>(Arrays.asList(StringUtils.split(parameterValue,';')));
    entries=Collections2.filter(entries,new Predicate<String>(){
      @Override public boolean apply(      @Nullable String s){
        return StringUtils.isNotBlank(s);
      }
    }
);
    Map<String,String> result=Maps.newHashMap();
    for (    String entry : entries) {
      String data[]=StringUtils.split(entry,'|');
      result.put(StringUtils.trimToNull(data[0]),StringUtils.trimToNull(data[1]));
    }
    configuredTemplates=ImmutableMap.copyOf(result);
  }
  return configuredTemplates;
}
 

Example 8

From project atunit, under directory /atunit/src/main/java/atunit/core/.

Source file: CoreTestFixture.java

  15 
vote

public CoreTestFixture(Class<?> testClass) throws InvalidTestException {
  this.testClass=testClass;
  fields=Maps.newHashMap();
  for (  Field field : TestClassUtils.getFields(testClass)) {
    fields.put(field,null);
  }
  mockFields=TestClassUtils.getMockFields(fields.keySet());
  stubFields=TestClassUtils.getStubFields(fields.keySet());
  unitField=TestClassUtils.getUnitField(fields.keySet());
  containerClass=PluginUtils.getContainerPluginClass(testClass);
  pluginClasses=PluginUtils.getPluginClasses(testClass);
}
 

Example 9

From project atunit_1, under directory /test/atunit/guice/.

Source file: GuiceContainerTests.java

  15 
vote

@Test public void tDuplicateFields() throws Exception {
  GuiceContainer container=new GuiceContainer();
  Map<Field,Object> fieldValues=Maps.newHashMap();
  fieldValues.put(DuplicateFields.class.getDeclaredField("field1"),"field 1");
  fieldValues.put(DuplicateFields.class.getDeclaredField("field2"),"field 2");
  fieldValues.put(DuplicateFields.class.getDeclaredField("field3"),new Integer(3));
  DuplicateFields df=(DuplicateFields)container.createTest(DuplicateFields.class,fieldValues);
  assertFalse("field 1".equals(df.field1));
  assertFalse("field 2".equals(df.field2));
  assertEquals(3,df.field3.intValue());
}
 

Example 10

From project azkaban, under directory /azkaban/src/java/azkaban/serialization/de/.

Source file: ExecutableFlowDeserializer.java

  15 
vote

@Override public ExecutableFlow apply(Map<String,Object> descriptor){
  Map<String,ExecutableFlow> jobs=Maps.uniqueIndex(Iterables.<Map<String,Object>,ExecutableFlow>transform(Verifier.getVerifiedObject(descriptor,"jobs",Map.class).values(),jobDeserializer),new Function<ExecutableFlow,String>(){
    @Override public String apply(    ExecutableFlow flow){
      return flow.getName();
    }
  }
);
  Map<String,List<String>> dependencies=Verifier.getVerifiedObject(descriptor,"dependencies",Map.class);
  List<String> roots=Verifier.getVerifiedObject(descriptor,"root",List.class);
  String id=Verifier.getString(descriptor,"id");
  return buildFlow(id,roots,dependencies,jobs);
}
 

Example 11

From project b1-pack, under directory /cli/src/main/java/org/b1/pack/cli/.

Source file: FileTools.java

  15 
vote

public static Map<List<String>,FsObject> createRootMap(List<String> names){
  Map<List<String>,FsObject> map=Maps.newLinkedHashMap();
  for (  String name : names.isEmpty() ? Collections.singleton(".") : names) {
    File file=new File(name);
    List<String> path=getPath(file);
    Preconditions.checkState(map.put(path,new FsObject(file,path)) == null,"Duplicate path: %s",path);
  }
  return map;
}
 

Example 12

From project bamboo-sonar-integration, under directory /bamboo-sonar-tasks/src/main/java/com/marvelution/bamboo/plugins/sonar/tasks/actions/admin/.

Source file: ViewSonarServerMatrix.java

  15 
vote

public Map<String,Map<Integer,Boolean>> getServerMatrix(){
  if (matrix == null) {
    matrix=Maps.newHashMap();
    for (    Buildable buildable : getBuildables()) {
      Map<Integer,Boolean> serverMatches=Maps.newHashMap();
      for (      SonarServer server : getServers()) {
        serverMatches.put(server.getID(),Iterables.any(buildable.getBuildDefinition().getTaskDefinitions(),SonarPredicates.isSonarServerDependingTask(server.getID())));
      }
      matrix.put(buildable.getKey(),serverMatches);
    }
  }
  return matrix;
}
 

Example 13

From project Betfair-Trickle, under directory /src/main/java/uk/co/onehp/trickle/dao/.

Source file: HibernateHorseDao.java

  15 
vote

@Override public Horse getHorse(int runnerId,int raceId){
  Map<String,Integer> params=Maps.newHashMap();
  params.put("runnerId",runnerId);
  params.put("raceId",raceId);
  return (Horse)hibernateTemplate.findByNamedQueryAndNamedParam("getHorse",new String[]{"runnerId","raceId"},new Integer[]{runnerId,raceId}).get(0);
}
 

Example 14

From project build-info, under directory /build-info-api/src/main/java/org/jfrog/build/api/builder/.

Source file: PromotionBuilder.java

  15 
vote

public PromotionBuilder addProperty(String key,String value){
  if (properties == null) {
    properties=Maps.newHashMap();
  }
  Collection<String> collection;
  if (!properties.containsKey(key)) {
    collection=Sets.newHashSet();
  }
 else {
    collection=properties.get(key);
  }
  collection.add(value);
  properties.put(key,collection);
  return this;
}
 

Example 15

From project Bukkit-Plugin-Utilties, under directory /src/main/java/de/xzise/.

Source file: MinecraftUtil.java

  15 
vote

private static void generate(Set<org.bukkit.permissions.Permission> permissions,Set<String> children,String prefix,String name){
  if (children.isEmpty()) {
    Map<String,Boolean> childrenMap=Maps.newHashMapWithExpectedSize(children.size());
    for (    String child : children) {
      childrenMap.put(child,true);
    }
    permissions.add(new org.bukkit.permissions.Permission(prefix + (prefix.isEmpty() ? "" : ".") + name,childrenMap));
  }
}
 

Example 16

From project C-Cat, under directory /core/src/main/java/gov/llnl/ontology/mains/.

Source file: DecentralizedSearch.java

  15 
vote

public static Map<String,String> readTagMapping(String tagMapFile) throws Exception {
  Map<String,String> tagMap=Maps.newHashMap();
  BufferedReader br=new BufferedReader(new FileReader(tagMapFile));
  for (String line=null; (line=br.readLine()) != null; ) {
    String[] tokens=line.split("\\s+");
    tagMap.put(tokens[0],tokens[1]);
  }
  return tagMap;
}
 

Example 17

From project Cafe, under directory /webapp/src/org/openqa/selenium/android/.

Source file: AndroidWebDriver.java

  15 
vote

public AndroidWebDriver(Activity activity){
  this.activity=activity;
  store=Maps.newHashMap();
  findBy=new AndroidFindBy();
  currentWindowOrFrame=new DomWindow("");
  store=Maps.newHashMap();
  touchScreen=new AndroidTouchScreen(this);
  navigation=new AndroidNavigation();
  options=new AndroidOptions();
  element=getOrCreateWebElement("");
  localStorage=new AndroidLocalStorage(this);
  sessionStorage=new AndroidSessionStorage(this);
  targetLocator=new AndroidTargetLocator();
  viewManager=new WebViewManager();
  newWebView(true);
  CookieSyncManager.createInstance(activity);
  sessionCookieManager=new SessionCookieManager();
  CookieManager cookieManager=CookieManager.getInstance();
  cookieManager.removeAllCookie();
  networkHandler=new NetworkStateHandler(activity,webview);
}
 

Example 18

From project cdk, under directory /generator/src/main/java/org/richfaces/cdk/apt/.

Source file: AptSourceUtils.java

  15 
vote

/** 
 * <p class="changed_added_4_0"> Utility method to get all bean properties, similar to Introspector </p>
 * @param type
 * @return
 */
Map<String,AptBeanProperty> getBeanProperties(TypeElement type){
  if (null == type) {
    return Collections.emptyMap();
  }
  Name qName=type.getQualifiedName();
  Map<String,AptBeanProperty> result=beanPropertyCache.get(qName);
  if (result != null) {
    return result;
  }
  result=Maps.newHashMap();
  List<? extends Element> members=this.processingEnv.getElementUtils().getAllMembers(type);
  for (  Element element : members) {
    if (ElementKind.METHOD.equals(element.getKind())) {
      ExecutableElement method=(ExecutableElement)element;
      processMethod(type,result,method);
    }
  }
  beanPropertyCache.put(qName,result);
  return result;
}
 

Example 19

From project Cinch, under directory /src/com/palantir/ptoss/cinch/core/.

Source file: BindingContext.java

  15 
vote

/** 
 * Look through all of the declared, static, final fields of the context object, grab the value, and insert a mapping from the field's name to the object. Note that this will index non-public fields.
 * @return the bindable constants map
 * @throws IllegalArgumentException on reflection error
 * @throws IllegalAccessException on reflection error
 */
private Map<String,Object> indexBindableConstants() throws IllegalArgumentException, IllegalAccessException {
  Map<String,Object> map=Maps.newHashMap();
  for (  Field field : object.getClass().getDeclaredFields()) {
    boolean accessible=field.isAccessible();
    field.setAccessible(true);
    if (Reflections.isFieldFinal(field) && Reflections.isFieldStatic(field)) {
      map.put(field.getName(),field.get(object));
    }
    field.setAccessible(accessible);
  }
  return map;
}
 

Example 20

From project CIShell, under directory /core/org.cishell.utilities/src/org/cishell/utilities/database/.

Source file: ForeignKey.java

  15 
vote

private Map<String,Object> translateToForeignNames(Map<String,Object> from){
  SortedMap<String,Object> to=Maps.newTreeMap();
  for (  ColumnPair pair : pairs) {
    to.put(pair.foreign,from.get(pair.local));
  }
  return to;
}
 

Example 21

From project Citizens, under directory /src/guard/net/citizensnpcs/guards/flags/.

Source file: FlagList.java

  15 
vote

private Map<FlagType,Map<String,FlagInfo>> getPopulatedMap(){
  Map<FlagType,Map<String,FlagInfo>> populated=Maps.newEnumMap(FlagType.class);
  for (  FlagType type : FlagType.values()) {
    populated.put(type,new HashMap<String,FlagInfo>());
  }
  return populated;
}
 

Example 22

From project closure-templates, under directory /java/src/com/google/template/soy/data/.

Source file: SoyMapData.java

  15 
vote

/** 
 * Constructor that initializes this SoyMapData from an existing map.
 * @param data The initial data in an existing map.
 */
public SoyMapData(Map<String,?> data){
  map=Maps.newHashMapWithExpectedSize(data.size());
  for (  Map.Entry<String,?> entry : data.entrySet()) {
    String key;
    try {
      key=entry.getKey();
    }
 catch (    ClassCastException cce) {
      throw new SoyDataException("Attempting to convert a map with non-string key to Soy data (key type " + ((Map.Entry<?,?>)entry).getKey().getClass().getName() + ").");
    }
    Object value=entry.getValue();
    try {
      map.put(key,SoyData.createFromExistingData(value));
    }
 catch (    SoyDataException sde) {
      sde.prependKeyToDataPath(key);
      throw sde;
    }
  }
}