本文整理匯總了Java中com.google.common.primitives.Shorts類的典型用法代碼示例。如果您正苦於以下問題:Java Shorts類的具體用法?Java Shorts怎麽用?Java Shorts使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Shorts類屬於com.google.common.primitives包,在下文中一共展示了Shorts類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: toArray
import com.google.common.primitives.Shorts; //導入依賴的package包/類
@SuppressWarnings({"unchecked", "rawtypes"}) // NOTE: We assume the component type matches the list
private Object toArray(Class<?> componentType, List<Object> values) {
if (componentType == boolean.class) {
return Booleans.toArray((Collection) values);
} else if (componentType == byte.class) {
return Bytes.toArray((Collection) values);
} else if (componentType == short.class) {
return Shorts.toArray((Collection) values);
} else if (componentType == int.class) {
return Ints.toArray((Collection) values);
} else if (componentType == long.class) {
return Longs.toArray((Collection) values);
} else if (componentType == float.class) {
return Floats.toArray((Collection) values);
} else if (componentType == double.class) {
return Doubles.toArray((Collection) values);
} else if (componentType == char.class) {
return Chars.toArray((Collection) values);
}
return values.toArray((Object[]) Array.newInstance(componentType, values.size()));
}
示例2: if
import com.google.common.primitives.Shorts; //導入依賴的package包/類
public static CacheDirectiveInfo convert
(CacheDirectiveInfoProto proto) {
CacheDirectiveInfo.Builder builder =
new CacheDirectiveInfo.Builder();
if (proto.hasId()) {
builder.setId(proto.getId());
}
if (proto.hasPath()) {
builder.setPath(new Path(proto.getPath()));
}
if (proto.hasReplication()) {
builder.setReplication(Shorts.checkedCast(
proto.getReplication()));
}
if (proto.hasPool()) {
builder.setPool(proto.getPool());
}
if (proto.hasExpiration()) {
builder.setExpiration(convert(proto.getExpiration()));
}
return builder.build();
}
示例3: convert
import com.google.common.primitives.Shorts; //導入依賴的package包/類
public static CacheDirectiveInfo convert(CacheDirectiveInfoProto proto) {
CacheDirectiveInfo.Builder builder = new CacheDirectiveInfo.Builder();
if (proto.hasId()) {
builder.setId(proto.getId());
}
if (proto.hasPath()) {
builder.setPath(new Path(proto.getPath()));
}
if (proto.hasReplication()) {
builder.setReplication(Shorts.checkedCast(
proto.getReplication()));
}
if (proto.hasPool()) {
builder.setPool(proto.getPool());
}
if (proto.hasExpiration()) {
builder.setExpiration(convert(proto.getExpiration()));
}
return builder.build();
}
示例4: AmplitudeData
import com.google.common.primitives.Shorts; //導入依賴的package包/類
public AmplitudeData(byte[] rawData) {
if (rawData == null) {
amplitude = 0;
return;
}
int step = rawData.length / Shorts.BYTES / sampleCount;
int count = 0;
double sum = 0;
for (int i = 0;
i < rawData.length - Shorts.BYTES;
i += step) {
byte[] bytes = new byte[Shorts.BYTES];
for (int j = 0;
j < Shorts.BYTES;
j++) {
bytes[j] = rawData[i + j];
}
short s = Shorts.fromByteArray(bytes);
sum += s * s;
count++;
}
amplitude = (int) Math.sqrt(sum / count);
}
示例5: writeImageBW
import com.google.common.primitives.Shorts; //導入依賴的package包/類
/**
* @param fileName
* @param pixelLums
* @param width
* @param height
* @param normalize
*/
public static void writeImageBW(final String fileName, final short[] pixelLums, final int width, final int height,
final boolean normalize) {
final float maxValue = normalize ? Shorts.max(pixelLums) : 255f;
LOG.log(Level.INFO, "Writing to {0} with max pixel lum of {1} normalise:{2}", new Object[] { fileName, Shorts.max(
pixelLums), normalize });
final BufferedImage result = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY);
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
result.setRGB(x, y, Color.HSBtoRGB(0, 0, Math.min(1f, pixelLums[y * width + x] / maxValue)));
}
}
try {
ImageIO.write(result, "png", new File(fileName + ".png"));
} catch (IOException ex) {
LOG.log(Level.SEVERE, null, ex);
}
}
示例6: toGlobalAfiSafiAddPath
import com.google.common.primitives.Shorts; //導入依賴的package包/類
static AfiSafi toGlobalAfiSafiAddPath(final AfiSafi afiSafi, final BgpTableType tableType,
final Map<TablesKey, PathSelectionMode> multiPathTables) {
final PathSelectionMode pathSelection = multiPathTables.get(new TablesKey(tableType.getAfi(), tableType.getSafi()));
if (pathSelection == null) {
return afiSafi;
}
final long maxPaths;
if (pathSelection instanceof AddPathBestNPathSelection) {
maxPaths = ((AddPathBestNPathSelection) pathSelection).getNBestPaths();
} else {
maxPaths = 0L;
}
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev171207.AfiSafi2 addPath = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev171207.AfiSafi2Builder()
.setReceive(true)
.setSendMax(Shorts.checkedCast(maxPaths))
.build();
return new AfiSafiBuilder(afiSafi)
.addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev171207.AfiSafi2.class,
addPath).build();
}
示例7: toGlobalAfiSafiAddPath
import com.google.common.primitives.Shorts; //導入依賴的package包/類
@Test
public void toGlobalAfiSafiAddPath() {
final AfiSafi afiSafi = OpenConfigMappingUtil.toGlobalAfiSafiAddPath(AFISAFI_IPV4, BGP_TABLE_TYPE_IPV4, Collections.emptyMap());
Assert.assertEquals(AFISAFI_IPV4, afiSafi);
final AfiSafi afiSafiResult = OpenConfigMappingUtil.toGlobalAfiSafiAddPath(AFISAFI_IPV4, BGP_TABLE_TYPE_IPV4, Collections.singletonMap(K4,
ADD_PATH_BEST_N_PATH_SELECTION));
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev171207.AfiSafi2 addPath =
new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev171207.AfiSafi2Builder()
.setSendMax(Shorts.checkedCast(N_PATHS)).setReceive(true).build();
final AfiSafi afisafiIpv4Psm2 = new AfiSafiBuilder(afiSafi)
.addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev171207.AfiSafi2.class,
addPath).build();
Assert.assertEquals(afisafiIpv4Psm2, afiSafiResult);
final AfiSafi afiSafiAllResult = OpenConfigMappingUtil.toGlobalAfiSafiAddPath(AFISAFI_IPV4, BGP_TABLE_TYPE_IPV4,
Collections.singletonMap(K4, ADD_PATH_BEST_ALL_PATH_SELECTION));
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev171207.AfiSafi2 addPathAll =
new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev171207.AfiSafi2Builder()
.setSendMax(Shorts.checkedCast(ALL_PATHS)).setReceive(true).build();
final AfiSafi afiAll = new AfiSafiBuilder(afiSafi)
.addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev171207.AfiSafi2.class,
addPathAll).build();
Assert.assertEquals(afiAll, afiSafiAllResult);
}
示例8: toAddPathCapability
import com.google.common.primitives.Shorts; //導入依賴的package包/類
@Test
public void toAddPathCapability() {
final List<AfiSafi> families = new ArrayList<>();
families.add(new AfiSafiBuilder().setAfiSafiName(IPV4UNICAST.class)
.addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev171207.AfiSafi1.class,
new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev171207.AfiSafi1Builder()
.setReceive(true).setSendMax(Shorts.checkedCast(ALL_PATHS)).build()).build());
families.add(new AfiSafiBuilder().setAfiSafiName(IPV6UNICAST.class)
.addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev171207.AfiSafi1.class,
new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev171207.AfiSafi1Builder()
.setReceive(false).setSendMax(Shorts.checkedCast(N_PATHS)).build()).build());
families.add(new AfiSafiBuilder().setAfiSafiName(IPV6LABELLEDUNICAST.class)
.addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev171207.AfiSafi1.class,
new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev171207.AfiSafi1Builder()
.setReceive(false).build()).build());
final List<AddressFamilies> result = OpenConfigMappingUtil.toAddPathCapability(families, this.tableTypeRegistry);
assertEquals(FAMILIES, result);
}
示例9: fromBgpPeer
import com.google.common.primitives.Shorts; //導入依賴的package包/類
@Test
public void fromBgpPeer() {
final Neighbor result = OpenConfigMappingUtil.fromBgpPeer(FAMILIES, TABLE_TYPES, 30, NEIGHBOR_ADDRESS, true, null, PORT_NUMBER, 30, AS, PeerRole.Ibgp, null, this.tableTypeRegistry);
final List<AfiSafi> afisafis = new ArrayList<>();
afisafis.add(new AfiSafiBuilder().setAfiSafiName(IPV4UNICAST.class)
.addAugmentation(AfiSafi1.class, new AfiSafi1Builder().setReceive(true).setSendMax(Shorts.checkedCast(ALL_PATHS)).build()).build());
afisafis.add(new AfiSafiBuilder().setAfiSafiName(IPV6UNICAST.class)
.addAugmentation(AfiSafi1.class, new AfiSafi1Builder().setReceive(false).setSendMax(Shorts.checkedCast(ALL_PATHS)).build()).build());
final Neighbor expected = new NeighborBuilder()
.setAfiSafis(new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.AfiSafisBuilder().setAfiSafi(afisafis).build())
.setConfig(new ConfigBuilder().setPeerAs(AS).setPeerType(PeerType.INTERNAL).setRouteFlapDamping(false).setSendCommunity(CommunityType.NONE).build())
.setNeighborAddress(NEIGHBOR_ADDRESS)
.setRouteReflector(new RouteReflectorBuilder().setConfig(new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp
.neighbor.group.route.reflector.ConfigBuilder().setRouteReflectorClient(false).build()).build())
.setTimers(new TimersBuilder().setConfig(new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group
.timers.ConfigBuilder().setHoldTime(DEFAULT_TIMERS).setMinimumAdvertisementInterval(DEFAULT_TIMERS)
.setKeepaliveInterval(DEFAULT_TIMERS).setConnectRetry(DEFAULT_TIMERS).build()).build())
.setTransport(new TransportBuilder().setConfig(new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor
.group.transport.ConfigBuilder().setMtuDiscovery(false).setPassiveMode(false).addAugmentation(Config1.class, new Config1Builder()
.setRemotePort(new PortNumber(179)).build()).build()).build())
.build();
assertEquals(expected, result);
}
示例10: getMapShortList
import com.google.common.primitives.Shorts; //導入依賴的package包/類
public Map<Short, List<Short>> getMapShortList()
{
if (mapShortArray == null) {
return null;
}
return Maps.transformValues(mapShortArray, Shorts::asList);
}
示例11: indexOf
import com.google.common.primitives.Shorts; //導入依賴的package包/類
/**
* {@inheritDoc}
*
* @throws NullPointerException
* if the wrapped array was <code>null</code>.
*/
@Override
public int indexOf(Object o) {
// Will make the method fail if array is null.
if (size() < 1) {
return -1;
}
if (o instanceof Short) {
return Shorts.indexOf(array, ((Short) o).shortValue());
}
return -1;
}
示例12: lastIndexOf
import com.google.common.primitives.Shorts; //導入依賴的package包/類
/**
* {@inheritDoc}
*
* @throws NullPointerException
* if the wrapped array was <code>null</code>.
*/
@Override
public int lastIndexOf(Object o) {
// Will make the method fail if array is null.
if (size() < 1) {
return -1;
}
if (o instanceof Short) {
return Shorts.lastIndexOf(array, ((Short) o).shortValue());
}
return -1;
}
示例13: contains
import com.google.common.primitives.Shorts; //導入依賴的package包/類
/**
* {@inheritDoc}
*
* @throws NullPointerException
* if the wrapped array was <code>null</code>.
*/
@Override
public boolean contains(Object o) {
// Will make the method fail if array is null.
if (size() < 1) {
return false;
}
if (o instanceof Short) {
return Shorts.contains(array, ((Short) o).shortValue());
}
return false;
}
示例14: testReadAddresses_ip4
import com.google.common.primitives.Shorts; //導入依賴的package包/類
@Test
public void testReadAddresses_ip4() throws IOException {
AddressFamily addressFamily = AddressFamily.AF_INET;
TransportProtocol transportProtocol = TransportProtocol.STREAM;
Command command = Command.PROXY;
int ipSize = addressFamily.getAddressSize();
int portSize = 2;
byte[] srcAddress = InetAddress.getByName("1.2.3.4").getAddress();
byte[] dstAddress = InetAddress.getByName("5.6.7.8").getAddress();
short srcPort = 501;
short dstPort = 601;
byte[] stream = Bytes.concat(srcAddress, dstAddress,
Shorts.toByteArray(srcPort), Shorts.toByteArray(dstPort));
assertEquals(ipSize * 2 + portSize * 2, stream.length);
Parser parser = newParser(stream);
Header header = new Header();
header.setCommand(command);
header.setAddressFamily(addressFamily);
header.setTransportProtocol(transportProtocol);
parser.readAddresses(header);
assertArrayEquals(srcAddress, header.getSrcAddress());
assertArrayEquals(dstAddress, header.getDstAddress());
assertEquals(srcPort, header.getSrcPort());
assertEquals(dstPort, header.getDstPort());
}
示例15: testReadAddresses_ip6
import com.google.common.primitives.Shorts; //導入依賴的package包/類
@Test
public void testReadAddresses_ip6() throws IOException {
AddressFamily addressFamily = AddressFamily.AF_INET6;
TransportProtocol transportProtocol = TransportProtocol.STREAM;
Command command = Command.PROXY;
int ipSize = addressFamily.getAddressSize();
int portSize = 2;
byte[] srcAddress = InetAddress.getByName("1:2:3:4:5:6:7:8").getAddress();
byte[] dstAddress = InetAddress.getByName("9:A:B:C:D:E:F:1").getAddress();
short srcPort = 501;
short dstPort = 601;
assertEquals(ipSize, srcAddress.length);
assertEquals(ipSize, dstAddress.length);
byte[] stream = Bytes.concat(srcAddress, dstAddress,
Shorts.toByteArray(srcPort), Shorts.toByteArray(dstPort));
assertEquals(ipSize * 2 + portSize * 2, stream.length);
Parser parser = newParser(stream);
Header header = new Header();
header.setCommand(command);
header.setAddressFamily(addressFamily);
header.setTransportProtocol(transportProtocol);
parser.readAddresses(header);
assertArrayEquals(srcAddress, header.getSrcAddress());
assertArrayEquals(dstAddress, header.getDstAddress());
assertEquals(srcPort, header.getSrcPort());
assertEquals(dstPort, header.getDstPort());
}