本文整理汇总了Java中java.util.Map.Entry.setValue方法的典型用法代码示例。如果您正苦于以下问题:Java Entry.setValue方法的具体用法?Java Entry.setValue怎么用?Java Entry.setValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Map.Entry
的用法示例。
在下文中一共展示了Entry.setValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadProperties
import java.util.Map.Entry; //导入方法依赖的package包/类
/**
* Loads the properties file into properties, with added functionality of
* loading the files itself for values of the properties mentioned in the file
* <p>
* i.e. if file=/home/hello.properties which contains
* key1=val1,,val2,,file::test.properties,val3
* key2=a,,b,,c,,file::test.properties and test.properties contains - x y z..
* <p>
* then effecive properties returned will be - key1=val1,,val2,,x,,y,,z,,val3
* key2=a,,b,,c,,x,,y,,z
*
* @param file
* @param fileValueIndicator
* @param valueSeparator
* @return
*/
public static Properties loadProperties(String file, String fileValueIndicator, String valueSeparator)
{
Properties props = loadFileIntoProperties(file);
Set<Entry<Object, Object>> entrySet = props.entrySet();
for (Entry<Object, Object> entry : entrySet)
{
String value = (String) entry.getValue();
if (value.contains(fileValueIndicator))
{
// the value might have multiple file urls, load each of them append,
// and remove these file urls on the go
String[] allValues = value.split(valueSeparator);
for (String each : allValues)
{
if (each.contains(fileValueIndicator))
{
String fileToBeLoaded = each.split(fileValueIndicator)[1];
String newValue = getValueListFormatted(fileToBeLoaded, valueSeparator);
entry.setValue(value.replace(each, newValue));
}
}
}
}
return props;
}
示例2: constrainedEntry
import java.util.Map.Entry; //导入方法依赖的package包/类
/**
* Returns a constrained view of the specified entry, using the specified
* constraint. The {@link Entry#setValue} operation will be verified with the
* constraint.
*
* @param entry the entry to constrain
* @param constraint the constraint for the entry
* @return a constrained view of the specified entry
*/
private static <K, V> Entry<K, V> constrainedEntry(
final Entry<K, V> entry,
final MapConstraint<? super K, ? super V> constraint) {
checkNotNull(entry);
checkNotNull(constraint);
return new ForwardingMapEntry<K, V>() {
@Override protected Entry<K, V> delegate() {
return entry;
}
@Override public V setValue(V value) {
constraint.checkKeyValue(getKey(), value);
return entry.setValue(value);
}
};
}
示例3: testEntrySetSetValueSameValue
import java.util.Map.Entry; //导入方法依赖的package包/类
public void testEntrySetSetValueSameValue() {
// TODO: Investigate the extent to which, in practice, maps that support
// put() also support Entry.setValue().
if (!supportsPut) {
return;
}
final Map<K, V> map;
try {
map = makePopulatedMap();
} catch (UnsupportedOperationException e) {
return;
}
Set<Entry<K, V>> entrySet = map.entrySet();
Entry<K, V> entry = entrySet.iterator().next();
final V oldValue = entry.getValue();
final V returnedValue = entry.setValue(oldValue);
assertEquals(oldValue, returnedValue);
assertTrue(entrySet.contains(mapEntry(entry.getKey(), oldValue)));
assertEquals(oldValue, map.get(entry.getKey()));
assertInvariants(map);
}
示例4: writeAnnotations
import java.util.Map.Entry; //导入方法依赖的package包/类
private void writeAnnotations(@Nonnull DexDataWriter writer) throws IOException {
InternalEncodedValueWriter encodedValueWriter = new InternalEncodedValueWriter(writer);
annotationSectionOffset = writer.getPosition();
for (Entry<? extends AnnotationKey, Integer> entry: annotationSection.getItems()) {
entry.setValue(writer.getPosition());
AnnotationKey key = entry.getKey();
writer.writeUbyte(annotationSection.getVisibility(key));
writer.writeUleb128(typeSection.getItemIndex(annotationSection.getType(key)));
Collection<? extends AnnotationElement> elements = Ordering.from(BaseAnnotationElement.BY_NAME)
.immutableSortedCopy(annotationSection.getElements(key));
writer.writeUleb128(elements.size());
for (AnnotationElement element: elements) {
writer.writeUleb128(stringSection.getItemIndex(annotationSection.getElementName(element)));
writeEncodedValue(encodedValueWriter, annotationSection.getElementValue(element));
}
}
}
示例5: tick
import java.util.Map.Entry; //导入方法依赖的package包/类
public void tick(double time) {
if (trainsLeaving.size() > 1) {
throw new IllegalStateException("This shouldn't be possible!");
}
for (Entry<Train, Double> trainElement : trains.entrySet()) {
Train t = trainElement.getKey();
SignalController signalController = nextBlockSignalController
.get(t.getEcu().getJourneyPlan().getJourneyPath().getTrackAfterStation(this));
if (signalController == null) {
if (t.getEcu().getJourneyPlan().getJourneyPath().getLast() != this) {
logger.error("SignallController is null (shouldn't be)");
}
continue;
}
double delay = trainElement.getValue();
if (trainsLeaving.contains(t)) {
if (t.getEngine().getObjective() != TrainObjective.PROCEED) {
t.signalChange(SignalType.GREEN);
}
continue; // ignore them, they're leaving
}
if (trainsLeaving.size() > 0) {
// if there are other trains leaving, wait for them to leave
continue;
}
if (signalController.getStatus() == GREEN) {
delay -= time;
if (delay <= 0) {
t.signalChange(SignalType.GREEN);
trainsLeaving.add(t);
}
} else {
break;
}
trainElement.setValue(delay);
break; // Only do this for one train
}
}
示例6: unwrapBsonable
import java.util.Map.Entry; //导入方法依赖的package包/类
public static Object unwrapBsonable(Object value) {
if (value instanceof Document) {
for (Entry<String, Object> entry : ((Document) value).entrySet()) {
entry.setValue(unwrapBsonable(entry.getValue()));
}
return value;
}
if (value instanceof Iterable<?>) {
return ImmutableList.copyOf(unwrapBsonableIterable((Iterable<?>) value));
}
if (value instanceof Constraints.ConstraintHost) {
return convertToBson((Constraints.ConstraintHost) value);
}
if (value == null
|| value instanceof Number
|| value instanceof Boolean
|| value instanceof String) {
return value;
}
if (value instanceof Adapted<?>) {
return ((Adapted) value).toBson();
}
return String.valueOf(value);
}
示例7: writeTypes
import java.util.Map.Entry; //导入方法依赖的package包/类
private void writeTypes(@Nonnull DexDataWriter writer) throws IOException {
typeSectionOffset = writer.getPosition();
int index = 0;
List<Entry<? extends TypeKey, Integer>> typeEntries = Lists.newArrayList(typeSection.getItems());
Collections.sort(typeEntries, toStringKeyComparator);
for (Entry<? extends TypeKey, Integer> entry : typeEntries) {
entry.setValue(index++);
writer.writeInt(stringSection.getItemIndex(typeSection.getString(entry.getKey())));
}
}
示例8: namedParameters
import java.util.Map.Entry; //导入方法依赖的package包/类
/**
* 将Map中的primitive类型数组转换为对象数组,以支持In操作
*
* @param map
* @return
*/
public static Map namedParameters(Map map) {
for (Object o : map.entrySet()) {
Entry en = (Entry) o;
en.setValue(handle(en.getValue()));
}
return map;
}
示例9: writeProtos
import java.util.Map.Entry; //导入方法依赖的package包/类
private void writeProtos(@Nonnull DexDataWriter writer) throws IOException {
protoSectionOffset = writer.getPosition();
int index = 0;
List<Entry<? extends ProtoKey, Integer>> protoEntries = Lists.newArrayList(protoSection.getItems());
Collections.sort(protoEntries, DexWriter.<ProtoKey>comparableKeyComparator());
for (Entry<? extends ProtoKey, Integer> entry: protoEntries) {
entry.setValue(index++);
ProtoKey key = entry.getKey();
writer.writeInt(stringSection.getItemIndex(protoSection.getShorty(key)));
writer.writeInt(typeSection.getItemIndex(protoSection.getReturnType(key)));
writer.writeInt(typeListSection.getNullableItemOffset(protoSection.getParameters(key)));
}
}
示例10: testFilteredValuesIllegalSetValue
import java.util.Map.Entry; //导入方法依赖的package包/类
public void testFilteredValuesIllegalSetValue() {
Map<String, Integer> unfiltered = createUnfiltered();
Map<String, Integer> filtered = Maps.filterValues(unfiltered, EVEN);
filtered.put("a", 2);
filtered.put("b", 4);
assertEquals(ImmutableMap.of("a", 2, "b", 4), filtered);
Entry<String, Integer> entry = filtered.entrySet().iterator().next();
try {
entry.setValue(5);
fail();
} catch (IllegalArgumentException expected) {}
assertEquals(ImmutableMap.of("a", 2, "b", 4), filtered);
}
示例11: testBashIt
import java.util.Map.Entry; //导入方法依赖的package包/类
public void testBashIt() throws Exception {
BiMap<Integer, Integer> bimap = HashBiMap.create(N);
BiMap<Integer, Integer> inverse = bimap.inverse();
for (int i = 0; i < N; i++) {
assertNull(bimap.put(2 * i, 2 * i + 1));
}
for (int i = 0; i < N; i++) {
assertEquals(2 * i + 1, (int) bimap.get(2 * i));
}
for (int i = 0; i < N; i++) {
assertEquals(2 * i, (int) inverse.get(2 * i + 1));
}
for (int i = 0; i < N; i++) {
int oldValue = bimap.get(2 * i);
assertEquals(2 * i + 1, (int) bimap.put(2 * i, oldValue - 2));
}
for (int i = 0; i < N; i++) {
assertEquals(2 * i - 1, (int) bimap.get(2 * i));
}
for (int i = 0; i < N; i++) {
assertEquals(2 * i, (int) inverse.get(2 * i - 1));
}
Set<Entry<Integer, Integer>> entries = bimap.entrySet();
for (Entry<Integer, Integer> entry : entries) {
entry.setValue(entry.getValue() + 2 * N);
}
for (int i = 0; i < N; i++) {
assertEquals(2 * N + 2 * i - 1, (int) bimap.get(2 * i));
}
}
示例12: testEntrySet
import java.util.Map.Entry; //导入方法依赖的package包/类
@Test public void testEntrySet()
{
_map.putAll(KEY1, Arrays.asList(VALUES));
_map.put(KEY2, VALUE2);
_map.put(KEY3, VALUE3);
Set<Entry<String, String>> set = _map.entrySet();
assertNotNull(set);
assertEquals(3, set.size());
for (Entry<String, String> e : set)
{
if (e.getKey().equals(KEY1))
{
assertEquals(VALUES[2], e.getValue());
e.setValue(VALUES[1]);
}
else if (e.getKey().equals(KEY2))
{
assertEquals(VALUE2, e.getValue());
e.setValue(VALUE3);
}
else if (e.getKey().equals(KEY3))
{
assertEquals(VALUE3, e.getValue());
e.setValue(VALUE2);
}
}
assertEquals(VALUES[1], _map.get(KEY1));
assertEquals(VALUES.length, _map.length(KEY1));
assertEquals(VALUE3, _map.get(KEY2));
assertEquals(VALUE2, _map.get(KEY3));
}
示例13: testEntrySetToArrayMutationThrows
import java.util.Map.Entry; //导入方法依赖的package包/类
public void testEntrySetToArrayMutationThrows() {
map.putInstance(String.class, "test");
@SuppressWarnings("unchecked") // Should get a CCE later if cast is wrong
Entry<Object, Object> entry = (Entry<Object, Object>) map.entrySet().toArray()[0];
assertEquals(TypeToken.of(String.class), entry.getKey());
assertEquals("test", entry.getValue());
try {
entry.setValue(1);
fail();
} catch (UnsupportedOperationException expected) {}
}
示例14: writeTypeLists
import java.util.Map.Entry; //导入方法依赖的package包/类
private void writeTypeLists(@Nonnull DexDataWriter writer) throws IOException {
writer.align();
typeListSectionOffset = writer.getPosition();
for (Entry<? extends TypeListKey, Integer> entry: typeListSection.getItems()) {
writer.align();
entry.setValue(writer.getPosition());
Collection<? extends TypeKey> types = typeListSection.getTypes(entry.getKey());
writer.writeInt(types.size());
for (TypeKey typeKey: types) {
writer.writeUshort(typeSection.getItemIndex(typeKey));
}
}
}
示例15: writeMethods
import java.util.Map.Entry; //导入方法依赖的package包/类
private void writeMethods(@Nonnull DexDataWriter writer) throws IOException {
methodSectionOffset = writer.getPosition();
int index = 0;
List<Entry<? extends MethodRefKey, Integer>> methodEntries = Lists.newArrayList(methodSection.getItems());
Collections.sort(methodEntries, DexWriter.<MethodRefKey>comparableKeyComparator());
for (Entry<? extends MethodRefKey, Integer> entry: methodEntries) {
entry.setValue(index++);
MethodRefKey key = entry.getKey();
writer.writeUshort(typeSection.getItemIndex(methodSection.getDefiningClass(key)));
writer.writeUshort(protoSection.getItemIndex(methodSection.getPrototype(key)));
writer.writeInt(stringSection.getItemIndex(methodSection.getName(key)));
}
}