當前位置: 首頁>>代碼示例>>Java>>正文


Java LongValue類代碼示例

本文整理匯總了Java中com.google.cloud.datastore.LongValue的典型用法代碼示例。如果您正苦於以下問題:Java LongValue類的具體用法?Java LongValue怎麽用?Java LongValue使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


LongValue類屬於com.google.cloud.datastore包,在下文中一共展示了LongValue類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testUnmarshalToObject_List

import com.google.cloud.datastore.LongValue; //導入依賴的package包/類
@Test
public void testUnmarshalToObject_List() {
	// Setup
	Key key = Key.newBuilder("project", "kind", 1).build();
	Entity entity = Entity.newBuilder(key)
			.set("object",
					Arrays.asList(DoubleValue.of(3.14), LongValue.of(42),
							StringValue.of("hello")))
			.set("list",
					Arrays.asList(DoubleValue.of(3.14), LongValue.of(42),
							StringValue.of("hello")))
			.set("linkedList", Arrays.asList(DoubleValue.of(3.14), LongValue.of(42),
					StringValue.of("hello")))
			.build();
	Unmarshaller unmarshaller = new Unmarshaller();
	TestBean bean = new TestBean();
	bean.linkedList = new LinkedList<Object>();

	// Exercise
	unmarshaller.unmarshalToObject(entity, bean);

	// Verify
	Assert.assertThat((List<?>) bean.object, contains(3.14, 42L, "hello"));
	Assert.assertThat(bean.list, contains(3.14, 42L, "hello"));
	Assert.assertThat(bean.linkedList, contains(3.14, 42L, "hello"));
	Assert.assertThat(bean.linkedList, instanceOf(LinkedList.class));
}
 
開發者ID:tkob,項目名稱:spring-data-gclouddatastore,代碼行數:28,代碼來源:UnmarshallerTests.java

示例2: toDatastore

import com.google.cloud.datastore.LongValue; //導入依賴的package包/類
@Override
public ValueBuilder<?, ?, ?> toDatastore(Object input) {
  if (input == null) {
    return NullValue.newBuilder();
  }
  return LongValue.newBuilder((int) input);
}
 
開發者ID:sai-pullabhotla,項目名稱:catatumbo,代碼行數:8,代碼來源:IntegerMapper.java

示例3: toModel

import com.google.cloud.datastore.LongValue; //導入依賴的package包/類
@Override
public Object toModel(Value<?> input) {
  if (input instanceof NullValue) {
    return null;
  }
  Long l = ((LongValue) input).get();
  if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) {
    throw new MappingException(String.format("Value %d is out of range for integer type", l));
  }
  return l.intValue();
}
 
開發者ID:sai-pullabhotla,項目名稱:catatumbo,代碼行數:12,代碼來源:IntegerMapper.java

示例4: toDatastore

import com.google.cloud.datastore.LongValue; //導入依賴的package包/類
@Override
public ValueBuilder<?, ?, ?> toDatastore(Object input) {
  if (input == null) {
    return NullValue.newBuilder();
  }
  return LongValue.newBuilder((short) input);
}
 
開發者ID:sai-pullabhotla,項目名稱:catatumbo,代碼行數:8,代碼來源:ShortMapper.java

示例5: toModel

import com.google.cloud.datastore.LongValue; //導入依賴的package包/類
@Override
public Object toModel(Value<?> input) {
  if (input instanceof NullValue) {
    return null;
  }
  Long l = ((LongValue) input).get();
  if (l < Short.MIN_VALUE || l > Short.MAX_VALUE) {
    throw new MappingException(String.format("Value %d is out of range for short type", l));
  }
  return l.shortValue();
}
 
開發者ID:sai-pullabhotla,項目名稱:catatumbo,代碼行數:12,代碼來源:ShortMapper.java

示例6: toDatastore

import com.google.cloud.datastore.LongValue; //導入依賴的package包/類
@Override
public ValueBuilder<?, ?, ?> toDatastore(Object input) {
  ValueBuilder<?, ?, ?> builder;
  if (input == null) {
    builder = NullValue.newBuilder();
  } else if (input instanceof Long) {
    builder = LongValue.newBuilder((long) input);
  } else if (input instanceof Double) {
    builder = DoubleValue.newBuilder((double) input);
  } else if (input instanceof Boolean) {
    builder = BooleanValue.newBuilder((boolean) input);
  } else if (input instanceof String) {
    builder = StringValue.newBuilder((String) input);
  } else if (input instanceof DatastoreKey) {
    builder = KeyValue.newBuilder(((DatastoreKey) input).nativeKey());
  } else if (input instanceof GeoLocation) {
    GeoLocation geoLocation = (GeoLocation) input;
    builder = LatLngValue
        .newBuilder(LatLng.of(geoLocation.getLatitude(), geoLocation.getLongitude()));
  } else if (input instanceof Map) {
    @SuppressWarnings("unchecked")
    Map<String, ?> map = (Map<String, ?>) input;
    FullEntity.Builder<IncompleteKey> entityBuilder = FullEntity.newBuilder();
    for (Map.Entry<String, ?> entry : map.entrySet()) {
      String key = entry.getKey();
      entityBuilder.set(key, toDatastore(entry.getValue()).build());
    }
    builder = EntityValue.newBuilder(entityBuilder.build());
  } else {
    throw new MappingException(String.format("Unsupported type: %s", input.getClass().getName()));
  }
  return builder;
}
 
開發者ID:sai-pullabhotla,項目名稱:catatumbo,代碼行數:34,代碼來源:CatchAllMapper.java

示例7: toModel

