Java Code Examples for java.util.EnumMap#entrySet()
The following examples show how to use
java.util.EnumMap#entrySet() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RocksRawKVStore.java From sofa-jraft with Apache License 2.0 | 6 votes |
void ingestSstFiles(final EnumMap<SstColumnFamily, File> sstFileTable) { final Timer.Context timeCtx = getTimeContext("INGEST_SST_FILE"); final Lock readLock = this.readWriteLock.readLock(); readLock.lock(); try { for (final Map.Entry<SstColumnFamily, File> entry : sstFileTable.entrySet()) { final SstColumnFamily sstColumnFamily = entry.getKey(); final File sstFile = entry.getValue(); final ColumnFamilyHandle columnFamilyHandle = findColumnFamilyHandle(sstColumnFamily); try (final IngestExternalFileOptions ingestOptions = new IngestExternalFileOptions()) { if (FileUtils.sizeOf(sstFile) == 0L) { return; } final String filePath = sstFile.getAbsolutePath(); LOG.info("Start ingest sst file {}.", filePath); this.db.ingestExternalFile(columnFamilyHandle, Collections.singletonList(filePath), ingestOptions); } catch (final RocksDBException e) { throw new StorageException("Fail to ingest sst file at path: " + sstFile, e); } } } finally { readLock.unlock(); timeCtx.stop(); } }
Example 2
Source File: DistinctEntrySetElements.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { final EnumMap<TestEnum, String> enumMap = new EnumMap<>(TestEnum.class); for (TestEnum e : TestEnum.values()) { enumMap.put(e, e.name()); } Set<Map.Entry<TestEnum, String>> entrySet = enumMap.entrySet(); HashSet<Map.Entry<TestEnum, String>> hashSet = new HashSet<>(entrySet); if (false == hashSet.equals(entrySet)) { throw new RuntimeException("Test FAILED: Sets are not equal."); } if (hashSet.hashCode() != entrySet.hashCode()) { throw new RuntimeException("Test FAILED: Set's hashcodes are not equal."); } }
Example 3
Source File: DistinctEntrySetElements.java From hottub with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { final EnumMap<TestEnum, String> enumMap = new EnumMap<>(TestEnum.class); for (TestEnum e : TestEnum.values()) { enumMap.put(e, e.name()); } Set<Map.Entry<TestEnum, String>> entrySet = enumMap.entrySet(); HashSet<Map.Entry<TestEnum, String>> hashSet = new HashSet<>(entrySet); if (false == hashSet.equals(entrySet)) { throw new RuntimeException("Test FAILED: Sets are not equal."); } if (hashSet.hashCode() != entrySet.hashCode()) { throw new RuntimeException("Test FAILED: Set's hashcodes are not equal."); } }
Example 4
Source File: DistinctEntrySetElements.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { final EnumMap<TestEnum, String> enumMap = new EnumMap<>(TestEnum.class); for (TestEnum e : TestEnum.values()) { enumMap.put(e, e.name()); } Set<Map.Entry<TestEnum, String>> entrySet = enumMap.entrySet(); HashSet<Map.Entry<TestEnum, String>> hashSet = new HashSet<>(entrySet); if (false == hashSet.equals(entrySet)) { throw new RuntimeException("Test FAILED: Sets are not equal."); } if (hashSet.hashCode() != entrySet.hashCode()) { throw new RuntimeException("Test FAILED: Set's hashcodes are not equal."); } }
Example 5
Source File: DistinctEntrySetElements.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { final EnumMap<TestEnum, String> enumMap = new EnumMap<>(TestEnum.class); for (TestEnum e : TestEnum.values()) { enumMap.put(e, e.name()); } Set<Map.Entry<TestEnum, String>> entrySet = enumMap.entrySet(); HashSet<Map.Entry<TestEnum, String>> hashSet = new HashSet<>(entrySet); if (false == hashSet.equals(entrySet)) { throw new RuntimeException("Test FAILED: Sets are not equal."); } if (hashSet.hashCode() != entrySet.hashCode()) { throw new RuntimeException("Test FAILED: Set's hashcodes are not equal."); } }
Example 6
Source File: DistinctEntrySetElements.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { final EnumMap<TestEnum, String> enumMap = new EnumMap<>(TestEnum.class); for (TestEnum e : TestEnum.values()) { enumMap.put(e, e.name()); } Set<Map.Entry<TestEnum, String>> entrySet = enumMap.entrySet(); HashSet<Map.Entry<TestEnum, String>> hashSet = new HashSet<>(entrySet); if (false == hashSet.equals(entrySet)) { throw new RuntimeException("Test FAILED: Sets are not equal."); } if (hashSet.hashCode() != entrySet.hashCode()) { throw new RuntimeException("Test FAILED: Set's hashcodes are not equal."); } }
Example 7
Source File: ImmutableMap.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
private static <K extends Enum<K>, V> ImmutableMap<K, V> copyOfEnumMap(EnumMap<K, ? extends V> original) { EnumMap<K, V> copy = new EnumMap<K, V>(original); for (Map.Entry<?, ?> entry : copy.entrySet()) { checkEntryNotNull(entry.getKey(), entry.getValue()); } return ImmutableEnumMap.asImmutable(copy); }
Example 8
Source File: StringResources.java From buck with Apache License 2.0 | 5 votes |
/** * Writes the metadata and strings in the following format to the output stream: [Int: # of * plurals] [Int: Smallest resource id among plurals] [[Short: resource id delta] [Byte: #genders] * [[Byte: gender enum ordinal] [Byte: #categories] [[Byte: category] [Short: length of plural * value]] x #categories] x # of genders] x # of plurals [Byte array of plural value] x Summation * of gedners over plural categories over # of plurals * * @param outputStream * @throws IOException */ private void writePlurals(DataOutputStream outputStream) throws IOException { outputStream.writeInt(plurals.size()); if (plurals.isEmpty()) { return; } int previousResourceId = plurals.firstKey(); outputStream.writeInt(previousResourceId); try (ByteArrayOutputStream dataStream = new ByteArrayOutputStream()) { for (Map.Entry<Integer, EnumMap<Gender, ImmutableMap<String, String>>> entry : plurals.entrySet()) { writeShort(outputStream, entry.getKey() - previousResourceId); EnumMap<Gender, ImmutableMap<String, String>> genderMap = entry.getValue(); outputStream.writeByte(genderMap.size()); for (Map.Entry<Gender, ImmutableMap<String, String>> gender : genderMap.entrySet()) { outputStream.writeByte(gender.getKey().ordinal()); ImmutableMap<String, String> categoryMap = gender.getValue(); outputStream.writeByte(categoryMap.size()); for (Map.Entry<String, String> cat : categoryMap.entrySet()) { outputStream.writeByte( Objects.requireNonNull(PLURAL_CATEGORY_MAP.get(cat.getKey())).byteValue()); byte[] pluralValue = getUnescapedStringBytes(cat.getValue()); writeShort(outputStream, pluralValue.length); dataStream.write(pluralValue); } } previousResourceId = entry.getKey(); } outputStream.write(dataStream.toByteArray()); } }
Example 9
Source File: ImmutableMap.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
private static <K extends Enum<K>, V> ImmutableMap<K, V> copyOfEnumMap(EnumMap<K, ? extends V> original) { EnumMap<K, V> copy = new EnumMap<K, V>(original); for (Map.Entry<?, ?> entry : copy.entrySet()) { checkEntryNotNull(entry.getKey(), entry.getValue()); } return ImmutableEnumMap.asImmutable(copy); }
Example 10
Source File: ImmutableMap.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
private static <K extends Enum<K>, V> ImmutableMap<K, V> copyOfEnumMap( EnumMap<K, ? extends V> original) { EnumMap<K, V> copy = new EnumMap<K, V>(original); for (Map.Entry<?, ?> entry : copy.entrySet()) { checkEntryNotNull(entry.getKey(), entry.getValue()); } return ImmutableEnumMap.asImmutable(copy); }
Example 11
Source File: HFileSortedOplog.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
@Override public void close(EnumMap<Metadata, byte[]> metadata) throws IOException { if (logger.fineEnabled()) { logger.fine("Finalizing and closing writer on " + path); } if (bfw != null) { bfw.compactBloom(); writer.addGeneralBloomFilter(bfw); } // append system metadata writer.appendFileInfo(InternalMetadata.GEMFIRE_MAGIC.bytes(), MAGIC); writer.appendFileInfo(InternalMetadata.VERSION.bytes(), VERSION_1); // append comparator info // if (writer.getComparator() instanceof DelegatingSerializedComparator) { // ByteArrayOutputStream bos = new ByteArrayOutputStream(); // DataOutput out = new DataOutputStream(bos); // // writecomparatorinfo(out, ((delegatingserializedcomparator) writer.getcomparator()).getcomparators()); // writer.appendFileInfo(InternalMetadata.COMPARATORS.bytes(), bos.toByteArray()); // } // TODO write statistics data to soplog // writer.appendFileInfo(Meta.STATISTICS.toBytes(), null); // append user metadata if (metadata != null) { for (Entry<Metadata, byte[]> entry : metadata.entrySet()) { writer.appendFileInfo(entry.getKey().name().getBytes(), entry.getValue()); } } writer.close(); }
Example 12
Source File: TransactionLogHeader.java From grakn with GNU Affero General Public License v3.0 | 5 votes |
private DataOutput serializeHeader(Serializer serializer, int capacity, LogTxStatus status, EnumMap<LogTxMeta, Object> meta) { Preconditions.checkArgument(status != null && meta != null, "Invalid status or meta"); DataOutput out = serializer.getDataOutput(capacity); out.putLong(times.getTime(txTimestamp)); VariableLong.writePositive(out, transactionId); out.writeObjectNotNull(status); Preconditions.checkArgument(meta.size() < Byte.MAX_VALUE, "Too much meta data: %s", meta.size()); out.putByte(VariableLong.unsignedByte(meta.size())); for (Map.Entry<LogTxMeta, Object> metaEntry : meta.entrySet()) { out.putByte(VariableLong.unsignedByte(metaEntry.getKey().ordinal())); out.writeObjectNotNull(metaEntry.getValue()); } return out; }
Example 13
Source File: VaadinConnectTypeConversionEndpoints.java From flow with Apache License 2.0 | 5 votes |
public EnumMap<TestEnum, String> getFooEnumMap( EnumMap<TestEnum, String> value) { EnumMap<TestEnum, String> enumStringEnumMap = new EnumMap<>( TestEnum.class); for (Map.Entry<TestEnum, String> entry : value.entrySet()) { enumStringEnumMap.put(entry.getKey(), entry.getValue() + "foo"); } return enumStringEnumMap; }
Example 14
Source File: StringResources.java From buck with Apache License 2.0 | 5 votes |
/** * Writes the metadata and strings in the following format to the output stream: [Int: # of * strings] [Int: Smallest resource id among strings] [[Short: resource id delta] [Byte: #genders] * [[Byte: gender enum ordinal] [Short: length of the string] [Byte array of the string value]] x * #genders] x # of strings * * @param outputStream * @throws IOException */ private void writeStrings(DataOutputStream outputStream) throws IOException { outputStream.writeInt(strings.size()); if (strings.isEmpty()) { return; } int previousResourceId = strings.firstKey(); outputStream.writeInt(previousResourceId); try (ByteArrayOutputStream dataStream = new ByteArrayOutputStream()) { for (Map.Entry<Integer, EnumMap<Gender, String>> entry : strings.entrySet()) { writeShort(outputStream, entry.getKey() - previousResourceId); EnumMap<Gender, String> genderMap = entry.getValue(); outputStream.writeByte(genderMap.size()); for (Map.Entry<Gender, String> gender : genderMap.entrySet()) { outputStream.writeByte(gender.getKey().ordinal()); byte[] genderValue = getUnescapedStringBytes(gender.getValue()); writeShort(outputStream, genderValue.length); dataStream.write(genderValue); } previousResourceId = entry.getKey(); } outputStream.write(dataStream.toByteArray()); } }
Example 15
Source File: Puzzlers2010.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
private static void printSize2(EnumMap<Sex, Sex> map) { map.put(Sex.MALE, Sex.FEMALE); map.put(Sex.FEMALE,Sex.MALE); Set<Map.Entry<Sex, Sex>> set = new HashSet<Map.Entry<Sex, Sex>>(map.entrySet()); System.out.print(set.size() + " "); Set<Map.Entry<Sex, Sex>> set2 = new HashSet<Map.Entry<Sex, Sex>>(); set2.addAll(map.entrySet()); System.out.print(set2.size() + " "); }
Example 16
Source File: SyncChannelHolder.java From OpenModsLib with MIT License | 5 votes |
private SyncChannelHolder() { final EnumMap<Side, FMLEmbeddedChannel> channels = NetworkRegistry.INSTANCE.newChannel(CHANNEL_NAME, new InboundSyncHandler()); for (Map.Entry<Side, FMLEmbeddedChannel> e : channels.entrySet()) { final FMLEmbeddedChannel channel = e.getValue(); ExtendedOutboundHandler.install(channel); senders.put(e.getKey(), ExtPacketSenderFactory.createMultiplePlayersSender(channel)); } }
Example 17
Source File: Divider.java From Dividers with Apache License 2.0 | 4 votes |
Divider(EnumMap<Direction, Sublayer> sublayers) { for (EnumMap.Entry<Direction, Sublayer> sublayer : sublayers.entrySet()) { this.sublayers.put(sublayer.getKey(), sublayer.getValue()); } }
Example 18
Source File: HFileSortedOplog.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
@Override public void close(EnumMap<Meta, byte[]> metadata) throws IOException { if (closed.get()) { logger.finer("Writer already closed"); return; } bfw.compactBloom(); writer.addGeneralBloomFilter(bfw); // append system metadata writer.appendFileInfo(Meta.GEMFIRE_MAGIC.toBytes(), Hoplog.MAGIC); writer.appendFileInfo(Meta.SORTED_OPLOG_VERSION.toBytes(), HoplogVersion.V1.toBytes()); writer.appendFileInfo(Meta.GEMFIRE_VERSION.toBytes(), Version.CURRENT.toBytes()); // append comparator info // if (writer.getComparator() instanceof DelegatingSerializedComparator) { // ByteArrayOutputStream bos = new ByteArrayOutputStream(); // DataOutput out = new DataOutputStream(bos); // // writeComparatorInfo(out, ((DelegatingSerializedComparator) writer.getComparator()).getComparators()); // writer.appendFileInfo(Meta.COMPARATORS.toBytes(), bos.toByteArray()); // } // append user metadata HyperLogLog cachedEntryCountEstimate = null; if (metadata != null) { for (Entry<Meta, byte[]> entry : metadata.entrySet()) { writer.appendFileInfo(entry.getKey().toBytes(), entry.getValue()); if (Meta.LOCAL_CARDINALITY_ESTIMATE_V2.equals(entry.getKey())) { cachedEntryCountEstimate = HyperLogLog.Builder.build(entry.getValue()); } } } writer.close(); logger.fine("Completed closing writer"); closed.set(true); // cache estimate value to avoid reads later entryCountEstimate = cachedEntryCountEstimate; }
Example 19
Source File: HFileSortedOplog.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
@Override public void close(EnumMap<Meta, byte[]> metadata) throws IOException { if (closed.get()) { logger.finer("Writer already closed"); return; } bfw.compactBloom(); writer.addGeneralBloomFilter(bfw); // append system metadata writer.appendFileInfo(Meta.GEMFIRE_MAGIC.toBytes(), Hoplog.MAGIC); writer.appendFileInfo(Meta.SORTED_OPLOG_VERSION.toBytes(), HoplogVersion.V1.toBytes()); writer.appendFileInfo(Meta.GEMFIRE_VERSION.toBytes(), Version.CURRENT.toBytes()); // append comparator info // if (writer.getComparator() instanceof DelegatingSerializedComparator) { // ByteArrayOutputStream bos = new ByteArrayOutputStream(); // DataOutput out = new DataOutputStream(bos); // // writeComparatorInfo(out, ((DelegatingSerializedComparator) writer.getComparator()).getComparators()); // writer.appendFileInfo(Meta.COMPARATORS.toBytes(), bos.toByteArray()); // } // append user metadata HyperLogLog cachedEntryCountEstimate = null; if (metadata != null) { for (Entry<Meta, byte[]> entry : metadata.entrySet()) { writer.appendFileInfo(entry.getKey().toBytes(), entry.getValue()); if (Meta.LOCAL_CARDINALITY_ESTIMATE_V2.equals(entry.getKey())) { cachedEntryCountEstimate = HyperLogLog.Builder.build(entry.getValue()); } } } writer.close(); logger.fine("Completed closing writer"); closed.set(true); // cache estimate value to avoid reads later entryCountEstimate = cachedEntryCountEstimate; }
Example 20
Source File: SimClusterStateProvider.java From lucene-solr with Apache License 2.0 | 4 votes |
/** * Add a new replica. Note that if any details of a replica (node, coreNodeName, SolrCore name, etc) * are missing they will be filled in using the policy framework. * @param message replica details * @param results result of the operation */ @SuppressWarnings({"unchecked", "rawtypes"}) public void simAddReplica(ZkNodeProps message, NamedList results) throws Exception { if (message.getStr(CommonAdminParams.ASYNC) != null) { results.add(CoreAdminParams.REQUESTID, message.getStr(CommonAdminParams.ASYNC)); } ClusterState clusterState = getClusterState(); DocCollection coll = clusterState.getCollection(message.getStr(ZkStateReader.COLLECTION_PROP)); AtomicReference<PolicyHelper.SessionWrapper> sessionWrapper = new AtomicReference<>(); Replica.Type replicaType = Replica.Type.valueOf(message.getStr(ZkStateReader.REPLICA_TYPE, Replica.Type.NRT.name()).toUpperCase(Locale.ROOT)); EnumMap<Replica.Type, Integer> replicaTypesVsCount = new EnumMap<>(Replica.Type.class); replicaTypesVsCount.put(Replica.Type.NRT, message.getInt(NRT_REPLICAS, replicaType == Replica.Type.NRT ? 1 : 0)); replicaTypesVsCount.put(Replica.Type.TLOG, message.getInt(TLOG_REPLICAS, replicaType == Replica.Type.TLOG ? 1 : 0)); replicaTypesVsCount.put(Replica.Type.PULL, message.getInt(PULL_REPLICAS, replicaType == Replica.Type.PULL ? 1 : 0)); int totalReplicas = 0; for (Map.Entry<Replica.Type, Integer> entry : replicaTypesVsCount.entrySet()) { totalReplicas += entry.getValue(); } if (totalReplicas > 1) { if (message.getStr(CoreAdminParams.NAME) != null) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Cannot create " + totalReplicas + " replicas if 'name' parameter is specified"); } if (message.getStr(CoreAdminParams.CORE_NODE_NAME) != null) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Cannot create " + totalReplicas + " replicas if 'coreNodeName' parameter is specified"); } } List<ReplicaPosition> replicaPositions = AddReplicaCmd.buildReplicaPositions(cloudManager, clusterState, coll.getName(), message, replicaTypesVsCount, sessionWrapper); for (ReplicaPosition replicaPosition : replicaPositions) { AddReplicaCmd.CreateReplica createReplica = AddReplicaCmd.assignReplicaDetails(cloudManager, clusterState, message, replicaPosition); if (message.getStr(CoreAdminParams.CORE_NODE_NAME) == null) { createReplica.coreNodeName = Assign.assignCoreNodeName(stateManager, coll); } ReplicaInfo ri = new ReplicaInfo( createReplica.coreNodeName, createReplica.coreName, createReplica.collectionName, createReplica.sliceName, createReplica.replicaType, createReplica.node, message.getProperties() ); simAddReplica(ri.getNode(), ri, true); } if (sessionWrapper.get() != null) { sessionWrapper.get().release(); } results.add("success", ""); }