List of usage examples for com.google.common.collect HashBiMap create
public static <K, V> HashBiMap<K, V> create()
From source file:com.android.sdklib.repository.targets.AndroidTargetManager.java
@NonNull private Map<LocalPackage, IAndroidTarget> getTargetMap(@NonNull ProgressIndicator progress) { if (mTargets == null) { Map<String, String> newErrors = Maps.newHashMap(); RepoManager manager = mSdkHandler.getSdkManager(progress); Map<AndroidVersion, PlatformTarget> platformTargets = Maps.newHashMap(); BiMap<IAndroidTarget, LocalPackage> tempTargetToPackage = HashBiMap.create(); for (LocalPackage p : manager.getPackages().getLocalPackages().values()) { TypeDetails details = p.getTypeDetails(); if (details instanceof DetailsTypes.PlatformDetailsType) { try { PlatformTarget target = new PlatformTarget(p, mSdkHandler, mFop, progress); AndroidVersion androidVersion = target.getVersion(); // If we've already seen a platform with this version, replace the existing // with this if this is the "real" package (with the expected path). // Otherwise, don't create a duplicate. PlatformTarget existing = platformTargets.get(androidVersion); if (existing == null || p.getPath().equals(DetailsTypes.getPlatformPath(androidVersion))) { if (existing != null) { tempTargetToPackage.remove(existing); }//from w ww. j a va 2s . c o m platformTargets.put(androidVersion, target); tempTargetToPackage.put(target, p); } } catch (IllegalArgumentException e) { newErrors.put(p.getPath(), e.getMessage()); } } } for (LocalPackage p : manager.getPackages().getLocalPackages().values()) { TypeDetails details = p.getTypeDetails(); if (details instanceof DetailsTypes.AddonDetailsType) { AndroidVersion addonVersion = ((DetailsTypes.AddonDetailsType) details).getAndroidVersion(); PlatformTarget baseTarget = platformTargets.get(addonVersion); if (baseTarget != null) { tempTargetToPackage.put(new AddonTarget(p, baseTarget, mSdkHandler.getSystemImageManager(progress), progress, mFop), p); } } } Map<LocalPackage, IAndroidTarget> result = Maps.newTreeMap(TARGET_COMPARATOR); result.putAll(tempTargetToPackage.inverse()); for (LocalPackage p : manager.getPackages() .getLocalPackagesForPrefix(SdkConstants.FD_ANDROID_SOURCES)) { TypeDetails details = p.getTypeDetails(); if (details instanceof DetailsTypes.ApiDetailsType) { PlatformTarget target = platformTargets .get(((DetailsTypes.ApiDetailsType) details).getAndroidVersion()); if (target != null) { target.setSources(p.getLocation()); } } } mTargets = result; mLoadErrors = newErrors; } return mTargets; }
From source file:additionalpipes.utils.FrequencyMap.java
@SuppressWarnings("unchecked") public void readFromNBT(NBTTagCompound nbt) { for (NBTTagCompound usernameNBT : (Collection<NBTTagCompound>) nbt.getTags()) { BiMap<Integer, String> freqMap = HashBiMap.create(); for (NBTTagInt freqNBT : (Collection<NBTTagInt>) usernameNBT.getTags()) { freqMap.put(freqNBT.data, freqNBT.getName()); }//from w w w . j a va2s . co m userMap.put(usernameNBT.getName(), freqMap); } }
From source file:com.opengamma.bbg.loader.BloombergFXForwardScaleResolver.java
private BiMap<String, ExternalIdBundle> getSubIds(Collection<ExternalIdBundle> identifiers) { if (_useTickerSubscriptions) { BiMap<String, ExternalIdBundle> result = HashBiMap.create(); for (ExternalIdBundle bundle : identifiers) { for (ExternalId id : bundle) { if (s_tickerSchemes.contains(id.getScheme())) { result.put(id.getValue(), bundle); break; }/* w w w. j a v a 2 s . c o m*/ } } return result; } else { return BloombergDataUtils.convertToBloombergBuidKeys(identifiers, _referenceDataProvider); } }
From source file:org.granitemc.granite.utils.Mappings.java
public static void load() { try {/*from w w w.j av a2 s. c o m*/ File mappingsFile = new File(Granite.getServerConfig().getMappingsFile().getAbsolutePath()); String url = "https://raw.githubusercontent.com/GraniteTeam/GraniteMappings/master/1.8.1.json"; if (Granite.getServerConfig().getAutomaticMappingsUpdating()) { Granite.getLogger().info("Querying " + url + " for updates"); HttpRequest req = HttpRequest.get(url); if (!mappingsFile.exists() || !Objects.equals(req.eTag(), Granite.getServerConfig().getLatestMappingsEtag())) { Granite.getLogger().info("Could not find mappings.json (or etag didn't match)"); Granite.getLogger().info("Downloading from " + url); if (req.code() == 404) { throw new RuntimeException( "Cannot find mappings file on either the local system or on GitHub. Try placing a mappings.json file in the root server directory."); } else if (req.code() == 200) { req.receive(mappingsFile); ((GraniteServerConfig) Granite.getServerConfig()).file.put("latest-mappings-etag", req.eTag()); ((GraniteServerConfig) Granite.getServerConfig()).file.save(); } } } file = ConfigFactory.parseReader(new InputStreamReader(new FileInputStream(mappingsFile)), ConfigParseOptions.defaults().setSyntax(ConfigSyntax.JSON)); } catch (java.io.IOException e) { e.printStackTrace(); } classes = HashBiMap.create(); ctClasses = HashBiMap.create(); methods = new HashMap<>(); ctMethods = new HashMap<>(); fields = new HashMap<>(); ctFields = new HashMap<>(); pool = new ClassPool(true); try { for (Map.Entry<String, ConfigValue> classObject : file.getObject("classes").entrySet()) { String className = (String) ((ConfigObject) classObject.getValue()).get("name").unwrapped(); ctClasses.put(classObject.getKey(), pool.get(className)); ctClasses.put(classObject.getKey() + "[]", pool.get(className + "[]")); } for (Map.Entry<String, CtClass> entry : ctClasses.entrySet()) { CtClass ctClass = entry.getValue(); if (!entry.getKey().endsWith("[]")) { ConfigObject classObject = file .getObject("classes." + entry.getKey().replaceAll("\\$", "\"\\$\"")); methods.put(ctClass, HashBiMap.<String, MethodHandle>create()); ctMethods.put(ctClass, HashBiMap.<String, CtMethod>create()); if (classObject.containsKey("methods")) { for (Map.Entry<String, ConfigValue> methodEntry : ((ConfigObject) classObject .get("methods")).entrySet()) { String methodSignature = methodEntry.getKey(); String methodName = (String) methodEntry.getValue().unwrapped(); SignatureParser.MethodSignature obfSig = SignatureParser.parseJvm(methodSignature); /*MethodHandle mh = null; try { mh = MethodHandles.lookup().findVirtual(clazz.getValue(), methodSignature.split("\\(")[0], MethodType.methodType(obfSig.getReturnType(), obfSig.getParamTypes())); } catch (NoSuchMethodException | IllegalAccessException e) { if (e.getMessage().startsWith("no such method")) { try { Method m = clazz.getValue().getDeclaredMethod(methodSignature.split("\\(")[0], obfSig.getParamTypes()); m.setAccessible(true); mh = MethodHandles.lookup().unreflect(m); } catch (NoSuchMethodException | IllegalAccessException e1) { e1.printStackTrace(); } } } if (mh == null) { mh = mh; }*/ CtMethod method = ctClass.getMethod(methodSignature.split("\\(")[0], "(" + methodSignature.split("\\(")[1]); ctMethods.get(method.getDeclaringClass()).put(methodName, method); } } fields.put(ctClass, HashBiMap.<String, Field>create()); ctFields.put(ctClass, HashBiMap.<String, CtField>create()); if (classObject.containsKey("fields")) { for (Map.Entry<String, ConfigValue> fieldEntry : ((ConfigObject) classObject.get("fields")) .entrySet()) { String obfuscatedFieldName = fieldEntry.getKey(); String fieldName = (String) fieldEntry.getValue().unwrapped(); ctFields.get(ctClass).put(fieldName, ctClass.getDeclaredField(obfuscatedFieldName)); } } } } } catch (NotFoundException e) { e.printStackTrace(); } }
From source file:seeit3d.base.model.Container.java
private Container(IContainerRepresentedObject representedObject, List<MetricCalculator> metrics, int currentLevel) { this.identifier = Utils.generateContainerIdentifier(); this.polycylinders = new ArrayList<PolyCylinder>(); this.relatedContainers = new ArrayList<Container>(); this.children = new ArrayList<Container>(); this.representedObject = representedObject; this.metrics = metrics; this.propertiesMap = HashBiMap.create(); for (int i = 0; i < VisualProperty.values().length && i < metrics.size(); i++) { VisualProperty prop = VisualProperty.values()[i]; MetricCalculator metric = metrics.get(i); this.propertiesMap.put(metric, prop); }//from w w w. j a v a 2s .co m this.sorted = false; this.currentLevel = currentLevel; this.sceneGraphRelationshipGenerator = new NoRelationships(); SeeIT3D.injector().injectMembers(this); }
From source file:com.google.code.jgntp.internal.io.NioTcpGntpClient.java
public NioTcpGntpClient(GntpApplicationInfo applicationInfo, SocketAddress growlAddress, Executor executor, GntpListener listener, GntpPassword password, boolean encrypted, long retryTime, TimeUnit retryTimeUnit, int notificationRetryCount) { super(applicationInfo, growlAddress, password, encrypted); Preconditions.checkNotNull(executor, "Executor must not be null"); if (retryTime > 0) { Preconditions.checkNotNull(retryTimeUnit, "Retry time unit must not be null"); }/*from w w w .j a v a 2s.c o m*/ Preconditions.checkArgument(notificationRetryCount >= 0, "Notification retries must be equal or greater than zero"); this.retryTime = retryTime; this.retryTimeUnit = retryTimeUnit; this.notificationRetryCount = notificationRetryCount; if (retryTime > 0) { retryExecutorService = Executors.newSingleThreadScheduledExecutor(); } else { retryExecutorService = null; } bootstrap = new ClientBootstrap(new NioClientSocketChannelFactory(executor, executor)); bootstrap.setPipelineFactory(new GntpChannelPipelineFactory(new GntpChannelHandler(this, listener))); bootstrap.setOption("tcpNoDelay", true); bootstrap.setOption("remoteAddress", growlAddress); bootstrap.setOption("soTimeout", 60 * 1000); bootstrap.setOption("receiveBufferSizePredictor", new AdaptiveReceiveBufferSizePredictor()); channelGroup = new DefaultChannelGroup("jgntp"); notificationIdGenerator = new AtomicLong(); // no need to sync on this map because notificationIdGenerator guarantees ID uniqueness // and there is only one way for alterations to this map occur for any notification // see GntpChannelHandler for details notificationsSent = HashBiMap.create(); notificationRetries = Maps.newConcurrentMap(); }
From source file:de.iteratec.iteraplan.elasticeam.util.I18nMap.java
/** * Adds a new metamodel element and name to the map. * /*from w ww .ja va 2s. c o m*/ * @param locale * The locale of the name. * @param key * The name. * @param value * The metamodel element. */ public void set(Locale locale, String key, N value) { if (!this.valueByLocalizedName.containsKey(locale)) { BiMap<String, N> localeValues = HashBiMap.create(); this.valueByLocalizedName.put(locale, localeValues); } BiMap<String, N> localeValues = this.valueByLocalizedName.get(locale); if (localeValues.containsKey(key) && !value.equals(localeValues.get(key))) { throw new MetamodelException(ElasticeamException.GENERAL_ERROR, "Duplicate locale name " + key + " in locale " + locale + "."); } if (key == null) { localeValues.inverse().remove(value); } else { if (localeValues.inverse().containsKey(value)) { localeValues.inverse().remove(value); } localeValues.put(key, value); } }
From source file:de.sep2011.funckit.model.graphmodel.implementations.ComponentImpl.java
/** * Do initialization here as there are many constructors. */// ww w . jav a2s .c o m private void init(ComponentType type) { this.type = type; this.orientation = type.getOrientation(); accessPointMap = HashBiMap.create(); for (Input inner : type.getInputs()) { assert type.getOuterPosition(inner) != null; assert type.getOuterName(inner) != null; Input outer = new InputImpl(this, type.getOuterPosition(inner), type.getOuterName(inner)); inputs.add(outer); accessPointMap.put(outer, inner); } for (Output inner : type.getOutputs()) { assert type.getOuterPosition(inner) != null; assert type.getOuterName(inner) != null; Output outer = new OutputImpl(this, type.getOuterPosition(inner), type.getOuterName(inner)); outputs.add(outer); accessPointMap.put(outer, inner); } }
From source file:org.schemarepo.api.TypedSchemaRepository.java
/** * Utility function for getting a idToSchemaCache for a given subject, or * initializing such cache if it does not exist yet. * * @param subjectName of the desired idToSchemaCache * @return the idToSchemaCache for the requested subject *///from w w w . j ava2s . co m private BiMap<ID, SCHEMA> getIdToSchemaCache(SUBJECT subjectName) { BiMap<ID, SCHEMA> idToSchemaCache = subjectToIdToSchemaCache.get(subjectName); if (idToSchemaCache == null) { synchronized (this) { // Checking again, in case it was initialized between the initial get // and the if check. idToSchemaCache = subjectToIdToSchemaCache.get(subjectName); if (idToSchemaCache == null) { idToSchemaCache = HashBiMap.create(); subjectToIdToSchemaCache.put(subjectName, idToSchemaCache); } } } return idToSchemaCache; }
From source file:org.killbill.billing.plugin.meter.timeline.persistent.DefaultTimelineDao.java
@Override public BiMap<Integer, String> getSources(final TenantContext context) throws UnableToObtainConnectionException, CallbackFailedException { final HashBiMap<Integer, String> accumulator = HashBiMap.create(); for (final Map<String, Object> metric : delegate.getSources(createInternalTenantContext(context))) { accumulator.put(Integer.valueOf(metric.get("record_id").toString()), metric.get("source").toString()); }//from w ww. j a v a 2 s . c o m return accumulator; }