List of usage examples for java.util LinkedHashMap forEach
public void forEach(BiConsumer<? super K, ? super V> action)
From source file:com.streamsets.pipeline.lib.jdbc.multithread.TableContextUtil.java
/** * Determines if there are invalid values specified in the initial offset value * for columns./* w ww . ja va 2 s . c om*/ */ //@VisibleForTesting void checkForInvalidInitialOffsetValues(PushSource.Context context, List<Stage.ConfigIssue> issues, String qualifiedTableName, LinkedHashMap<String, Integer> offsetColumnToType, Map<String, String> offsetColumnToStartOffset) throws StageException { List<String> invalidInitialOffsetFieldAndValue = new ArrayList<>(); offsetColumnToType.forEach((offsetColumn, offsetSqlType) -> { String initialOffsetValue = offsetColumnToStartOffset.get(offsetColumn); try { if (jdbcUtil.isSqlTypeOneOf(offsetSqlType, Types.DATE, Types.TIME, Types.TIMESTAMP)) { Long.valueOf(initialOffsetValue); //NOSONAR } else { //Use native field conversion strategy to conver string to specify type and get value Field.create(OffsetQueryUtil.SQL_TYPE_TO_FIELD_TYPE.get(offsetSqlType), initialOffsetValue) .getValue(); } } catch (IllegalArgumentException e) { LOG.error(Utils.format("Invalid Initial Offset Value {} for column {} in table {}", initialOffsetValue, offsetColumn, qualifiedTableName), e); invalidInitialOffsetFieldAndValue.add(offsetColumn + " - " + initialOffsetValue); } }); if (!invalidInitialOffsetFieldAndValue.isEmpty()) { throw new StageException(JdbcErrors.JDBC_72, qualifiedTableName, COMMA_JOINER.join(invalidInitialOffsetFieldAndValue)); } }
From source file:com.netflix.imfutility.itunes.audio.AudioMapXmlProvider.java
/** * Gets flat map of uuid + channel of track for each tracks and uuids: [uuid:cn1, uuid:cn2, ....]. * * @param virtualTracksChannels uuid to channels map * @return flat map of uuid + channel of track for each tracks and uuids: [uuid:cn1, uuid:cn2, ....] */// www. j a va 2s . c o m private ArrayList<String> getSequencedTrackChannelNumbers( LinkedHashMap<String, Integer> virtualTracksChannels) { ArrayList<String> res = new ArrayList<>(); virtualTracksChannels.forEach((String trackId, Integer trackChannelCount) -> { for (int i = 0; i < trackChannelCount; i++) { res.add(getIntermediateKey(trackId, i)); } }); return res; }
From source file:com.netflix.imfutility.itunes.audio.AudioMapXmlProvider.java
/** * Gets pan parameter for track.//from ww w.ja v a2 s.com * <p></p> * Example: pan=4c|c0=c0|c1=c1|c2=c2|c3=c3,aformat=channel_layouts=FL+FR+FC+LFE * * @param track audio track * @return pan parameter for track */ private String getPanParameter(LinkedHashMap<String, ChannelType> track) { int[] i = { 0 }; StringJoiner aformat = new StringJoiner("+", ",aformat=channel_layouts=", ""); // ,aformat=channel_layouts= StringBuilder panParameter = new StringBuilder("pan="); // pan= panParameter.append(track.size()).append("c"); // pan=4c track.forEach((chName, channel) -> { panParameter.append("|c").append(i[0]).append("="); // pan=4c|c0= // gets channel number in amerge channels sequence int sequencedChannel = sequencedTrackChannelNumbers.indexOf( getIntermediateKey(channel.getCPLVirtualTrackId(), channel.getCPLVirtualTrackChannel() - 1)); if (sequencedChannel == -1) { throw new ConversionException(String.format( "Audio Virtual TrackId \"%s\" with channel number \"%d\" was not found in CPL.", channel.getCPLVirtualTrackId(), channel.getCPLVirtualTrackChannel())); } panParameter.append("c").append(sequencedChannel); // pan=4c|c0=c0 aformat.add(chName); // ,aformat=channel_layouts=FL i[0]++; }); panParameter.append(aformat); // pan=4c|c0=c0|c1=c1|c2=c2|c3=c3,aformat=channel_layouts=FL+FR+FC+LFE return panParameter.toString(); }
From source file:net.minecraftforge.registries.GameData.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public static Multimap<ResourceLocation, ResourceLocation> injectSnapshot( Map<ResourceLocation, ForgeRegistry.Snapshot> snapshot, boolean injectFrozenData, boolean isLocalWorld) { FMLLog.log.info("Injecting existing registry data into this {} instance", FMLCommonHandler.instance().getEffectiveSide().isServer() ? "server" : "client"); RegistryManager.ACTIVE.registries.forEach((name, reg) -> reg.validateContent(name)); RegistryManager.ACTIVE.registries.forEach((name, reg) -> reg.dump(name)); RegistryManager.ACTIVE.registries.forEach((name, reg) -> reg.resetDelegates()); List<ResourceLocation> missingRegs = snapshot.keySet().stream() .filter(name -> !RegistryManager.ACTIVE.registries.containsKey(name)).collect(Collectors.toList()); if (missingRegs.size() > 0) { String text = "Forge Mod Loader detected missing/unknown registrie(s).\n\n" + "There are " + missingRegs.size() + " missing registries in this save.\n" + "If you continue the missing registries will get removed.\n" + "This may cause issues, it is advised that you create a world backup before continuing.\n\n" + "Missing Registries:\n"; for (ResourceLocation s : missingRegs) text += s.toString() + "\n"; if (!StartupQuery.confirm(text)) StartupQuery.abort();// w w w . ja v a2s.c om } RegistryManager STAGING = new RegistryManager("STAGING"); final Map<ResourceLocation, Map<ResourceLocation, Integer[]>> remaps = Maps.newHashMap(); final LinkedHashMap<ResourceLocation, Map<ResourceLocation, Integer>> missing = Maps.newLinkedHashMap(); // Load the snapshot into the "STAGING" registry snapshot.forEach((key, value) -> { final Class<? extends IForgeRegistryEntry> clazz = RegistryManager.ACTIVE.getSuperType(key); remaps.put(key, Maps.newLinkedHashMap()); missing.put(key, Maps.newHashMap()); loadPersistentDataToStagingRegistry(RegistryManager.ACTIVE, STAGING, remaps.get(key), missing.get(key), key, value, clazz); }); snapshot.forEach((key, value) -> { value.dummied.forEach(dummy -> { Map<ResourceLocation, Integer> m = missing.get(key); ForgeRegistry<?> reg = STAGING.getRegistry(key); // Currently missing locally, we just inject and carry on if (m.containsKey(dummy)) { if (reg.markDummy(dummy, m.get(dummy))) m.remove(dummy); } else if (isLocalWorld) { if (ForgeRegistry.DEBUG) FMLLog.log.debug("Registry {}: Resuscitating dummy entry {}", key, dummy); } else { // The server believes this is a dummy block identity, but we seem to have one locally. This is likely a conflict // in mod setup - Mark this entry as a dummy int id = reg.getID(dummy); FMLLog.log.warn( "Registry {}: The ID {} is currently locally mapped - it will be replaced with a dummy for this session", key, id); reg.markDummy(dummy, id); } }); }); int count = missing.values().stream().mapToInt(Map::size).sum(); if (count > 0) { FMLLog.log.debug("There are {} mappings missing - attempting a mod remap", count); Multimap<ResourceLocation, ResourceLocation> defaulted = ArrayListMultimap.create(); Multimap<ResourceLocation, ResourceLocation> failed = ArrayListMultimap.create(); missing.entrySet().stream().filter(e -> e.getValue().size() > 0).forEach(m -> { ResourceLocation name = m.getKey(); ForgeRegistry<?> reg = STAGING.getRegistry(name); RegistryEvent.MissingMappings<?> event = reg.getMissingEvent(name, m.getValue()); MinecraftForge.EVENT_BUS.post(event); List<MissingMappings.Mapping<?>> lst = event.getAllMappings().stream() .filter(e -> e.getAction() == MissingMappings.Action.DEFAULT).collect(Collectors.toList()); if (!lst.isEmpty()) { FMLLog.log.error("Unidentified mapping from registry {}", name); lst.forEach(map -> { FMLLog.log.error(" {}: {}", map.key, map.id); if (!isLocalWorld) defaulted.put(name, map.key); }); } event.getAllMappings().stream().filter(e -> e.getAction() == MissingMappings.Action.FAIL) .forEach(fail -> failed.put(name, fail.key)); final Class<? extends IForgeRegistryEntry> clazz = RegistryManager.ACTIVE.getSuperType(name); processMissing(clazz, name, STAGING, event, m.getValue(), remaps.get(name), defaulted.get(name), failed.get(name)); }); if (!defaulted.isEmpty() && !isLocalWorld) return defaulted; if (!defaulted.isEmpty()) { StringBuilder buf = new StringBuilder(); buf.append("Forge Mod Loader detected missing registry entries.\n\n").append("There are ") .append(defaulted.size()).append(" missing entries in this save.\n") .append("If you continue the missing entries will get removed.\n") .append("A world backup will be automatically created in your saves directory.\n\n"); defaulted.asMap().forEach((name, entries) -> { buf.append("Missing ").append(name).append(":\n"); entries.forEach(rl -> buf.append(" ").append(rl).append("\n")); }); boolean confirmed = StartupQuery.confirm(buf.toString()); if (!confirmed) StartupQuery.abort(); try { String skip = System.getProperty("fml.doNotBackup"); if (skip == null || !"true".equals(skip)) { ZipperUtil.backupWorld(); } else { for (int x = 0; x < 10; x++) FMLLog.log.error("!!!!!!!!!! UPDATING WORLD WITHOUT DOING BACKUP !!!!!!!!!!!!!!!!"); } } catch (IOException e) { StartupQuery.notify("The world backup couldn't be created.\n\n" + e); StartupQuery.abort(); } } if (!defaulted.isEmpty()) { if (isLocalWorld) FMLLog.log.error( "There are unidentified mappings in this world - we are going to attempt to process anyway"); } } if (injectFrozenData) { // If we're loading from disk, we can actually substitute air in the block map for anything that is otherwise "missing". This keeps the reference in the map, in case // the block comes back later missing.forEach((name, m) -> { ForgeRegistry<?> reg = STAGING.getRegistry(name); m.forEach((rl, id) -> reg.markDummy(rl, id)); }); // If we're loading up the world from disk, we want to add in the new data that might have been provisioned by mods // So we load it from the frozen persistent registry RegistryManager.ACTIVE.registries.forEach((name, reg) -> { final Class<? extends IForgeRegistryEntry> clazz = RegistryManager.ACTIVE.getSuperType(name); loadFrozenDataToStagingRegistry(STAGING, name, remaps.get(name), clazz); }); } // Validate that all the STAGING data is good STAGING.registries.forEach((name, reg) -> reg.validateContent(name)); // Load the STAGING registry into the ACTIVE registry for (Map.Entry<ResourceLocation, ForgeRegistry<? extends IForgeRegistryEntry<?>>> r : RegistryManager.ACTIVE.registries .entrySet()) { final Class<? extends IForgeRegistryEntry> registrySuperType = RegistryManager.ACTIVE .getSuperType(r.getKey()); loadRegistry(r.getKey(), STAGING, RegistryManager.ACTIVE, registrySuperType, true); } // Dump the active registry RegistryManager.ACTIVE.registries.forEach((name, reg) -> reg.dump(name)); // Tell mods that the ids have changed Loader.instance().fireRemapEvent(remaps, false); // The id map changed, ensure we apply object holders ObjectHolderRegistry.INSTANCE.applyObjectHolders(); // Return an empty list, because we're good return ArrayListMultimap.create(); }