当前位置: 首页>>代码示例>>Java>>正文


Java Shorts类代码示例

本文整理汇总了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()));
}
 
开发者ID:TNG,项目名称:ArchUnit,代码行数:22,代码来源:JavaClassProcessor.java

示例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();
}
 
开发者ID:naver,项目名称:hadoop,代码行数:23,代码来源:PBHelper.java

示例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();
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:21,代码来源:PBHelperClient.java

示例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);
}
 
开发者ID:bither,项目名称:bither-android,代码行数:26,代码来源:AmplitudeData.java

示例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);
	}
}
 
开发者ID:salamanders,项目名称:virtual-star-tracker,代码行数:27,代码来源:ImageUtils.java

示例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();
}
 
开发者ID:opendaylight,项目名称:bgpcep,代码行数:21,代码来源:OpenConfigMappingUtil.java

示例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);
}
 
开发者ID:opendaylight,项目名称:bgpcep,代码行数:26,代码来源:OpenConfigMappingUtilTest.java

示例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);
}
 
开发者ID:opendaylight,项目名称:bgpcep,代码行数:19,代码来源:OpenConfigMappingUtilTest.java

示例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);
}
 
开发者ID:opendaylight,项目名称:bgpcep,代码行数:24,代码来源:OpenConfigMappingUtilTest.java

示例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);
}
 
开发者ID:airlift,项目名称:drift,代码行数:8,代码来源:ArrayField.java

示例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;
}
 
开发者ID:eclipse,项目名称:xtext-lib,代码行数:18,代码来源:Conversions.java

示例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;
}
 
开发者ID:eclipse,项目名称:xtext-lib,代码行数:18,代码来源:Conversions.java

示例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;
}
 
开发者ID:eclipse,项目名称:xtext-lib,代码行数:18,代码来源:Conversions.java

示例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());
}
 
开发者ID:aws,项目名称:elastic-load-balancing-tools,代码行数:30,代码来源:ParserTest.java

示例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());
}
 
开发者ID:aws,项目名称:elastic-load-balancing-tools,代码行数:33,代码来源:ParserTest.java


注:本文中的com.google.common.primitives.Shorts类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。