List of usage examples for com.google.common.collect ImmutableMap get
V get(Object key);
From source file:de.adrodoc55.minecraft.mpl.conversion.StructureConverter.java
public TagCompound convert(MplCompilationResult result) { states.clear();//from w w w. j a va 2 s . c om ImmutableMap<Coordinate3D, MplBlock> blockMap = result.getBlocks(); ImmutableSet<Coordinate3D> coordinates = blockMap.keySet(); Coordinate3D min = getMinCoordinate(coordinates); Coordinate3D max = getMaxCoordinate(coordinates); List<ITag> blocks = new ArrayList<>(); for (int y = min.getY(); y <= max.getY(); y++) { for (int z = min.getZ(); z <= max.getZ(); z++) { for (int x = min.getX(); x <= max.getX(); x++) { Coordinate3D coord = new Coordinate3D(x, y, z); MplBlock block = blockMap.get(coord); if (block == null) { block = new AirBlock(coord); } TagCompound tag = new TagCompound(""); tag.setTag(new TagInteger("state", registerState(block))); tag.setTag(new TagList("pos", posAt(x, y, z))); if (block instanceof CommandBlock) { TagCompound nbt = toControl((CommandBlock) block); nbt.setName("nbt"); tag.setTag(nbt); } blocks.add(tag); } } } short sizeX = (short) (1 + max.getX() - min.getX()); short sizeY = (short) (1 + max.getY() - min.getY()); short sizeZ = (short) (1 + max.getZ() - min.getZ()); List<ITag> palette = states.stream().map(s -> s.getState()).collect(toList()); TagCompound structure = new TagCompound(""); structure.setTag(new TagInteger("version", 1)); structure.setTag(new TagString("author", "MPL")); structure.setTag(new TagList("blocks", blocks)); structure.setTag(new TagList("entities", new ArrayList<>())); structure.setTag(new TagList("palette", palette)); structure.setTag(new TagList("size", posAt(sizeX, sizeY, sizeZ))); return structure; }
From source file:pl.asie.foamfix.client.Deduplicator.java
public Object deduplicateObject(Object o, int recursion) { if (o == null || recursion > maxRecursion) return o; Class c = o.getClass();/*from ww w.ja v a 2 s . co m*/ if (!shouldCheckClass(c)) return o; if (!deduplicatedObjects.add(o)) return o; // System.out.println("-" + Strings.repeat("-", recursion) + " " + c.getName()); if (o instanceof IBakedModel) { if (o instanceof IPerspectiveAwareModel.MapWrapper) { try { Object to = IPAM_MW_TRANSFORMS_GETTER.invoke(o); Object toD = deduplicate0(to); if (toD != null && to != toD) { IPAM_MW_TRANSFORMS_SETTER.invoke(o, toD); } } catch (Throwable t) { t.printStackTrace(); } } else if ("net.minecraftforge.client.model.ItemLayerModel$BakedItemModel".equals(c.getName())) { try { Object to = BIM_TRANSFORMS_GETTER.invoke(o); Object toD = deduplicate0(to); if (toD != null && to != toD) { BIM_TRANSFORMS_SETTER.invoke(o, toD); } } catch (Throwable t) { t.printStackTrace(); } } } if (c == UnpackedBakedQuad.class) { try { float[][][] array = (float[][][]) FIELD_UNPACKED_DATA_GETTER.invokeExact((UnpackedBakedQuad) o); // float[][][]s are not currently deduplicated deduplicate0(array); } catch (Throwable t) { t.printStackTrace(); } } else if (o instanceof ResourceLocation || o instanceof TRSRTransformation) { return deduplicate0(o); } else if (c == ItemCameraTransforms.class) { Object d = deduplicate0(o); if (d != o) return d; // TODO: Add ItemTransformVec3f dedup, maybe return o; } else if (o instanceof Item || o instanceof Block || o instanceof World || o instanceof Entity || o instanceof Logger || o instanceof IRegistry) { BLACKLIST_CLASS.add(c); } else if (o != ItemOverrideList.NONE && c == ItemOverrideList.class && ((ItemOverrideList) o).getOverrides().isEmpty()) { successfuls++; return ItemOverrideList.NONE; } else if (o instanceof com.google.common.base.Optional) { Optional opt = (Optional) o; if (opt.isPresent()) { Object b = deduplicateObject(opt.get(), recursion + 1); if (b != null && b != opt.get()) { return Optional.of(b); } } } else if (o instanceof Multimap) { if (o instanceof ImmutableMultimap) { // TODO: Handle me? } else { for (Object key : ((Multimap) o).keySet()) { List l = Lists.newArrayList(((Multimap) o).values()); for (int i = 0; i < l.size(); i++) { l.set(i, deduplicateObject(l.get(i), recursion + 1)); } ((Multimap) o).replaceValues(key, l); } } } else if (o instanceof Map) { if (o instanceof ImmutableMap) { ImmutableMap im = (ImmutableMap) o; Map newMap = new HashMap(); boolean deduplicated = false; for (Object key : im.keySet()) { Object a = im.get(key); Object b = deduplicateObject(a, recursion + 1); newMap.put(key, b != null ? b : a); if (b != null && b != a) deduplicated = true; } if (deduplicated) { return ImmutableMap.copyOf(newMap); } } else { for (Object key : ((Map) o).keySet()) { Object value = ((Map) o).get(key); Object valueD = deduplicateObject(value, recursion + 1); if (valueD != null && value != valueD) ((Map) o).put(key, valueD); } } } else if (o instanceof List) { if (o instanceof ImmutableList) { ImmutableList il = (ImmutableList) o; List newList = new ArrayList(); boolean deduplicated = false; for (int i = 0; i < il.size(); i++) { Object a = il.get(i); Object b = deduplicateObject(a, recursion + 1); newList.add(b != null ? b : a); if (b != null && b != a) deduplicated = true; } if (deduplicated) { return ImmutableList.copyOf(newList); } } else { List l = (List) o; for (int i = 0; i < l.size(); i++) { l.set(i, deduplicateObject(l.get(i), recursion + 1)); } } } else if (o instanceof Collection) { if (!COLLECTION_CONSTRUCTORS.containsKey(c)) { try { COLLECTION_CONSTRUCTORS.put(c, MethodHandles.publicLookup().findConstructor(c, MethodType.methodType(void.class))); } catch (Exception e) { COLLECTION_CONSTRUCTORS.put(c, null); } } MethodHandle constructor = COLLECTION_CONSTRUCTORS.get(c); if (constructor != null) { try { Collection nc = (Collection) constructor.invoke(); for (Object o1 : ((Collection) o)) { nc.add(deduplicateObject(o1, recursion + 1)); } return nc; } catch (Throwable t) { } } // fallback for (Object o1 : ((Collection) o)) { deduplicateObject(o1, recursion + 1); } } else if (c.isArray()) { for (int i = 0; i < Array.getLength(o); i++) { Object entry = Array.get(o, i); Object entryD = deduplicateObject(entry, recursion + 1); if (entryD != null && entry != entryD) Array.set(o, i, entryD); } } else { if (!CLASS_FIELDS.containsKey(c)) { ImmutableSet.Builder<MethodHandle[]> fsBuilder = ImmutableSet.builder(); Class cc = c; do { for (Field f : cc.getDeclaredFields()) { f.setAccessible(true); if ((f.getModifiers() & Modifier.STATIC) != 0) continue; if (shouldCheckClass(f.getType())) { try { fsBuilder.add(new MethodHandle[] { MethodHandles.lookup().unreflectGetter(f), MethodHandles.lookup().unreflectSetter(f) }); } catch (IllegalAccessException e) { e.printStackTrace(); } } } } while ((cc = cc.getSuperclass()) != Object.class); CLASS_FIELDS.put(c, fsBuilder.build()); } for (MethodHandle[] mh : CLASS_FIELDS.get(c)) { try { // System.out.println("-" + Strings.repeat("-", recursion) + "* " + f.getName()); Object value = mh[0].invoke(o); Object valueD = deduplicateObject(value, recursion + 1); if (TRIM_ARRAYS_CLASSES.contains(c)) { if (valueD instanceof ArrayList) { ((ArrayList) valueD).trimToSize(); } } if (valueD != null && value != valueD) mh[1].invoke(o, valueD); } catch (IllegalAccessException e) { } catch (Throwable t) { t.printStackTrace(); } } } return o; }
From source file:org.excalibur.driver.google.compute.GoogleCompute.java
@Override public void stop(String... names) { ImmutableMap<String, Instance> instances = getAllComputeInstances(); for (String instanceName : names) { Instance instance = instances.get(instanceName); Disk disk = getBootDisk(instance); compute.instances().setDiskAutoDelete(credentials_.getProject(), instance.getZone(), instance.getName(), false, disk.getName());/*from w w w .ja v a 2 s . co m*/ } this.terminateInstances(names); }
From source file:vazkii.botania.client.model.SpecialFlowerModel.java
@Override public IModel process(ImmutableMap<String, String> customData) { // Load the base variant from blockstate json, and also add all the model paths we received from external API ImmutableMap.Builder<Optional<String>, ModelResourceLocation> blockBuilder = ImmutableMap.builder(); ImmutableMap.Builder<Optional<String>, ModelResourceLocation> itemBuilder = ImmutableMap.builder(); for (String key : customData.keySet()) { if ("base".equals(key)) { blockBuilder.put(Optional.empty(), getLocation(customData.get(key))); }// ww w . ja v a 2s . c o m } for (Map.Entry<String, ModelResourceLocation> e : BotaniaAPIClient.getRegisteredSubtileBlockModels() .entrySet()) { blockBuilder.put(Optional.of(e.getKey()), e.getValue()); } for (Map.Entry<String, ModelResourceLocation> e : BotaniaAPIClient.getRegisteredSubtileItemModels() .entrySet()) { itemBuilder.put(Optional.of(e.getKey()), e.getValue()); } ImmutableMap<Optional<String>, ModelResourceLocation> blockModels = blockBuilder.build(); ImmutableMap<Optional<String>, ModelResourceLocation> itemModels = itemBuilder.build(); if (blockModels.isEmpty() && itemModels.isEmpty()) return INSTANCE; return new SpecialFlowerModel(blockModels, itemModels); }
From source file:com.pinterest.pinlater.backends.mysql.PinLaterMySQLBackend.java
@Override protected int retryFailedJobsFromShard(final String queueName, final String shardName, final int priority, final int attemptsRemaining, final long runAfterTimestampMillis, final int limit) throws Exception { Connection conn = null;//from w w w . j av a 2s. c om try { ImmutableMap<String, MySQLDataSources> shardMap = shardMapRef.get(); conn = shardMap.get(shardName).getGeneralDataSource().getConnection(); return JdbcUtils.executeUpdate(conn, String.format(MySQLQueries.RETRY_FAILED_JOBS, MySQLBackendUtils.constructJobsTableName(queueName, shardName, priority)), PinLaterJobState.PENDING.getValue(), attemptsRemaining, new Timestamp(runAfterTimestampMillis), PinLaterJobState.FAILED.getValue(), limit); } finally { JdbcUtils.closeConnection(conn); } }
From source file:com.pinterest.pinlater.backends.mysql.PinLaterMySQLBackend.java
@Override protected int deleteJobsFromShard(final String queueName, final String shardName, final PinLaterJobState jobState, final int priority, final String bodyRegexTomatch, final int limit) throws Exception { Connection conn = null;// www.java2s. com try { ImmutableMap<String, MySQLDataSources> shardMap = shardMapRef.get(); conn = shardMap.get(shardName).getGeneralDataSource().getConnection(); return JdbcUtils.executeUpdate(conn, String.format(MySQLQueries.DELETE_JOBS, MySQLBackendUtils.constructJobsTableName(queueName, shardName, priority), getBodyRegexClause(bodyRegexTomatch)), jobState.getValue(), limit); } finally { JdbcUtils.closeConnection(conn); } }
From source file:com.facebook.buck.cli.BuckConfig.java
public Optional<String> getValue(String sectionName, String propertyName) { ImmutableMap<String, String> properties = this.getEntriesForSection(sectionName); return Optional.fromNullable(properties.get(propertyName)); }
From source file:com.facebook.buck.cxx.CxxLibraryDescription.java
public ImmutableSortedSet<Flavor> addImplicitFlavorsForRuleTypes(ImmutableSortedSet<Flavor> argDefaultFlavors, BuildRuleType... types) {//from ww w . jav a 2 s.com Optional<Flavor> typeFlavor = LIBRARY_TYPE.getFlavor(argDefaultFlavors); Optional<Flavor> platformFlavor = getCxxPlatforms().getFlavor(argDefaultFlavors); LOG.debug("Got arg default type %s platform %s", typeFlavor, platformFlavor); for (BuildRuleType type : types) { ImmutableMap<String, Flavor> libraryDefaults = cxxBuckConfig.getDefaultFlavorsForRuleType(type); if (!typeFlavor.isPresent()) { typeFlavor = Optional.ofNullable(libraryDefaults.get(CxxBuckConfig.DEFAULT_FLAVOR_LIBRARY_TYPE)); } if (!platformFlavor.isPresent()) { platformFlavor = Optional.ofNullable(libraryDefaults.get(CxxBuckConfig.DEFAULT_FLAVOR_PLATFORM)); } } ImmutableSortedSet<Flavor> result = ImmutableSortedSet.of( // Default to static if not otherwise specified. typeFlavor.orElse(CxxDescriptionEnhancer.STATIC_FLAVOR), platformFlavor.orElse(defaultCxxPlatform.getFlavor())); LOG.debug("Got default flavors %s for rule types %s", result, Arrays.toString(types)); return result; }
From source file:com.facebook.buck.cli.BuckConfig.java
/** * A (possibly empty) sequence of paths to files that should be included by default when * evaluating a build file.// ww w . ja v a2 s . c o m */ public Iterable<String> getDefaultIncludes() { ImmutableMap<String, String> entries = getEntriesForSection("buildfile"); String includes = Strings.nullToEmpty(entries.get("includes")); return Splitter.on(' ').trimResults().omitEmptyStrings().split(includes); }
From source file:com.pinterest.pinlater.backends.mysql.PinLaterMySQLBackend.java
@Override protected int getJobCountFromShard(final String queueName, final String shardName, final Set<Integer> priorities, final PinLaterJobState jobState, final boolean countFutureJobs, final String bodyRegexTomatch) throws Exception { final String countQuery = countFutureJobs ? MySQLQueries.COUNT_FUTURE_JOBS_BY_STATE_PRIORITY : MySQLQueries.COUNT_CURRENT_JOBS_BY_STATE_PRIORITY; int totalCount = 0; Connection conn = null;// w ww .jav a2s .c o m try { ImmutableMap<String, MySQLDataSources> shardMap = shardMapRef.get(); conn = shardMap.get(shardName).getGeneralDataSource().getConnection(); for (int priority : priorities) { Integer count = JdbcUtils.selectOne(conn, String.format(countQuery, MySQLBackendUtils.constructJobsTableName(queueName, shardName, priority), getBodyRegexClause(bodyRegexTomatch)), new SingleColumnRowProcessor<Integer>(Integer.class), jobState.getValue(), countLimit); if (count != null) { totalCount += count; } } } finally { JdbcUtils.closeConnection(conn); } return totalCount; }