List of usage examples for com.google.common.collect Maps newHashMap
public static <K, V> HashMap<K, V> newHashMap()
From source file:com.google.gapid.util.Flags.java
/** * Parses the given command line arguments and initializes the given flags. *///from w w w . ja v a 2 s . c om public static synchronized String[] initFlags(Flag<?>[] flags, String[] args) { if (initialized) { throw new RuntimeException("Flags already initalized"); } initialized = true; Map<String, Flag<?>> flagMap = Maps.newHashMap(); for (Flag<?> flag : flags) { if (flagMap.put(flag.getName(), flag) != null) { throw new RuntimeException("Duplicate flag: " + flag.getName()); } if (isBooleanFlag(flag) && flagMap.put("no" + flag.getName(), flag) != null) { throw new RuntimeException("Duplicate flag: no" + flag.getName()); } } List<String> result = Lists.newArrayList(); for (int i = 0; i < args.length; i++) { if (!args[i].startsWith("-")) { result.add(args[i]); continue; } else if ("--".equals(args[i])) { for (int j = i + 1; j < args.length; j++) { result.add(args[j]); } break; } Matcher m = FLAG_PATTERN.matcher(args[i]); if (!m.matches()) { throw new InvalidFlagException(args[i]); } String name = m.group(1); String value = m.group(2); Flag<?> flag = flagMap.get(name); if (flag == null) { throw new InvalidFlagException(name); } if (value == null) { if (isBooleanFlag(flag)) { if (i + 1 < args.length && !args[i + 1].startsWith("-")) { value = args[++i]; } else { value = String.valueOf(!name.startsWith("no")); } } else if (++i >= args.length) { throw new InvalidFlagException(name + " is missing its argument"); } else { value = args[i]; } } else if (isBooleanFlag(flag) && name.startsWith("no")) { throw new InvalidFlagException(args[i]); } flag.setValue(value); } if (help.get()) { printHelp(System.out, flags); System.exit(1); } return result.toArray(new String[result.size()]); }
From source file:interactivespaces.example.activity.routable.output.SimpleJavaRoutableOutputActivity.java
@Override public void onActivityActivate() { Map<String, Object> message = Maps.newHashMap(); message.put("message", "yipee! activated!"); sendOutputJson("output1", message); }
From source file:interactivespaces.master.api.MasterApiMessageSupport.java
/** * Get a failure Master API response./*from ww w .ja va2 s . c om*/ * * @param reason * the reason for the failure * * @return the Master API response object */ public static Map<String, Object> getFailureResponse(String reason) { Map<String, Object> result = Maps.newHashMap(); result.put(MasterApiMessage.MASTER_API_MESSAGE_ENVELOPE_RESULT, MasterApiMessage.MASTER_API_RESULT_FAILURE); result.put(MasterApiMessage.MASTER_API_MESSAGE_ENVELOPE_REASON, reason); return result; }
From source file:vazkii.tinkerer.common.block.tile.peripheral.PeripheralAspectContainer.java
public static void appendAspectEntry(Map<Double, Map<String, Object>> result, int count, Aspect aspect, int quantity) { Map<String, Object> aspectDetails = Maps.newHashMap(); aspectDetails.put("name", aspect.getName()); aspectDetails.put("quantity", new Double(quantity)); result.put(new Double(count), aspectDetails); }
From source file:net.roddrim.number5.tools.collect.FluentMap.java
public static <K, V> FluentMap<K, V> ofNewHashMap() { return of(Maps.newHashMap()); }
From source file:io.macgyver.core.service.config.SpringConfigLoader.java
public static Map<String, String> getAllProperties(PropertySource<?> aPropSource) { Map<String, String> result = Maps.newHashMap(); if (aPropSource instanceof CompositePropertySource) { CompositePropertySource cps = (CompositePropertySource) aPropSource; cps.getPropertySources().forEach(ps -> { result.putAll(getAllProperties(ps)); });//from ww w . ja v a 2 s .c om return result; } if (aPropSource instanceof EnumerablePropertySource<?>) { EnumerablePropertySource<?> ps = (EnumerablePropertySource<?>) aPropSource; Arrays.asList(ps.getPropertyNames()).forEach(key -> { String val = Objects.toString(ps.getProperty(key), null); result.put(key, val); }); return result; } // note: Most descendants of PropertySource are // EnumerablePropertySource. There are some // few others like JndiPropertySource or StubPropertySource logger.warn("Given PropertySource is instanceof " + aPropSource.getClass().getName() + " and cannot be iterated"); return result; }
From source file:org.apache.kylin.tool.util.ToolUtil.java
public static String decideKylinMajorVersionFromCommitFile() { Map<String, String> majorVersionCommitMap = Maps.newHashMap(); majorVersionCommitMap.put("1.3", "commit.sha1"); majorVersionCommitMap.put("1.5", "commit_SHA1"); for (Map.Entry<String, String> majorVersionEntry : majorVersionCommitMap.entrySet()) { if (new File(KylinConfig.getKylinHome(), majorVersionEntry.getValue()).exists()) { return majorVersionEntry.getKey(); }//from w w w .ja va 2s .co m } return null; }
From source file:acromusashi.kafka.log.producer.util.KeyedMessageConverter.java
/** * ApacheLog?1?Kafka???/*from w w w .j a v a 2 s .c o m*/ * * @param apacheLogStr ApacheLog?1 * @param topic ?Topic * @param host ? * @param apacheLogFormat ApacheLog * @param jsonDateFormatStr Kafka?? * @return Kafka * @throws Exception ? */ public static KeyedMessage<String, String> convertToMessage(String apacheLogStr, String topic, String host, String apacheLogFormat, String jsonDateFormatStr) throws Exception { ParsedLog parsedLogObj = ApacheLogParseUtil.getParsedLog(apacheLogStr, apacheLogFormat); Map<String, String> parsedLog = parsedLogObj.getParsedLog(); Map<String, String> jsonMapLog = Maps.newHashMap(); String strfTimeFormat = parsedLogObj.getStrftimeFormat(); for (Entry<String, String> apacheLogEntry : parsedLog.entrySet()) { String jsonKey = ApacheLtsvMapper.convertApacheFormatToLtsvKey(apacheLogEntry.getKey()); //jsonKey?????strttime???time????????? if (jsonKey == null || jsonKey.equals("") || jsonKey.equals("time")) { String javaFormatTime = StrftimeFormatMapper.convertStftToDateStr(apacheLogEntry.getValue(), strfTimeFormat, jsonDateFormatStr); jsonMapLog.put("time", javaFormatTime); } else { jsonMapLog.put(jsonKey, apacheLogEntry.getValue()); } } // hostname jsonMapLog.put("hostname", host); ObjectMapper mapper = new ObjectMapper(); String jsonLog = mapper.writeValueAsString(jsonMapLog); KeyedMessage<String, String> result = new KeyedMessage<String, String>(topic, host, jsonLog); return result; }
From source file:com.naver.timetable.dao.TimeTableDAO.java
/** * ?? ? ./*from w w w . j a v a 2s . c om*/ * @param studentNum * @param year * @param season * @return */ public List<Lecture> getTimeTable(String studentNum, String year, String season) { Map<String, Object> parameterMap = Maps.newHashMap(); parameterMap.put("studentNum", studentNum); parameterMap.put("lecture_year", year); parameterMap.put("lecture_season", season); return hufsCubrid.queryForList("getTimeTable", parameterMap); }
From source file:org.jetbrains.jet.lang.types.DescriptorSubstitutor.java
@NotNull public static TypeSubstitutor substituteTypeParameters(@NotNull List<TypeParameterDescriptor> typeParameters, @NotNull final TypeSubstitutor originalSubstitutor, @NotNull DeclarationDescriptor newContainingDeclaration, @NotNull List<TypeParameterDescriptor> result) { final Map<TypeConstructor, TypeProjection> mutableSubstitution = Maps.newHashMap(); TypeSubstitutor substitutor = TypeSubstitutor.create(new TypeSubstitution() { @Override//ww w .j a va 2 s.c o m public TypeProjection get(TypeConstructor key) { if (originalSubstitutor.inRange(key)) { return originalSubstitutor.getSubstitution().get(key); } return mutableSubstitution.get(key); } @Override public boolean isEmpty() { return originalSubstitutor.isEmpty() && mutableSubstitution.isEmpty(); } @Override public String toString() { return "DescriptorSubstitutor.substituteTypeParameters(" + mutableSubstitution + " / " + originalSubstitutor.getSubstitution() + ")"; } }); for (TypeParameterDescriptor descriptor : typeParameters) { TypeParameterDescriptorImpl substituted = TypeParameterDescriptorImpl.createForFurtherModification( newContainingDeclaration, descriptor.getAnnotations(), descriptor.isReified(), descriptor.getVariance(), descriptor.getName(), descriptor.getIndex()); substituted.setInitialized(); mutableSubstitution.put(descriptor.getTypeConstructor(), new TypeProjection(substituted.getDefaultType())); for (JetType upperBound : descriptor.getUpperBounds()) { substituted.getUpperBounds().add(substitutor.substitute(upperBound, Variance.INVARIANT)); } result.add(substituted); } return substitutor; }