import com.google.cloud.datastore.LongValue; //導入依賴的package包/類
@Override
public Object toModel(Value<?> input) {
  Object javaValue;
  if (input instanceof NullValue) {
    javaValue = null;
  } else if (input instanceof StringValue) {
    javaValue = input.get();
  } else if (input instanceof LongValue) {
    javaValue = input.get();
  } else if (input instanceof DoubleValue) {
    javaValue = input.get();
  } else if (input instanceof BooleanValue) {
    javaValue = input.get();
  } else if (input instanceof KeyValue) {
    javaValue = new DefaultDatastoreKey(((KeyValue) input).get());
  } else if (input instanceof LatLngValue) {
    LatLng latLong = ((LatLngValue) input).get();
    javaValue = new GeoLocation(latLong.getLatitude(), latLong.getLongitude());
  } else if (input instanceof EntityValue) {
    EntityValue entityValue = (EntityValue) input;
    FullEntity<?> entity = entityValue.get();
    Map<String, Object> map = new HashMap<>();
    for (String property : entity.getNames()) {
      map.put(property, toModel(entity.getValue(property)));
    }
    javaValue = map;
  } else {
    throw new MappingException(String.format("Unsupported type %s", input.getClass().getName()));
  }
  return javaValue;
}
 
開發者ID:sai-pullabhotla,項目名稱:catatumbo,代碼行數:32,代碼來源:CatchAllMapper.java

示例8: toDatastore

import com.google.cloud.datastore.LongValue; //導入依賴的package包/類
@Override
public ValueBuilder<?, ?, ?> toDatastore(Object input) {
  if (input == null) {
    return NullValue.newBuilder();
  }
  return LongValue.newBuilder((long) input);
}
 
開發者ID:sai-pullabhotla,項目名稱:catatumbo,代碼行數:8,代碼來源:LongMapper.java

示例9: toModel

import com.google.cloud.datastore.LongValue; //導入依賴的package包/類
@Override
public Object toModel(Value<?> input) {
  if (input instanceof NullValue) {
    return null;
  }
  return ((LongValue) input).get();
}
 
開發者ID:sai-pullabhotla,項目名稱:catatumbo,代碼行數:8,代碼來源:LongMapper.java

示例10: testIndex_3

import com.google.cloud.datastore.LongValue; //導入依賴的package包/類
@Test(expected = IndexingException.class)
public void testIndex_3() {
  LongValue input = LongValue.of(5L);
  try {
    Value<?> output = indexer.index(input);
  } catch (Exception exp) {
    LOGGER.log(Level.INFO, exp.toString());
    throw exp;
  }
}
 
開發者ID:sai-pullabhotla,項目名稱:catatumbo,代碼行數:11,代碼來源:LowerCaseStringIndexerTest.java

示例11: testIndex_5

import com.google.cloud.datastore.LongValue; //導入依賴的package包/類
@Test(expected = IndexingException.class)
public void testIndex_5() {
  Value<?>[] inputArray = { StringValue.of("Hello"), NullValue.of(), LongValue.of(5L) };
  ListValue input = ListValue.of(Arrays.asList(inputArray));
  try {
    ListValue output = (ListValue) indexer.index(input);
  } catch (Exception exp) {
    LOGGER.log(Level.INFO, exp.toString());
    throw exp;
  }
}
 
開發者ID:sai-pullabhotla,項目名稱:catatumbo,代碼行數:12,代碼來源:UpperCaseStringListIndexerTest.java

示例12: toDatastore

import com.google.cloud.datastore.LongValue; //導入依賴的package包/類
@Override
public ValueBuilder<?, ?, ?> toDatastore(Object input) {
  if (input == null) {
    return NullValue.newBuilder();
  }
  return LongValue.newBuilder((byte) input);
}
 
開發者ID:sai-pullabhotla,項目名稱:catatumbo,代碼行數:8,代碼來源:ByteMapper.java

示例13: toModel

import com.google.cloud.datastore.LongValue; //導入依賴的package包/類
@Override
public Object toModel(Value<?> input) {
  if (input instanceof NullValue) {
    return null;
  }
  Long l = ((LongValue) input).get();
  if (l < Byte.MIN_VALUE || l > Byte.MAX_VALUE) {
    throw new MappingException(String.format("Value %d is out of range for byte type", l));
  }
  return l.byteValue();
}
 
開發者ID:sai-pullabhotla,項目名稱:catatumbo,代碼行數:12,代碼來源:ByteMapper.java

示例14: toDatastore

import com.google.cloud.datastore.LongValue; //導入依賴的package包/類
@Override
public ValueBuilder<?, ?, ?> toDatastore(Object input) {
  if (input == null) {
    return NullValue.newBuilder();
  }
  try {
    BigDecimal n = (BigDecimal) input;
    n = n.movePointRight(fractionalDigits);
    return LongValue.newBuilder(n.longValueExact());
  } catch (Exception e) {
    throw new MappingException(e);
  }
}
 
開發者ID:sai-pullabhotla,項目名稱:catatumbo,代碼行數:14,代碼來源:CurrencyMapper.java

示例15: toModel

import com.google.cloud.datastore.LongValue; //導入依賴的package包/類
@Override
public Object toModel(Value<?> input) {
  if (input instanceof NullValue) {
    return null;
  }
  BigDecimal n = new BigDecimal(((LongValue) input).get());
  n = n.movePointLeft(fractionalDigits);
  return n;
}
 
開發者ID:sai-pullabhotla,項目名稱:catatumbo,代碼行數:10,代碼來源:CurrencyMapper.java


注:本文中的com.google.cloud.datastore.LongValue類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。