target
stringlengths 20
113k
| src_fm
stringlengths 11
86.3k
| src_fm_fc
stringlengths 21
86.4k
| src_fm_fc_co
stringlengths 30
86.4k
| src_fm_fc_ms
stringlengths 42
86.8k
| src_fm_fc_ms_ff
stringlengths 43
86.8k
|
---|---|---|---|---|---|
@Test public void testFindPattern() { AbstractMemory sut = new MockMemory(ByteOrder.BIG_ENDIAN); sut.addMemorySource(new MockMemorySource(new byte[] { 0x0 }, 0, 0, 100)); sut .addMemorySource(new MockMemorySource(new byte[] { 0xA }, 0, 100, 100)); sut .addMemorySource(new MockMemorySource(new byte[] { 0xB }, 0, 200, 100)); sut .addMemorySource(new MockMemorySource(new byte[] { 0xD }, 0, 400, 100)); byte[] patternBuffer = new byte[100]; patternBuffer[66] = 0xD; patternBuffer[67] = 0xE; patternBuffer[68] = 0xA; patternBuffer[69] = 0xD; patternBuffer[70] = 0xB; patternBuffer[71] = 0xE; patternBuffer[72] = 0xE; patternBuffer[73] = 0xF; sut.addMemorySource(new BufferMemorySource(0, 500, patternBuffer)); sut .addMemorySource(new MockMemorySource(new byte[] { 0xD }, 0, 600, 100)); sut .addMemorySource(new MockMemorySource(new byte[] { 0xD }, 0, 700, 100)); sut .addMemorySource(new MockMemorySource(new byte[] { 0xD }, 0, 900, 100)); sut .addMemorySource(new MockMemorySource(new byte[] { 0xD }, 0, 1000, 100)); long address = sut.findPattern(new byte[] { 0xD, 0xE, 0xA, 0xD, 0xB, 0xE, 0xE, 0xF }, 1, 0); assertEquals(566, address); assertEquals(-1, sut.findPattern(new byte[] { 0xD, 0xE, 0xA, 0xD, 0xB, 0xE, 0xE, 0xF }, 1, 580)); assertEquals(-1, sut.findPattern(new byte[] { 0xD, 0xE, 0xA, 0xD, 0xB, 0xE, 0xE, 0xF }, 8, 0)); } | public void addMemorySource(IMemorySource source) { logger.logp(FINEST,"AbstractMemory","addMemorySource","Added memory range {0}-{1}",new Object[]{Long.toHexString(source.getBaseAddress()), Long.toHexString(source.getTopAddress()) }); if (GLOBAL_CACHE_ENABLED) { IMemorySource wrappedSource = new CachingMemorySource(source); decoratorMappingTable.put(source, wrappedSource); memorySources.addMemorySource(wrappedSource); } else { if (RECORDING_CACHE_STATS) { IMemorySource wrappedSource = new CountingMemorySource(source); decoratorMappingTable.put(source, wrappedSource); memorySources.addMemorySource(wrappedSource); } else { memorySources.addMemorySource(source); } } rangeTable = null; } | AbstractMemory extends SearchableMemory implements IMemory { public void addMemorySource(IMemorySource source) { logger.logp(FINEST,"AbstractMemory","addMemorySource","Added memory range {0}-{1}",new Object[]{Long.toHexString(source.getBaseAddress()), Long.toHexString(source.getTopAddress()) }); if (GLOBAL_CACHE_ENABLED) { IMemorySource wrappedSource = new CachingMemorySource(source); decoratorMappingTable.put(source, wrappedSource); memorySources.addMemorySource(wrappedSource); } else { if (RECORDING_CACHE_STATS) { IMemorySource wrappedSource = new CountingMemorySource(source); decoratorMappingTable.put(source, wrappedSource); memorySources.addMemorySource(wrappedSource); } else { memorySources.addMemorySource(source); } } rangeTable = null; } } | AbstractMemory extends SearchableMemory implements IMemory { public void addMemorySource(IMemorySource source) { logger.logp(FINEST,"AbstractMemory","addMemorySource","Added memory range {0}-{1}",new Object[]{Long.toHexString(source.getBaseAddress()), Long.toHexString(source.getTopAddress()) }); if (GLOBAL_CACHE_ENABLED) { IMemorySource wrappedSource = new CachingMemorySource(source); decoratorMappingTable.put(source, wrappedSource); memorySources.addMemorySource(wrappedSource); } else { if (RECORDING_CACHE_STATS) { IMemorySource wrappedSource = new CountingMemorySource(source); decoratorMappingTable.put(source, wrappedSource); memorySources.addMemorySource(wrappedSource); } else { memorySources.addMemorySource(source); } } rangeTable = null; } protected AbstractMemory(ByteOrder byteOrder); } | AbstractMemory extends SearchableMemory implements IMemory { public void addMemorySource(IMemorySource source) { logger.logp(FINEST,"AbstractMemory","addMemorySource","Added memory range {0}-{1}",new Object[]{Long.toHexString(source.getBaseAddress()), Long.toHexString(source.getTopAddress()) }); if (GLOBAL_CACHE_ENABLED) { IMemorySource wrappedSource = new CachingMemorySource(source); decoratorMappingTable.put(source, wrappedSource); memorySources.addMemorySource(wrappedSource); } else { if (RECORDING_CACHE_STATS) { IMemorySource wrappedSource = new CountingMemorySource(source); decoratorMappingTable.put(source, wrappedSource); memorySources.addMemorySource(wrappedSource); } else { memorySources.addMemorySource(source); } } rangeTable = null; } protected AbstractMemory(ByteOrder byteOrder); byte getByteAt(long address); int getBytesAt(long address, byte[] buffer); int getBytesAt(final long address, byte[] buffer, final int offset,final int length); int getIntAt(long address); long getLongAt(long address); short getShortAt(long address); void addMemorySource(IMemorySource source); void removeMemorySource(IMemorySource source); void addMemorySources(Collection<? extends IMemorySource> memorySources); List<IMemoryRange> getMemoryRanges(); ByteOrder getByteOrder(); boolean isShared(long address); boolean isExecutable(long address); boolean isReadOnly(long address); Properties getProperties(long address); } | AbstractMemory extends SearchableMemory implements IMemory { public void addMemorySource(IMemorySource source) { logger.logp(FINEST,"AbstractMemory","addMemorySource","Added memory range {0}-{1}",new Object[]{Long.toHexString(source.getBaseAddress()), Long.toHexString(source.getTopAddress()) }); if (GLOBAL_CACHE_ENABLED) { IMemorySource wrappedSource = new CachingMemorySource(source); decoratorMappingTable.put(source, wrappedSource); memorySources.addMemorySource(wrappedSource); } else { if (RECORDING_CACHE_STATS) { IMemorySource wrappedSource = new CountingMemorySource(source); decoratorMappingTable.put(source, wrappedSource); memorySources.addMemorySource(wrappedSource); } else { memorySources.addMemorySource(source); } } rangeTable = null; } protected AbstractMemory(ByteOrder byteOrder); byte getByteAt(long address); int getBytesAt(long address, byte[] buffer); int getBytesAt(final long address, byte[] buffer, final int offset,final int length); int getIntAt(long address); long getLongAt(long address); short getShortAt(long address); void addMemorySource(IMemorySource source); void removeMemorySource(IMemorySource source); void addMemorySources(Collection<? extends IMemorySource> memorySources); List<IMemoryRange> getMemoryRanges(); ByteOrder getByteOrder(); boolean isShared(long address); boolean isExecutable(long address); boolean isReadOnly(long address); Properties getProperties(long address); } |
@Test public void testGetStreamPosition() throws Exception { AbstractMemory memory = new MockMemory(ByteOrder.BIG_ENDIAN); memory.addMemorySource(new MockMemorySource(new byte[] { (byte)0xA0}, 0, 0x10000, 0x10000)); memory.addMemorySource(new MockMemorySource(new byte[] { (byte)0xB0}, 0, 0x20000, 0x10000)); IMemoryImageInputStream sut = new IMemoryImageInputStream(memory, 0x10000); long pos = sut.getStreamPosition(); assertEquals(0xA0,sut.read()); assertEquals(0xA0,sut.read()); assertEquals(pos + 2,sut.getStreamPosition()); } | @Override public long getStreamPosition() throws IOException { return address; } | IMemoryImageInputStream extends ImageInputStreamImpl { @Override public long getStreamPosition() throws IOException { return address; } } | IMemoryImageInputStream extends ImageInputStreamImpl { @Override public long getStreamPosition() throws IOException { return address; } IMemoryImageInputStream(IMemory memory, long startingAddress); } | IMemoryImageInputStream extends ImageInputStreamImpl { @Override public long getStreamPosition() throws IOException { return address; } IMemoryImageInputStream(IMemory memory, long startingAddress); @Override int read(byte[] buffer, int offset, int length); @Override int read(); @Override long getStreamPosition(); @Override void seek(long pos); } | IMemoryImageInputStream extends ImageInputStreamImpl { @Override public long getStreamPosition() throws IOException { return address; } IMemoryImageInputStream(IMemory memory, long startingAddress); @Override int read(byte[] buffer, int offset, int length); @Override int read(); @Override long getStreamPosition(); @Override void seek(long pos); } |
@Test public void testSeek() throws Exception { AbstractMemory memory = new MockMemory(ByteOrder.BIG_ENDIAN); memory.addMemorySource(new MockMemorySource(new byte[] { (byte)0xA0}, 0, 0x10000, 0x10000)); memory.addMemorySource(new MockMemorySource(new byte[] { (byte)0xB0}, 0, 0x20000, 0x10000)); IMemoryImageInputStream sut = new IMemoryImageInputStream(memory, 0x10000); assertEquals(0x10000,sut.getStreamPosition()); assertEquals(0xA0,sut.read()); sut.seek(0x20000); assertEquals(0x20000,sut.getStreamPosition()); assertEquals(0xB0,sut.read()); } | @Override public void seek(long pos) throws IOException { address = pos; } | IMemoryImageInputStream extends ImageInputStreamImpl { @Override public void seek(long pos) throws IOException { address = pos; } } | IMemoryImageInputStream extends ImageInputStreamImpl { @Override public void seek(long pos) throws IOException { address = pos; } IMemoryImageInputStream(IMemory memory, long startingAddress); } | IMemoryImageInputStream extends ImageInputStreamImpl { @Override public void seek(long pos) throws IOException { address = pos; } IMemoryImageInputStream(IMemory memory, long startingAddress); @Override int read(byte[] buffer, int offset, int length); @Override int read(); @Override long getStreamPosition(); @Override void seek(long pos); } | IMemoryImageInputStream extends ImageInputStreamImpl { @Override public void seek(long pos) throws IOException { address = pos; } IMemoryImageInputStream(IMemory memory, long startingAddress); @Override int read(byte[] buffer, int offset, int length); @Override int read(); @Override long getStreamPosition(); @Override void seek(long pos); } |
@Test public void testEOFBlocks() throws Exception { AbstractMemory memory = new MockMemory(ByteOrder.BIG_ENDIAN); memory.addMemorySource(new MockMemorySource(new byte[] { (byte)0xDE, (byte)0xAD, (byte)0xBE, (byte)0xEF}, 0, 0x10000, 0x10000)); memory.addMemorySource(new UnbackedMemorySource(0x20000, 0x10000, "Deliberately not backed")); IMemoryImageInputStream sut = new IMemoryImageInputStream(memory, 0x1FFFC); byte[] buffer = new byte[10]; assertEquals(4,sut.read(buffer)); assertEquals((byte)0xDE,buffer[0]); assertEquals((byte)0xAD,buffer[1]); assertEquals((byte)0xBE,buffer[2]); assertEquals((byte)0xEF,buffer[3]); assertEquals(-1,sut.read(buffer)); } | @Override public int read(byte[] buffer, int offset, int length) throws IOException { int read = 0; try { read = memory.getBytesAt(address, buffer,offset,length); } catch (MemoryFault f) { if (f.getAddress() == address) { return -1; } else { read = (int)(f.getAddress() - address); } } address += read; return read; } | IMemoryImageInputStream extends ImageInputStreamImpl { @Override public int read(byte[] buffer, int offset, int length) throws IOException { int read = 0; try { read = memory.getBytesAt(address, buffer,offset,length); } catch (MemoryFault f) { if (f.getAddress() == address) { return -1; } else { read = (int)(f.getAddress() - address); } } address += read; return read; } } | IMemoryImageInputStream extends ImageInputStreamImpl { @Override public int read(byte[] buffer, int offset, int length) throws IOException { int read = 0; try { read = memory.getBytesAt(address, buffer,offset,length); } catch (MemoryFault f) { if (f.getAddress() == address) { return -1; } else { read = (int)(f.getAddress() - address); } } address += read; return read; } IMemoryImageInputStream(IMemory memory, long startingAddress); } | IMemoryImageInputStream extends ImageInputStreamImpl { @Override public int read(byte[] buffer, int offset, int length) throws IOException { int read = 0; try { read = memory.getBytesAt(address, buffer,offset,length); } catch (MemoryFault f) { if (f.getAddress() == address) { return -1; } else { read = (int)(f.getAddress() - address); } } address += read; return read; } IMemoryImageInputStream(IMemory memory, long startingAddress); @Override int read(byte[] buffer, int offset, int length); @Override int read(); @Override long getStreamPosition(); @Override void seek(long pos); } | IMemoryImageInputStream extends ImageInputStreamImpl { @Override public int read(byte[] buffer, int offset, int length) throws IOException { int read = 0; try { read = memory.getBytesAt(address, buffer,offset,length); } catch (MemoryFault f) { if (f.getAddress() == address) { return -1; } else { read = (int)(f.getAddress() - address); } } address += read; return read; } IMemoryImageInputStream(IMemory memory, long startingAddress); @Override int read(byte[] buffer, int offset, int length); @Override int read(); @Override long getStreamPosition(); @Override void seek(long pos); } |
@Test public void testFindPatternAcrossRanges() { AbstractMemory sut = new MockMemory(ByteOrder.BIG_ENDIAN); sut.addMemorySource(new MockMemorySource(new byte[] { 0x0 }, 0, 0, 100)); sut .addMemorySource(new MockMemorySource(new byte[] { 0xA }, 0, 100, 100)); sut .addMemorySource(new MockMemorySource(new byte[] { 0xB }, 0, 200, 100)); sut .addMemorySource(new MockMemorySource(new byte[] { 0xD }, 0, 400, 100)); byte[] patternBuffer1 = new byte[100]; byte[] patternBuffer2 = new byte[100]; patternBuffer1[97] = 0xD; patternBuffer1[98] = 0xE; patternBuffer1[99] = 0xA; patternBuffer2[0] = 0xD; patternBuffer2[1] = 0xB; patternBuffer2[2] = 0xE; patternBuffer2[3] = 0xE; patternBuffer2[4] = 0xF; sut.addMemorySource(new BufferMemorySource(0, 500, patternBuffer1)); sut.addMemorySource(new BufferMemorySource(0, 600, patternBuffer2)); sut .addMemorySource(new MockMemorySource(new byte[] { 0xD }, 0, 700, 100)); sut .addMemorySource(new MockMemorySource(new byte[] { 0xD }, 0, 900, 100)); sut .addMemorySource(new MockMemorySource(new byte[] { 0xD }, 0, 1000, 100)); long address = sut.findPattern(new byte[] { 0xD, 0xE, 0xA, 0xD, 0xB, 0xE, 0xE, 0xF }, 1, 0); assertEquals(597, address); assertEquals(-1, sut.findPattern(new byte[] { 0xD, 0xE, 0xA, 0xD, 0xB, 0xE, 0xE, 0xF }, 1, 598)); assertEquals(-1, sut.findPattern(new byte[] { 0xD, 0xE, 0xA, 0xD, 0xB, 0xE, 0xE, 0xF }, 8, 0)); } | public void addMemorySource(IMemorySource source) { logger.logp(FINEST,"AbstractMemory","addMemorySource","Added memory range {0}-{1}",new Object[]{Long.toHexString(source.getBaseAddress()), Long.toHexString(source.getTopAddress()) }); if (GLOBAL_CACHE_ENABLED) { IMemorySource wrappedSource = new CachingMemorySource(source); decoratorMappingTable.put(source, wrappedSource); memorySources.addMemorySource(wrappedSource); } else { if (RECORDING_CACHE_STATS) { IMemorySource wrappedSource = new CountingMemorySource(source); decoratorMappingTable.put(source, wrappedSource); memorySources.addMemorySource(wrappedSource); } else { memorySources.addMemorySource(source); } } rangeTable = null; } | AbstractMemory extends SearchableMemory implements IMemory { public void addMemorySource(IMemorySource source) { logger.logp(FINEST,"AbstractMemory","addMemorySource","Added memory range {0}-{1}",new Object[]{Long.toHexString(source.getBaseAddress()), Long.toHexString(source.getTopAddress()) }); if (GLOBAL_CACHE_ENABLED) { IMemorySource wrappedSource = new CachingMemorySource(source); decoratorMappingTable.put(source, wrappedSource); memorySources.addMemorySource(wrappedSource); } else { if (RECORDING_CACHE_STATS) { IMemorySource wrappedSource = new CountingMemorySource(source); decoratorMappingTable.put(source, wrappedSource); memorySources.addMemorySource(wrappedSource); } else { memorySources.addMemorySource(source); } } rangeTable = null; } } | AbstractMemory extends SearchableMemory implements IMemory { public void addMemorySource(IMemorySource source) { logger.logp(FINEST,"AbstractMemory","addMemorySource","Added memory range {0}-{1}",new Object[]{Long.toHexString(source.getBaseAddress()), Long.toHexString(source.getTopAddress()) }); if (GLOBAL_CACHE_ENABLED) { IMemorySource wrappedSource = new CachingMemorySource(source); decoratorMappingTable.put(source, wrappedSource); memorySources.addMemorySource(wrappedSource); } else { if (RECORDING_CACHE_STATS) { IMemorySource wrappedSource = new CountingMemorySource(source); decoratorMappingTable.put(source, wrappedSource); memorySources.addMemorySource(wrappedSource); } else { memorySources.addMemorySource(source); } } rangeTable = null; } protected AbstractMemory(ByteOrder byteOrder); } | AbstractMemory extends SearchableMemory implements IMemory { public void addMemorySource(IMemorySource source) { logger.logp(FINEST,"AbstractMemory","addMemorySource","Added memory range {0}-{1}",new Object[]{Long.toHexString(source.getBaseAddress()), Long.toHexString(source.getTopAddress()) }); if (GLOBAL_CACHE_ENABLED) { IMemorySource wrappedSource = new CachingMemorySource(source); decoratorMappingTable.put(source, wrappedSource); memorySources.addMemorySource(wrappedSource); } else { if (RECORDING_CACHE_STATS) { IMemorySource wrappedSource = new CountingMemorySource(source); decoratorMappingTable.put(source, wrappedSource); memorySources.addMemorySource(wrappedSource); } else { memorySources.addMemorySource(source); } } rangeTable = null; } protected AbstractMemory(ByteOrder byteOrder); byte getByteAt(long address); int getBytesAt(long address, byte[] buffer); int getBytesAt(final long address, byte[] buffer, final int offset,final int length); int getIntAt(long address); long getLongAt(long address); short getShortAt(long address); void addMemorySource(IMemorySource source); void removeMemorySource(IMemorySource source); void addMemorySources(Collection<? extends IMemorySource> memorySources); List<IMemoryRange> getMemoryRanges(); ByteOrder getByteOrder(); boolean isShared(long address); boolean isExecutable(long address); boolean isReadOnly(long address); Properties getProperties(long address); } | AbstractMemory extends SearchableMemory implements IMemory { public void addMemorySource(IMemorySource source) { logger.logp(FINEST,"AbstractMemory","addMemorySource","Added memory range {0}-{1}",new Object[]{Long.toHexString(source.getBaseAddress()), Long.toHexString(source.getTopAddress()) }); if (GLOBAL_CACHE_ENABLED) { IMemorySource wrappedSource = new CachingMemorySource(source); decoratorMappingTable.put(source, wrappedSource); memorySources.addMemorySource(wrappedSource); } else { if (RECORDING_CACHE_STATS) { IMemorySource wrappedSource = new CountingMemorySource(source); decoratorMappingTable.put(source, wrappedSource); memorySources.addMemorySource(wrappedSource); } else { memorySources.addMemorySource(source); } } rangeTable = null; } protected AbstractMemory(ByteOrder byteOrder); byte getByteAt(long address); int getBytesAt(long address, byte[] buffer); int getBytesAt(final long address, byte[] buffer, final int offset,final int length); int getIntAt(long address); long getLongAt(long address); short getShortAt(long address); void addMemorySource(IMemorySource source); void removeMemorySource(IMemorySource source); void addMemorySources(Collection<? extends IMemorySource> memorySources); List<IMemoryRange> getMemoryRanges(); ByteOrder getByteOrder(); boolean isShared(long address); boolean isExecutable(long address); boolean isReadOnly(long address); Properties getProperties(long address); } |
@Test public void testFindPatternWithDeadSpace() { AbstractMemory sut = new MockMemory(ByteOrder.BIG_ENDIAN); sut .addMemorySource(new MockMemorySource(new byte[] { 0x0 }, 0, 0, 0x1000)); sut .addMemorySource(new UnbackedMemorySource(0x1000, 0x2000, "Dead space")); sut.addMemorySource(new MockMemorySource(new byte[] { 0xB }, 0, 0x3000, 0x1000)); sut .addMemorySource(new UnbackedMemorySource(0x4000, 0x1000, "Dead space")); byte[] patternBuffer1 = new byte[0x1000]; patternBuffer1[97] = 0xD; patternBuffer1[98] = 0xE; patternBuffer1[99] = 0xA; patternBuffer1[100] = 0xD; patternBuffer1[101] = 0xB; patternBuffer1[102] = 0xE; patternBuffer1[103] = 0xE; patternBuffer1[104] = 0xF; sut.addMemorySource(new BufferMemorySource(0, 0x5000, patternBuffer1)); sut.addMemorySource(new MockMemorySource(new byte[] { 0xD }, 0, 0x7000, 0x1000)); sut.addMemorySource(new MockMemorySource(new byte[] { 0xD }, 0, 0x9000, 0x1000)); sut.addMemorySource(new MockMemorySource(new byte[] { 0xD }, 0, 0x10000, 0x1000)); long address = sut.findPattern(new byte[] { 0xD, 0xE, 0xA, 0xD, 0xB, 0xE, 0xE, 0xF }, 1, 0); assertEquals(0x5061, address); assertEquals(-1, sut.findPattern(new byte[] { 0xD, 0xE, 0xA, 0xD, 0xB, 0xE, 0xE, 0xF }, 1, 0x5062)); assertEquals(-1, sut.findPattern(new byte[] { 0xD, 0xE, 0xA, 0xD, 0xB, 0xE, 0xE, 0xF }, 8, 0)); } | public void addMemorySource(IMemorySource source) { logger.logp(FINEST,"AbstractMemory","addMemorySource","Added memory range {0}-{1}",new Object[]{Long.toHexString(source.getBaseAddress()), Long.toHexString(source.getTopAddress()) }); if (GLOBAL_CACHE_ENABLED) { IMemorySource wrappedSource = new CachingMemorySource(source); decoratorMappingTable.put(source, wrappedSource); memorySources.addMemorySource(wrappedSource); } else { if (RECORDING_CACHE_STATS) { IMemorySource wrappedSource = new CountingMemorySource(source); decoratorMappingTable.put(source, wrappedSource); memorySources.addMemorySource(wrappedSource); } else { memorySources.addMemorySource(source); } } rangeTable = null; } | AbstractMemory extends SearchableMemory implements IMemory { public void addMemorySource(IMemorySource source) { logger.logp(FINEST,"AbstractMemory","addMemorySource","Added memory range {0}-{1}",new Object[]{Long.toHexString(source.getBaseAddress()), Long.toHexString(source.getTopAddress()) }); if (GLOBAL_CACHE_ENABLED) { IMemorySource wrappedSource = new CachingMemorySource(source); decoratorMappingTable.put(source, wrappedSource); memorySources.addMemorySource(wrappedSource); } else { if (RECORDING_CACHE_STATS) { IMemorySource wrappedSource = new CountingMemorySource(source); decoratorMappingTable.put(source, wrappedSource); memorySources.addMemorySource(wrappedSource); } else { memorySources.addMemorySource(source); } } rangeTable = null; } } | AbstractMemory extends SearchableMemory implements IMemory { public void addMemorySource(IMemorySource source) { logger.logp(FINEST,"AbstractMemory","addMemorySource","Added memory range {0}-{1}",new Object[]{Long.toHexString(source.getBaseAddress()), Long.toHexString(source.getTopAddress()) }); if (GLOBAL_CACHE_ENABLED) { IMemorySource wrappedSource = new CachingMemorySource(source); decoratorMappingTable.put(source, wrappedSource); memorySources.addMemorySource(wrappedSource); } else { if (RECORDING_CACHE_STATS) { IMemorySource wrappedSource = new CountingMemorySource(source); decoratorMappingTable.put(source, wrappedSource); memorySources.addMemorySource(wrappedSource); } else { memorySources.addMemorySource(source); } } rangeTable = null; } protected AbstractMemory(ByteOrder byteOrder); } | AbstractMemory extends SearchableMemory implements IMemory { public void addMemorySource(IMemorySource source) { logger.logp(FINEST,"AbstractMemory","addMemorySource","Added memory range {0}-{1}",new Object[]{Long.toHexString(source.getBaseAddress()), Long.toHexString(source.getTopAddress()) }); if (GLOBAL_CACHE_ENABLED) { IMemorySource wrappedSource = new CachingMemorySource(source); decoratorMappingTable.put(source, wrappedSource); memorySources.addMemorySource(wrappedSource); } else { if (RECORDING_CACHE_STATS) { IMemorySource wrappedSource = new CountingMemorySource(source); decoratorMappingTable.put(source, wrappedSource); memorySources.addMemorySource(wrappedSource); } else { memorySources.addMemorySource(source); } } rangeTable = null; } protected AbstractMemory(ByteOrder byteOrder); byte getByteAt(long address); int getBytesAt(long address, byte[] buffer); int getBytesAt(final long address, byte[] buffer, final int offset,final int length); int getIntAt(long address); long getLongAt(long address); short getShortAt(long address); void addMemorySource(IMemorySource source); void removeMemorySource(IMemorySource source); void addMemorySources(Collection<? extends IMemorySource> memorySources); List<IMemoryRange> getMemoryRanges(); ByteOrder getByteOrder(); boolean isShared(long address); boolean isExecutable(long address); boolean isReadOnly(long address); Properties getProperties(long address); } | AbstractMemory extends SearchableMemory implements IMemory { public void addMemorySource(IMemorySource source) { logger.logp(FINEST,"AbstractMemory","addMemorySource","Added memory range {0}-{1}",new Object[]{Long.toHexString(source.getBaseAddress()), Long.toHexString(source.getTopAddress()) }); if (GLOBAL_CACHE_ENABLED) { IMemorySource wrappedSource = new CachingMemorySource(source); decoratorMappingTable.put(source, wrappedSource); memorySources.addMemorySource(wrappedSource); } else { if (RECORDING_CACHE_STATS) { IMemorySource wrappedSource = new CountingMemorySource(source); decoratorMappingTable.put(source, wrappedSource); memorySources.addMemorySource(wrappedSource); } else { memorySources.addMemorySource(source); } } rangeTable = null; } protected AbstractMemory(ByteOrder byteOrder); byte getByteAt(long address); int getBytesAt(long address, byte[] buffer); int getBytesAt(final long address, byte[] buffer, final int offset,final int length); int getIntAt(long address); long getLongAt(long address); short getShortAt(long address); void addMemorySource(IMemorySource source); void removeMemorySource(IMemorySource source); void addMemorySources(Collection<? extends IMemorySource> memorySources); List<IMemoryRange> getMemoryRanges(); ByteOrder getByteOrder(); boolean isShared(long address); boolean isExecutable(long address); boolean isReadOnly(long address); Properties getProperties(long address); } |
@Test public void testMergeRanges() { AbstractMemory sut = new MockMemory(ByteOrder.BIG_ENDIAN); sut.addMemorySource(new MockMemorySource(new byte[] { 0x0 }, 0, 0x10000, 0x10000)); sut.addMemorySource(new MockMemorySource(new byte[] { 0x0 }, 0, 0x60000, 0x10000)); sut.addMemorySource(new MockMemorySource(new byte[] { 0x0 }, 0, 0x50000, 0x10000)); sut.addMemorySource(new MockMemorySource(new byte[] { 0x0 }, 0, 0x30000, 0x10000)); sut.addMemorySource(new MockMemorySource(new byte[] { 0x0 }, 0, 0x20000, 0x10000)); sut.addMemorySource(new MockMemorySource(new byte[] { 0x0 }, 0, 0x70000, 0x10000)); sut.addMemorySource(new MockMemorySource(new byte[] { 0x0 }, 0, 0x80000, 0x10000)); long[][] result = sut.buildRangeTable(); assertEquals(7, result.length); int mergedRecords = sut.mergeRangeTable(result); assertEquals(2, mergedRecords); assertEquals(0x10000, result[0][0]); assertEquals(0x30000, result[0][1]); assertEquals(0x50000, result[1][0]); assertEquals(0x40000, result[1][1]); } | public void addMemorySource(IMemorySource source) { logger.logp(FINEST,"AbstractMemory","addMemorySource","Added memory range {0}-{1}",new Object[]{Long.toHexString(source.getBaseAddress()), Long.toHexString(source.getTopAddress()) }); if (GLOBAL_CACHE_ENABLED) { IMemorySource wrappedSource = new CachingMemorySource(source); decoratorMappingTable.put(source, wrappedSource); memorySources.addMemorySource(wrappedSource); } else { if (RECORDING_CACHE_STATS) { IMemorySource wrappedSource = new CountingMemorySource(source); decoratorMappingTable.put(source, wrappedSource); memorySources.addMemorySource(wrappedSource); } else { memorySources.addMemorySource(source); } } rangeTable = null; } | AbstractMemory extends SearchableMemory implements IMemory { public void addMemorySource(IMemorySource source) { logger.logp(FINEST,"AbstractMemory","addMemorySource","Added memory range {0}-{1}",new Object[]{Long.toHexString(source.getBaseAddress()), Long.toHexString(source.getTopAddress()) }); if (GLOBAL_CACHE_ENABLED) { IMemorySource wrappedSource = new CachingMemorySource(source); decoratorMappingTable.put(source, wrappedSource); memorySources.addMemorySource(wrappedSource); } else { if (RECORDING_CACHE_STATS) { IMemorySource wrappedSource = new CountingMemorySource(source); decoratorMappingTable.put(source, wrappedSource); memorySources.addMemorySource(wrappedSource); } else { memorySources.addMemorySource(source); } } rangeTable = null; } } | AbstractMemory extends SearchableMemory implements IMemory { public void addMemorySource(IMemorySource source) { logger.logp(FINEST,"AbstractMemory","addMemorySource","Added memory range {0}-{1}",new Object[]{Long.toHexString(source.getBaseAddress()), Long.toHexString(source.getTopAddress()) }); if (GLOBAL_CACHE_ENABLED) { IMemorySource wrappedSource = new CachingMemorySource(source); decoratorMappingTable.put(source, wrappedSource); memorySources.addMemorySource(wrappedSource); } else { if (RECORDING_CACHE_STATS) { IMemorySource wrappedSource = new CountingMemorySource(source); decoratorMappingTable.put(source, wrappedSource); memorySources.addMemorySource(wrappedSource); } else { memorySources.addMemorySource(source); } } rangeTable = null; } protected AbstractMemory(ByteOrder byteOrder); } | AbstractMemory extends SearchableMemory implements IMemory { public void addMemorySource(IMemorySource source) { logger.logp(FINEST,"AbstractMemory","addMemorySource","Added memory range {0}-{1}",new Object[]{Long.toHexString(source.getBaseAddress()), Long.toHexString(source.getTopAddress()) }); if (GLOBAL_CACHE_ENABLED) { IMemorySource wrappedSource = new CachingMemorySource(source); decoratorMappingTable.put(source, wrappedSource); memorySources.addMemorySource(wrappedSource); } else { if (RECORDING_CACHE_STATS) { IMemorySource wrappedSource = new CountingMemorySource(source); decoratorMappingTable.put(source, wrappedSource); memorySources.addMemorySource(wrappedSource); } else { memorySources.addMemorySource(source); } } rangeTable = null; } protected AbstractMemory(ByteOrder byteOrder); byte getByteAt(long address); int getBytesAt(long address, byte[] buffer); int getBytesAt(final long address, byte[] buffer, final int offset,final int length); int getIntAt(long address); long getLongAt(long address); short getShortAt(long address); void addMemorySource(IMemorySource source); void removeMemorySource(IMemorySource source); void addMemorySources(Collection<? extends IMemorySource> memorySources); List<IMemoryRange> getMemoryRanges(); ByteOrder getByteOrder(); boolean isShared(long address); boolean isExecutable(long address); boolean isReadOnly(long address); Properties getProperties(long address); } | AbstractMemory extends SearchableMemory implements IMemory { public void addMemorySource(IMemorySource source) { logger.logp(FINEST,"AbstractMemory","addMemorySource","Added memory range {0}-{1}",new Object[]{Long.toHexString(source.getBaseAddress()), Long.toHexString(source.getTopAddress()) }); if (GLOBAL_CACHE_ENABLED) { IMemorySource wrappedSource = new CachingMemorySource(source); decoratorMappingTable.put(source, wrappedSource); memorySources.addMemorySource(wrappedSource); } else { if (RECORDING_CACHE_STATS) { IMemorySource wrappedSource = new CountingMemorySource(source); decoratorMappingTable.put(source, wrappedSource); memorySources.addMemorySource(wrappedSource); } else { memorySources.addMemorySource(source); } } rangeTable = null; } protected AbstractMemory(ByteOrder byteOrder); byte getByteAt(long address); int getBytesAt(long address, byte[] buffer); int getBytesAt(final long address, byte[] buffer, final int offset,final int length); int getIntAt(long address); long getLongAt(long address); short getShortAt(long address); void addMemorySource(IMemorySource source); void removeMemorySource(IMemorySource source); void addMemorySources(Collection<? extends IMemorySource> memorySources); List<IMemoryRange> getMemoryRanges(); ByteOrder getByteOrder(); boolean isShared(long address); boolean isExecutable(long address); boolean isReadOnly(long address); Properties getProperties(long address); } |
@Test public void testGreaterThan() { assertTrue(Addresses.greaterThan(1, 0)); assertTrue(Addresses.greaterThan(Long.MAX_VALUE, Long.MAX_VALUE - 1)); assertFalse(Addresses.greaterThan(7, 8)); assertTrue(Addresses.greaterThan(0xFFFFFFFFFFFFFFFFL, 0)); assertTrue(Addresses.greaterThan(0xFFFFFFFFFFFFFFFFL, 0xFFFFFFFFFFFFFFFEL)); assertTrue(Addresses.greaterThan(0xFFFFFFFFFFFFFFFFL, 47)); assertFalse(Addresses.greaterThan(0xFFFFFFFFFFFFFFFFL, 0xFFFFFFFFFFFFFFFFL)); assertFalse(Addresses.greaterThan(0xFFFFFFFFFFFFFFFEL, 0xFFFFFFFFFFFFFFFFL)); assertFalse(Addresses.greaterThan(0, 0xFFFFFFFFFFFFFFFFL)); assertFalse(Addresses.greaterThan(1, 1)); assertTrue(Addresses.greaterThan(0xFFFFFFFFFFFFFFFFL, Long.MAX_VALUE)); } | public static boolean greaterThan(long a, long b) { if (signBitsSame(a, b)) { return a > b; } else { return a < b; } } | Addresses { public static boolean greaterThan(long a, long b) { if (signBitsSame(a, b)) { return a > b; } else { return a < b; } } } | Addresses { public static boolean greaterThan(long a, long b) { if (signBitsSame(a, b)) { return a > b; } else { return a < b; } } } | Addresses { public static boolean greaterThan(long a, long b) { if (signBitsSame(a, b)) { return a > b; } else { return a < b; } } static boolean greaterThan(long a, long b); static boolean greaterThanOrEqual(long a, long b); static boolean lessThan(long a, long b); static boolean lessThanOrEqual(long a, long b); } | Addresses { public static boolean greaterThan(long a, long b) { if (signBitsSame(a, b)) { return a > b; } else { return a < b; } } static boolean greaterThan(long a, long b); static boolean greaterThanOrEqual(long a, long b); static boolean lessThan(long a, long b); static boolean lessThanOrEqual(long a, long b); } |
@Test public void testLessThan() { assertFalse(Addresses.lessThan(1, 0)); assertFalse(Addresses.lessThan(Long.MAX_VALUE, Long.MAX_VALUE - 1)); assertTrue(Addresses.lessThan(7, 8)); assertFalse(Addresses.lessThan(0xFFFFFFFFFFFFFFFFL, 0)); assertFalse(Addresses .lessThan(0xFFFFFFFFFFFFFFFFL, 0xFFFFFFFFFFFFFFFEL)); assertFalse(Addresses.lessThan(0xFFFFFFFFFFFFFFFFL, 47)); assertFalse(Addresses .lessThan(0xFFFFFFFFFFFFFFFFL, 0xFFFFFFFFFFFFFFFFL)); assertTrue(Addresses.lessThan(0xFFFFFFFFFFFFFFFEL, 0xFFFFFFFFFFFFFFFFL)); assertTrue(Addresses.lessThan(0, 0xFFFFFFFFFFFFFFFFL)); assertFalse(Addresses.lessThan(1, 1)); assertFalse(Addresses.lessThan(0xFFFFFFFFFFFFFFFFL, Long.MAX_VALUE)); } | public static boolean lessThan(long a, long b) { if (signBitsSame(a, b)) { return a < b; } else { return a > b; } } | Addresses { public static boolean lessThan(long a, long b) { if (signBitsSame(a, b)) { return a < b; } else { return a > b; } } } | Addresses { public static boolean lessThan(long a, long b) { if (signBitsSame(a, b)) { return a < b; } else { return a > b; } } } | Addresses { public static boolean lessThan(long a, long b) { if (signBitsSame(a, b)) { return a < b; } else { return a > b; } } static boolean greaterThan(long a, long b); static boolean greaterThanOrEqual(long a, long b); static boolean lessThan(long a, long b); static boolean lessThanOrEqual(long a, long b); } | Addresses { public static boolean lessThan(long a, long b) { if (signBitsSame(a, b)) { return a < b; } else { return a > b; } } static boolean greaterThan(long a, long b); static boolean greaterThanOrEqual(long a, long b); static boolean lessThan(long a, long b); static boolean lessThanOrEqual(long a, long b); } |
@Test public void testReadIndividualBytes() throws Exception { AbstractMemory memory = new MockMemory(ByteOrder.BIG_ENDIAN); memory.addMemorySource(new MockMemorySource(new byte[] { (byte)0xDE, (byte)0xAD, (byte)0xBE, (byte)0xEF}, 0, 0x10000, 0x10000)); IMemoryImageInputStream sut = new IMemoryImageInputStream(memory, 0x10000); assertEquals(0xDE,sut.read()); assertEquals(0xAD,sut.read()); assertEquals(0xBE,sut.read()); assertEquals(0xEF,sut.read()); assertEquals(0xDE,sut.read()); } | @Override public int read(byte[] buffer, int offset, int length) throws IOException { int read = 0; try { read = memory.getBytesAt(address, buffer,offset,length); } catch (MemoryFault f) { if (f.getAddress() == address) { return -1; } else { read = (int)(f.getAddress() - address); } } address += read; return read; } | IMemoryImageInputStream extends ImageInputStreamImpl { @Override public int read(byte[] buffer, int offset, int length) throws IOException { int read = 0; try { read = memory.getBytesAt(address, buffer,offset,length); } catch (MemoryFault f) { if (f.getAddress() == address) { return -1; } else { read = (int)(f.getAddress() - address); } } address += read; return read; } } | IMemoryImageInputStream extends ImageInputStreamImpl { @Override public int read(byte[] buffer, int offset, int length) throws IOException { int read = 0; try { read = memory.getBytesAt(address, buffer,offset,length); } catch (MemoryFault f) { if (f.getAddress() == address) { return -1; } else { read = (int)(f.getAddress() - address); } } address += read; return read; } IMemoryImageInputStream(IMemory memory, long startingAddress); } | IMemoryImageInputStream extends ImageInputStreamImpl { @Override public int read(byte[] buffer, int offset, int length) throws IOException { int read = 0; try { read = memory.getBytesAt(address, buffer,offset,length); } catch (MemoryFault f) { if (f.getAddress() == address) { return -1; } else { read = (int)(f.getAddress() - address); } } address += read; return read; } IMemoryImageInputStream(IMemory memory, long startingAddress); @Override int read(byte[] buffer, int offset, int length); @Override int read(); @Override long getStreamPosition(); @Override void seek(long pos); } | IMemoryImageInputStream extends ImageInputStreamImpl { @Override public int read(byte[] buffer, int offset, int length) throws IOException { int read = 0; try { read = memory.getBytesAt(address, buffer,offset,length); } catch (MemoryFault f) { if (f.getAddress() == address) { return -1; } else { read = (int)(f.getAddress() - address); } } address += read; return read; } IMemoryImageInputStream(IMemory memory, long startingAddress); @Override int read(byte[] buffer, int offset, int length); @Override int read(); @Override long getStreamPosition(); @Override void seek(long pos); } |
@Test public void testReadBlocksOfMemory() throws Exception { AbstractMemory memory = new MockMemory(ByteOrder.BIG_ENDIAN); memory.addMemorySource(new MockMemorySource(new byte[] { (byte)0xDE, (byte)0xAD, (byte)0xBE, (byte)0xEF}, 0, 0x10000, 0x10000)); IMemoryImageInputStream sut = new IMemoryImageInputStream(memory, 0x10000); byte[] buffer = new byte[5]; assertEquals(5,sut.read(buffer)); assertEquals((byte)0xDE,buffer[0]); assertEquals((byte)0xAD,buffer[1]); assertEquals((byte)0xBE,buffer[2]); assertEquals((byte)0xEF,buffer[3]); assertEquals((byte)0xDE,buffer[4]); assertEquals(5,sut.read(buffer)); assertEquals((byte)0xAD,buffer[0]); assertEquals((byte)0xBE,buffer[1]); assertEquals((byte)0xEF,buffer[2]); assertEquals((byte)0xDE,buffer[3]); assertEquals((byte)0xAD,buffer[4]); } | @Override public int read(byte[] buffer, int offset, int length) throws IOException { int read = 0; try { read = memory.getBytesAt(address, buffer,offset,length); } catch (MemoryFault f) { if (f.getAddress() == address) { return -1; } else { read = (int)(f.getAddress() - address); } } address += read; return read; } | IMemoryImageInputStream extends ImageInputStreamImpl { @Override public int read(byte[] buffer, int offset, int length) throws IOException { int read = 0; try { read = memory.getBytesAt(address, buffer,offset,length); } catch (MemoryFault f) { if (f.getAddress() == address) { return -1; } else { read = (int)(f.getAddress() - address); } } address += read; return read; } } | IMemoryImageInputStream extends ImageInputStreamImpl { @Override public int read(byte[] buffer, int offset, int length) throws IOException { int read = 0; try { read = memory.getBytesAt(address, buffer,offset,length); } catch (MemoryFault f) { if (f.getAddress() == address) { return -1; } else { read = (int)(f.getAddress() - address); } } address += read; return read; } IMemoryImageInputStream(IMemory memory, long startingAddress); } | IMemoryImageInputStream extends ImageInputStreamImpl { @Override public int read(byte[] buffer, int offset, int length) throws IOException { int read = 0; try { read = memory.getBytesAt(address, buffer,offset,length); } catch (MemoryFault f) { if (f.getAddress() == address) { return -1; } else { read = (int)(f.getAddress() - address); } } address += read; return read; } IMemoryImageInputStream(IMemory memory, long startingAddress); @Override int read(byte[] buffer, int offset, int length); @Override int read(); @Override long getStreamPosition(); @Override void seek(long pos); } | IMemoryImageInputStream extends ImageInputStreamImpl { @Override public int read(byte[] buffer, int offset, int length) throws IOException { int read = 0; try { read = memory.getBytesAt(address, buffer,offset,length); } catch (MemoryFault f) { if (f.getAddress() == address) { return -1; } else { read = (int)(f.getAddress() - address); } } address += read; return read; } IMemoryImageInputStream(IMemory memory, long startingAddress); @Override int read(byte[] buffer, int offset, int length); @Override int read(); @Override long getStreamPosition(); @Override void seek(long pos); } |
@Test public void testReadBlocksSpanning() throws Exception { AbstractMemory memory = new MockMemory(ByteOrder.BIG_ENDIAN); memory.addMemorySource(new MockMemorySource(new byte[] { (byte)0xDE, (byte)0xAD, (byte)0xBE, (byte)0xEF}, 0, 0x10000, 0x10000)); memory.addMemorySource(new MockMemorySource(new byte[] { (byte)0xCA, (byte)0xFE, (byte)0xBA, (byte)0xBE}, 0, 0x20000, 0x10000)); IMemoryImageInputStream sut = new IMemoryImageInputStream(memory, 0x1FFFC); byte[] buffer = new byte[10]; assertEquals(10,sut.read(buffer)); assertEquals((byte)0xDE,buffer[0]); assertEquals((byte)0xAD,buffer[1]); assertEquals((byte)0xBE,buffer[2]); assertEquals((byte)0xEF,buffer[3]); assertEquals((byte)0xCA,buffer[4]); assertEquals((byte)0xFE,buffer[5]); assertEquals((byte)0xBA,buffer[6]); assertEquals((byte)0xBE,buffer[7]); assertEquals((byte)0xCA,buffer[8]); assertEquals((byte)0xFE,buffer[9]); } | @Override public int read(byte[] buffer, int offset, int length) throws IOException { int read = 0; try { read = memory.getBytesAt(address, buffer,offset,length); } catch (MemoryFault f) { if (f.getAddress() == address) { return -1; } else { read = (int)(f.getAddress() - address); } } address += read; return read; } | IMemoryImageInputStream extends ImageInputStreamImpl { @Override public int read(byte[] buffer, int offset, int length) throws IOException { int read = 0; try { read = memory.getBytesAt(address, buffer,offset,length); } catch (MemoryFault f) { if (f.getAddress() == address) { return -1; } else { read = (int)(f.getAddress() - address); } } address += read; return read; } } | IMemoryImageInputStream extends ImageInputStreamImpl { @Override public int read(byte[] buffer, int offset, int length) throws IOException { int read = 0; try { read = memory.getBytesAt(address, buffer,offset,length); } catch (MemoryFault f) { if (f.getAddress() == address) { return -1; } else { read = (int)(f.getAddress() - address); } } address += read; return read; } IMemoryImageInputStream(IMemory memory, long startingAddress); } | IMemoryImageInputStream extends ImageInputStreamImpl { @Override public int read(byte[] buffer, int offset, int length) throws IOException { int read = 0; try { read = memory.getBytesAt(address, buffer,offset,length); } catch (MemoryFault f) { if (f.getAddress() == address) { return -1; } else { read = (int)(f.getAddress() - address); } } address += read; return read; } IMemoryImageInputStream(IMemory memory, long startingAddress); @Override int read(byte[] buffer, int offset, int length); @Override int read(); @Override long getStreamPosition(); @Override void seek(long pos); } | IMemoryImageInputStream extends ImageInputStreamImpl { @Override public int read(byte[] buffer, int offset, int length) throws IOException { int read = 0; try { read = memory.getBytesAt(address, buffer,offset,length); } catch (MemoryFault f) { if (f.getAddress() == address) { return -1; } else { read = (int)(f.getAddress() - address); } } address += read; return read; } IMemoryImageInputStream(IMemory memory, long startingAddress); @Override int read(byte[] buffer, int offset, int length); @Override int read(); @Override long getStreamPosition(); @Override void seek(long pos); } |
@Test public void testEOFIndividualBytes() throws Exception { AbstractMemory memory = new MockMemory(ByteOrder.BIG_ENDIAN); memory.addMemorySource(new MockMemorySource(new byte[] { (byte)0xA0}, 0, 0x10000, 0x10000)); memory.addMemorySource(new UnbackedMemorySource(0x20000, 0x10000, "Deliberately not backed")); IMemoryImageInputStream sut = new IMemoryImageInputStream(memory, 0x1FFFE); assertEquals(0xA0,sut.read()); assertEquals(0xA0,sut.read()); assertEquals(-1,sut.read()); } | @Override public int read(byte[] buffer, int offset, int length) throws IOException { int read = 0; try { read = memory.getBytesAt(address, buffer,offset,length); } catch (MemoryFault f) { if (f.getAddress() == address) { return -1; } else { read = (int)(f.getAddress() - address); } } address += read; return read; } | IMemoryImageInputStream extends ImageInputStreamImpl { @Override public int read(byte[] buffer, int offset, int length) throws IOException { int read = 0; try { read = memory.getBytesAt(address, buffer,offset,length); } catch (MemoryFault f) { if (f.getAddress() == address) { return -1; } else { read = (int)(f.getAddress() - address); } } address += read; return read; } } | IMemoryImageInputStream extends ImageInputStreamImpl { @Override public int read(byte[] buffer, int offset, int length) throws IOException { int read = 0; try { read = memory.getBytesAt(address, buffer,offset,length); } catch (MemoryFault f) { if (f.getAddress() == address) { return -1; } else { read = (int)(f.getAddress() - address); } } address += read; return read; } IMemoryImageInputStream(IMemory memory, long startingAddress); } | IMemoryImageInputStream extends ImageInputStreamImpl { @Override public int read(byte[] buffer, int offset, int length) throws IOException { int read = 0; try { read = memory.getBytesAt(address, buffer,offset,length); } catch (MemoryFault f) { if (f.getAddress() == address) { return -1; } else { read = (int)(f.getAddress() - address); } } address += read; return read; } IMemoryImageInputStream(IMemory memory, long startingAddress); @Override int read(byte[] buffer, int offset, int length); @Override int read(); @Override long getStreamPosition(); @Override void seek(long pos); } | IMemoryImageInputStream extends ImageInputStreamImpl { @Override public int read(byte[] buffer, int offset, int length) throws IOException { int read = 0; try { read = memory.getBytesAt(address, buffer,offset,length); } catch (MemoryFault f) { if (f.getAddress() == address) { return -1; } else { read = (int)(f.getAddress() - address); } } address += read; return read; } IMemoryImageInputStream(IMemory memory, long startingAddress); @Override int read(byte[] buffer, int offset, int length); @Override int read(); @Override long getStreamPosition(); @Override void seek(long pos); } |
@Test public void testCompleteQuery() { SqlBuilder sqlBuilder = new SqlBuilder(buildEntity()); String sql = sqlBuilder.build(); String expectedSql = "COPY simple_table (column1, column2) " + "FROM STDIN WITH (ENCODING 'UTF-8', DELIMITER '\t', HEADER false)"; assertEquals(expectedSql, sql); } | public String build() { addCopyTable(); addColumnNames(); addFileConfig(); return getSql(); } | SqlBuilder { public String build() { addCopyTable(); addColumnNames(); addFileConfig(); return getSql(); } } | SqlBuilder { public String build() { addCopyTable(); addColumnNames(); addFileConfig(); return getSql(); } SqlBuilder(EntityInfo entityInfo); } | SqlBuilder { public String build() { addCopyTable(); addColumnNames(); addFileConfig(); return getSql(); } SqlBuilder(EntityInfo entityInfo); String build(); void addCopyTable(); void addColumnNames(); void addFileConfig(); String getSql(); } | SqlBuilder { public String build() { addCopyTable(); addColumnNames(); addFileConfig(); return getSql(); } SqlBuilder(EntityInfo entityInfo); String build(); void addCopyTable(); void addColumnNames(); void addFileConfig(); String getSql(); } |
@Test public void testEscapeFieldTermination() { String text = "1234\tvalue\t5678\t"; String escaped = escaper.escapeForLoadFile(text); assertEquals("1234" + ESCAPED_BY_CHAR + FIELD_TERMINATED_CHAR + "value" + ESCAPED_BY_CHAR + FIELD_TERMINATED_CHAR + "5678" + ESCAPED_BY_CHAR + FIELD_TERMINATED_CHAR, escaped); logger.info("FROM:"); logger.info(text); logger.info("TO:"); logger.info(escaped); } | public String escapeForLoadFile(String text) { if (text == null) { return null; } int firstEscapableChar = findFirstEscapableChar(text); if (firstEscapableChar == -1) { return text; } StringBuilder sb = new StringBuilder(text.substring(0, firstEscapableChar)); int textLength = text.length(); for (int i = firstEscapableChar; i < textLength; i++) { char textCharacter = text.charAt(i); if (isEscapable(textCharacter)) { sb.append(ESCAPED_BY_CHAR); sb.append(textCharacter); } else { sb.append(textCharacter); } } return sb.toString(); } | LoadDataEscaper { public String escapeForLoadFile(String text) { if (text == null) { return null; } int firstEscapableChar = findFirstEscapableChar(text); if (firstEscapableChar == -1) { return text; } StringBuilder sb = new StringBuilder(text.substring(0, firstEscapableChar)); int textLength = text.length(); for (int i = firstEscapableChar; i < textLength; i++) { char textCharacter = text.charAt(i); if (isEscapable(textCharacter)) { sb.append(ESCAPED_BY_CHAR); sb.append(textCharacter); } else { sb.append(textCharacter); } } return sb.toString(); } } | LoadDataEscaper { public String escapeForLoadFile(String text) { if (text == null) { return null; } int firstEscapableChar = findFirstEscapableChar(text); if (firstEscapableChar == -1) { return text; } StringBuilder sb = new StringBuilder(text.substring(0, firstEscapableChar)); int textLength = text.length(); for (int i = firstEscapableChar; i < textLength; i++) { char textCharacter = text.charAt(i); if (isEscapable(textCharacter)) { sb.append(ESCAPED_BY_CHAR); sb.append(textCharacter); } else { sb.append(textCharacter); } } return sb.toString(); } } | LoadDataEscaper { public String escapeForLoadFile(String text) { if (text == null) { return null; } int firstEscapableChar = findFirstEscapableChar(text); if (firstEscapableChar == -1) { return text; } StringBuilder sb = new StringBuilder(text.substring(0, firstEscapableChar)); int textLength = text.length(); for (int i = firstEscapableChar; i < textLength; i++) { char textCharacter = text.charAt(i); if (isEscapable(textCharacter)) { sb.append(ESCAPED_BY_CHAR); sb.append(textCharacter); } else { sb.append(textCharacter); } } return sb.toString(); } String escapeForLoadFile(String text); } | LoadDataEscaper { public String escapeForLoadFile(String text) { if (text == null) { return null; } int firstEscapableChar = findFirstEscapableChar(text); if (firstEscapableChar == -1) { return text; } StringBuilder sb = new StringBuilder(text.substring(0, firstEscapableChar)); int textLength = text.length(); for (int i = firstEscapableChar; i < textLength; i++) { char textCharacter = text.charAt(i); if (isEscapable(textCharacter)) { sb.append(ESCAPED_BY_CHAR); sb.append(textCharacter); } else { sb.append(textCharacter); } } return sb.toString(); } String escapeForLoadFile(String text); } |
@Test public void booleanPrimitiveTest() { EntityFieldType type = getField("booleanPrimitive"); assertTrue(type.isPrimitive()); assertEquals(FieldTypeEnum.BOOLEAN, type.getFieldType()); } | public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } |
@Test public void booleanObjectTest() { EntityFieldType type = getField("booleanObject"); assertFalse(type.isPrimitive()); assertEquals(FieldTypeEnum.BOOLEAN, type.getFieldType()); } | public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } |
@Test public void bytePrimitiveTest() { EntityFieldType type = getField("bytePrimitive"); assertTrue(type.isPrimitive()); assertEquals(FieldTypeEnum.BYTE, type.getFieldType()); } | public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } |
@Test public void byteObjectTest() { EntityFieldType type = getField("byteObject"); assertFalse(type.isPrimitive()); assertEquals(FieldTypeEnum.BYTE, type.getFieldType()); } | public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } |
@Test public void shortPrimitiveTest() { EntityFieldType type = getField("shortPrimitive"); assertTrue(type.isPrimitive()); assertEquals(FieldTypeEnum.SHORT, type.getFieldType()); } | public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } |
@Test public void shortObjectTest() { EntityFieldType type = getField("shortObject"); assertFalse(type.isPrimitive()); assertEquals(FieldTypeEnum.SHORT, type.getFieldType()); } | public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } |
@Test public void intPrimitiveTest() { EntityFieldType type = getField("intPrimitive"); assertTrue(type.isPrimitive()); assertEquals(FieldTypeEnum.INT, type.getFieldType()); } | public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } |
@Test public void intObjectTest() { EntityFieldType type = getField("intObject"); assertFalse(type.isPrimitive()); assertEquals(FieldTypeEnum.INT, type.getFieldType()); } | public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } |
@Test public void longPrimitiveTest() { EntityFieldType type = getField("longPrimitive"); assertTrue(type.isPrimitive()); assertEquals(FieldTypeEnum.LONG, type.getFieldType()); } | public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } |
@Test public void testNoEscapeNeeded() { String text = "Some text with no escape neeed"; String escaped = escaper.escapeForStdIn(text); assertEquals(text, escaped); } | public String escapeForStdIn(String text) { if (text == null) { return null; } int firstEscapableChar = findFirstEscapableChar(text); if (firstEscapableChar == -1) { return text; } StringBuilder sb = new StringBuilder(text.substring(0, firstEscapableChar)); int textLength = text.length(); for (int i = firstEscapableChar; i < textLength; i++) { char textCharacter = text.charAt(i); if (isEscapable(textCharacter)) { sb.append(PgCopyConstants.ESCAPE_CHAR); sb.append(textCharacter); } else { sb.append(textCharacter); } } return sb.toString(); } | PgCopyEscaper { public String escapeForStdIn(String text) { if (text == null) { return null; } int firstEscapableChar = findFirstEscapableChar(text); if (firstEscapableChar == -1) { return text; } StringBuilder sb = new StringBuilder(text.substring(0, firstEscapableChar)); int textLength = text.length(); for (int i = firstEscapableChar; i < textLength; i++) { char textCharacter = text.charAt(i); if (isEscapable(textCharacter)) { sb.append(PgCopyConstants.ESCAPE_CHAR); sb.append(textCharacter); } else { sb.append(textCharacter); } } return sb.toString(); } } | PgCopyEscaper { public String escapeForStdIn(String text) { if (text == null) { return null; } int firstEscapableChar = findFirstEscapableChar(text); if (firstEscapableChar == -1) { return text; } StringBuilder sb = new StringBuilder(text.substring(0, firstEscapableChar)); int textLength = text.length(); for (int i = firstEscapableChar; i < textLength; i++) { char textCharacter = text.charAt(i); if (isEscapable(textCharacter)) { sb.append(PgCopyConstants.ESCAPE_CHAR); sb.append(textCharacter); } else { sb.append(textCharacter); } } return sb.toString(); } } | PgCopyEscaper { public String escapeForStdIn(String text) { if (text == null) { return null; } int firstEscapableChar = findFirstEscapableChar(text); if (firstEscapableChar == -1) { return text; } StringBuilder sb = new StringBuilder(text.substring(0, firstEscapableChar)); int textLength = text.length(); for (int i = firstEscapableChar; i < textLength; i++) { char textCharacter = text.charAt(i); if (isEscapable(textCharacter)) { sb.append(PgCopyConstants.ESCAPE_CHAR); sb.append(textCharacter); } else { sb.append(textCharacter); } } return sb.toString(); } String escapeForStdIn(String text); } | PgCopyEscaper { public String escapeForStdIn(String text) { if (text == null) { return null; } int firstEscapableChar = findFirstEscapableChar(text); if (firstEscapableChar == -1) { return text; } StringBuilder sb = new StringBuilder(text.substring(0, firstEscapableChar)); int textLength = text.length(); for (int i = firstEscapableChar; i < textLength; i++) { char textCharacter = text.charAt(i); if (isEscapable(textCharacter)) { sb.append(PgCopyConstants.ESCAPE_CHAR); sb.append(textCharacter); } else { sb.append(textCharacter); } } return sb.toString(); } String escapeForStdIn(String text); } |
@Test public void longObjectTest() { EntityFieldType type = getField("longObject"); assertFalse(type.isPrimitive()); assertEquals(FieldTypeEnum.LONG, type.getFieldType()); } | public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } |
@Test public void charPrimitiveTest() { EntityFieldType type = getField("charPrimitive"); assertTrue(type.isPrimitive()); assertEquals(FieldTypeEnum.CHAR, type.getFieldType()); } | public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } |
@Test public void charObjectTest() { EntityFieldType type = getField("charObject"); assertFalse(type.isPrimitive()); assertEquals(FieldTypeEnum.CHAR, type.getFieldType()); } | public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } |
@Test public void floatPrimitiveTest() { EntityFieldType type = getField("floatPrimitive"); assertTrue(type.isPrimitive()); assertEquals(FieldTypeEnum.FLOAT, type.getFieldType()); } | public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } |
@Test public void floatObjectTest() { EntityFieldType type = getField("floatObject"); assertFalse(type.isPrimitive()); assertEquals(FieldTypeEnum.FLOAT, type.getFieldType()); } | public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } |
@Test public void doublePrimitiveTest() { EntityFieldType type = getField("doublePrimitive"); assertTrue(type.isPrimitive()); assertEquals(FieldTypeEnum.DOUBLE, type.getFieldType()); } | public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } |
@Test public void doubleObjectTest() { EntityFieldType type = getField("doubleObject"); assertFalse(type.isPrimitive()); assertEquals(FieldTypeEnum.DOUBLE, type.getFieldType()); } | public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } |
@Test public void stringTest() { EntityFieldType type = getField("string"); assertFalse(type.isPrimitive()); assertEquals(FieldTypeEnum.STRING, type.getFieldType()); } | public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } |
@Test public void nonAnnotatedDateTest() { EntityFieldType type = getField("nonAnnotatedDate"); assertFalse(type.isPrimitive()); assertEquals(FieldTypeEnum.TIMESTAMP, type.getFieldType()); } | public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } |
@Test public void dateTest() { EntityFieldType type = getField("date"); assertFalse(type.isPrimitive()); assertEquals(FieldTypeEnum.DATE, type.getFieldType()); } | public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } |
@Test public void testEscapeEscapedByChar() { String text = "Some text with some \\ escape char \\\\ to change"; String escaped = escaper.escapeForStdIn(text); assertEquals("Some text with some " + ESCAPED_BY_CHAR + ESCAPED_BY_CHAR + " escape char " + ESCAPED_BY_CHAR + ESCAPED_BY_CHAR + ESCAPED_BY_CHAR + ESCAPED_BY_CHAR + " to change", escaped); logger.info("FROM:"); logger.info(text); logger.info("TO:"); logger.info(escaped); } | public String escapeForStdIn(String text) { if (text == null) { return null; } int firstEscapableChar = findFirstEscapableChar(text); if (firstEscapableChar == -1) { return text; } StringBuilder sb = new StringBuilder(text.substring(0, firstEscapableChar)); int textLength = text.length(); for (int i = firstEscapableChar; i < textLength; i++) { char textCharacter = text.charAt(i); if (isEscapable(textCharacter)) { sb.append(PgCopyConstants.ESCAPE_CHAR); sb.append(textCharacter); } else { sb.append(textCharacter); } } return sb.toString(); } | PgCopyEscaper { public String escapeForStdIn(String text) { if (text == null) { return null; } int firstEscapableChar = findFirstEscapableChar(text); if (firstEscapableChar == -1) { return text; } StringBuilder sb = new StringBuilder(text.substring(0, firstEscapableChar)); int textLength = text.length(); for (int i = firstEscapableChar; i < textLength; i++) { char textCharacter = text.charAt(i); if (isEscapable(textCharacter)) { sb.append(PgCopyConstants.ESCAPE_CHAR); sb.append(textCharacter); } else { sb.append(textCharacter); } } return sb.toString(); } } | PgCopyEscaper { public String escapeForStdIn(String text) { if (text == null) { return null; } int firstEscapableChar = findFirstEscapableChar(text); if (firstEscapableChar == -1) { return text; } StringBuilder sb = new StringBuilder(text.substring(0, firstEscapableChar)); int textLength = text.length(); for (int i = firstEscapableChar; i < textLength; i++) { char textCharacter = text.charAt(i); if (isEscapable(textCharacter)) { sb.append(PgCopyConstants.ESCAPE_CHAR); sb.append(textCharacter); } else { sb.append(textCharacter); } } return sb.toString(); } } | PgCopyEscaper { public String escapeForStdIn(String text) { if (text == null) { return null; } int firstEscapableChar = findFirstEscapableChar(text); if (firstEscapableChar == -1) { return text; } StringBuilder sb = new StringBuilder(text.substring(0, firstEscapableChar)); int textLength = text.length(); for (int i = firstEscapableChar; i < textLength; i++) { char textCharacter = text.charAt(i); if (isEscapable(textCharacter)) { sb.append(PgCopyConstants.ESCAPE_CHAR); sb.append(textCharacter); } else { sb.append(textCharacter); } } return sb.toString(); } String escapeForStdIn(String text); } | PgCopyEscaper { public String escapeForStdIn(String text) { if (text == null) { return null; } int firstEscapableChar = findFirstEscapableChar(text); if (firstEscapableChar == -1) { return text; } StringBuilder sb = new StringBuilder(text.substring(0, firstEscapableChar)); int textLength = text.length(); for (int i = firstEscapableChar; i < textLength; i++) { char textCharacter = text.charAt(i); if (isEscapable(textCharacter)) { sb.append(PgCopyConstants.ESCAPE_CHAR); sb.append(textCharacter); } else { sb.append(textCharacter); } } return sb.toString(); } String escapeForStdIn(String text); } |
@Test public void timeTest() { EntityFieldType type = getField("time"); assertFalse(type.isPrimitive()); assertEquals(FieldTypeEnum.TIME, type.getFieldType()); } | public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } |
@Test public void timeStampTest() { EntityFieldType type = getField("timeStamp"); assertFalse(type.isPrimitive()); assertEquals(FieldTypeEnum.TIMESTAMP, type.getFieldType()); } | public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } |
@Test public void sqlDateTest() { EntityFieldType type = getField("sqlDate"); assertFalse(type.isPrimitive()); assertEquals(FieldTypeEnum.DATE, type.getFieldType()); } | public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } |
@Test public void sqlTimeTest() { EntityFieldType type = getField("sqlTime"); assertFalse(type.isPrimitive()); assertEquals(FieldTypeEnum.TIME, type.getFieldType()); } | public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } |
@Test public void sqlTimeStampTest() { EntityFieldType type = getField("sqlTimeStamp"); assertFalse(type.isPrimitive()); assertEquals(FieldTypeEnum.TIMESTAMP, type.getFieldType()); } | public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } |
@Test public void localDateTest() { EntityFieldType type = getField("localDate"); assertFalse(type.isPrimitive()); assertEquals(FieldTypeEnum.LOCALDATE, type.getFieldType()); } | public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } |
@Test public void localTimeTest() { EntityFieldType type = getField("localTime"); assertFalse(type.isPrimitive()); assertEquals(FieldTypeEnum.LOCALTIME, type.getFieldType()); } | public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } |
@Test public void localDateTimeTest() { EntityFieldType type = getField("localDateTime"); assertFalse(type.isPrimitive()); assertEquals(FieldTypeEnum.LOCALDATETIME, type.getFieldType()); } | public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } |
@Test public void enumUnAnnotatedTest() { EntityFieldType type = getField("enumUnAnnotated"); assertFalse(type.isPrimitive()); assertEquals(FieldTypeEnum.ENUMORDINAL, type.getFieldType()); } | public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } |
@Test public void enumDefaultTest() { EntityFieldType type = getField("enumDefault"); assertFalse(type.isPrimitive()); assertEquals(FieldTypeEnum.ENUMORDINAL, type.getFieldType()); } | public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } |
@Test public void testEscapeFieldSeparator() { String text = "1234\tvalue\t5678\t"; String escaped = escaper.escapeForStdIn(text); assertEquals("1234" + ESCAPED_BY_CHAR + FIELD_TERMINATED_CHAR + "value" + ESCAPED_BY_CHAR + FIELD_TERMINATED_CHAR + "5678" + ESCAPED_BY_CHAR + FIELD_TERMINATED_CHAR, escaped); logger.info("FROM:"); logger.info(text); logger.info("TO:"); logger.info(escaped); } | public String escapeForStdIn(String text) { if (text == null) { return null; } int firstEscapableChar = findFirstEscapableChar(text); if (firstEscapableChar == -1) { return text; } StringBuilder sb = new StringBuilder(text.substring(0, firstEscapableChar)); int textLength = text.length(); for (int i = firstEscapableChar; i < textLength; i++) { char textCharacter = text.charAt(i); if (isEscapable(textCharacter)) { sb.append(PgCopyConstants.ESCAPE_CHAR); sb.append(textCharacter); } else { sb.append(textCharacter); } } return sb.toString(); } | PgCopyEscaper { public String escapeForStdIn(String text) { if (text == null) { return null; } int firstEscapableChar = findFirstEscapableChar(text); if (firstEscapableChar == -1) { return text; } StringBuilder sb = new StringBuilder(text.substring(0, firstEscapableChar)); int textLength = text.length(); for (int i = firstEscapableChar; i < textLength; i++) { char textCharacter = text.charAt(i); if (isEscapable(textCharacter)) { sb.append(PgCopyConstants.ESCAPE_CHAR); sb.append(textCharacter); } else { sb.append(textCharacter); } } return sb.toString(); } } | PgCopyEscaper { public String escapeForStdIn(String text) { if (text == null) { return null; } int firstEscapableChar = findFirstEscapableChar(text); if (firstEscapableChar == -1) { return text; } StringBuilder sb = new StringBuilder(text.substring(0, firstEscapableChar)); int textLength = text.length(); for (int i = firstEscapableChar; i < textLength; i++) { char textCharacter = text.charAt(i); if (isEscapable(textCharacter)) { sb.append(PgCopyConstants.ESCAPE_CHAR); sb.append(textCharacter); } else { sb.append(textCharacter); } } return sb.toString(); } } | PgCopyEscaper { public String escapeForStdIn(String text) { if (text == null) { return null; } int firstEscapableChar = findFirstEscapableChar(text); if (firstEscapableChar == -1) { return text; } StringBuilder sb = new StringBuilder(text.substring(0, firstEscapableChar)); int textLength = text.length(); for (int i = firstEscapableChar; i < textLength; i++) { char textCharacter = text.charAt(i); if (isEscapable(textCharacter)) { sb.append(PgCopyConstants.ESCAPE_CHAR); sb.append(textCharacter); } else { sb.append(textCharacter); } } return sb.toString(); } String escapeForStdIn(String text); } | PgCopyEscaper { public String escapeForStdIn(String text) { if (text == null) { return null; } int firstEscapableChar = findFirstEscapableChar(text); if (firstEscapableChar == -1) { return text; } StringBuilder sb = new StringBuilder(text.substring(0, firstEscapableChar)); int textLength = text.length(); for (int i = firstEscapableChar; i < textLength; i++) { char textCharacter = text.charAt(i); if (isEscapable(textCharacter)) { sb.append(PgCopyConstants.ESCAPE_CHAR); sb.append(textCharacter); } else { sb.append(textCharacter); } } return sb.toString(); } String escapeForStdIn(String text); } |
@Test public void enumOrdinalTest() { EntityFieldType type = getField("enumOrdinal"); assertFalse(type.isPrimitive()); assertEquals(FieldTypeEnum.ENUMORDINAL, type.getFieldType()); } | public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } |
@Test public void enumStringTest() { EntityFieldType type = getField("enumString"); assertFalse(type.isPrimitive()); assertEquals(FieldTypeEnum.ENUMSTRING, type.getFieldType()); } | public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } | FieldTypeInspector { public Optional<EntityFieldType> getFieldType(Class<?> javaType) { FieldTypeEnum value = null; if (Long.class.equals(javaType) || long.class.equals(javaType)) { value = FieldTypeEnum.LONG; } else if (Boolean.class.equals(javaType) || boolean.class.equals(javaType)) { value = FieldTypeEnum.BOOLEAN; } else if (Byte.class.equals(javaType) || byte.class.equals(javaType)) { value = FieldTypeEnum.BYTE; } else if (Character.class.equals(javaType) || char.class.equals(javaType)) { value = FieldTypeEnum.CHAR; } else if (Double.class.equals(javaType) || double.class.equals(javaType)) { value = FieldTypeEnum.DOUBLE; } else if (Float.class.equals(javaType) || float.class.equals(javaType)) { value = FieldTypeEnum.FLOAT; } else if (Integer.class.equals(javaType) || int.class.equals(javaType)) { value = FieldTypeEnum.INT; } else if (Short.class.equals(javaType) || short.class.equals(javaType)) { value = FieldTypeEnum.SHORT; } else if (String.class.equals(javaType)) { value = FieldTypeEnum.STRING; } else if (java.sql.Timestamp.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIMESTAMP; } else if (java.sql.Time.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.TIME; } else if (java.sql.Date.class.isAssignableFrom(javaType)) { value = FieldTypeEnum.DATE; } else if (BigDecimal.class.equals(javaType)) { value = FieldTypeEnum.BIGDECIMAL; } else if (BigInteger.class.equals(javaType)) { value = FieldTypeEnum.BIGINTEGER; } else if (LocalDate.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATE; } else if (LocalTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALTIME; } else if (LocalDateTime.class.equals(javaType)) { value = FieldTypeEnum.LOCALDATETIME; } if (value == null) { return Optional.empty(); } return Optional.of(new EntityFieldType(value, javaType.isPrimitive())); } Optional<EntityFieldType> getFieldType(Class<?> javaType); } |
@Test public void testEscapeLineTermination() { String text = "Some text with \nmore than one line\n"; String escaped = escaper.escapeForStdIn(text); assertEquals("Some text with " + ESCAPED_BY_CHAR + LINE_TERMINATED_CHAR + "more than one line" + ESCAPED_BY_CHAR + LINE_TERMINATED_CHAR, escaped); logger.info("FROM:"); logger.info(text); logger.info("TO:"); logger.info(escaped); } | public String escapeForStdIn(String text) { if (text == null) { return null; } int firstEscapableChar = findFirstEscapableChar(text); if (firstEscapableChar == -1) { return text; } StringBuilder sb = new StringBuilder(text.substring(0, firstEscapableChar)); int textLength = text.length(); for (int i = firstEscapableChar; i < textLength; i++) { char textCharacter = text.charAt(i); if (isEscapable(textCharacter)) { sb.append(PgCopyConstants.ESCAPE_CHAR); sb.append(textCharacter); } else { sb.append(textCharacter); } } return sb.toString(); } | PgCopyEscaper { public String escapeForStdIn(String text) { if (text == null) { return null; } int firstEscapableChar = findFirstEscapableChar(text); if (firstEscapableChar == -1) { return text; } StringBuilder sb = new StringBuilder(text.substring(0, firstEscapableChar)); int textLength = text.length(); for (int i = firstEscapableChar; i < textLength; i++) { char textCharacter = text.charAt(i); if (isEscapable(textCharacter)) { sb.append(PgCopyConstants.ESCAPE_CHAR); sb.append(textCharacter); } else { sb.append(textCharacter); } } return sb.toString(); } } | PgCopyEscaper { public String escapeForStdIn(String text) { if (text == null) { return null; } int firstEscapableChar = findFirstEscapableChar(text); if (firstEscapableChar == -1) { return text; } StringBuilder sb = new StringBuilder(text.substring(0, firstEscapableChar)); int textLength = text.length(); for (int i = firstEscapableChar; i < textLength; i++) { char textCharacter = text.charAt(i); if (isEscapable(textCharacter)) { sb.append(PgCopyConstants.ESCAPE_CHAR); sb.append(textCharacter); } else { sb.append(textCharacter); } } return sb.toString(); } } | PgCopyEscaper { public String escapeForStdIn(String text) { if (text == null) { return null; } int firstEscapableChar = findFirstEscapableChar(text); if (firstEscapableChar == -1) { return text; } StringBuilder sb = new StringBuilder(text.substring(0, firstEscapableChar)); int textLength = text.length(); for (int i = firstEscapableChar; i < textLength; i++) { char textCharacter = text.charAt(i); if (isEscapable(textCharacter)) { sb.append(PgCopyConstants.ESCAPE_CHAR); sb.append(textCharacter); } else { sb.append(textCharacter); } } return sb.toString(); } String escapeForStdIn(String text); } | PgCopyEscaper { public String escapeForStdIn(String text) { if (text == null) { return null; } int firstEscapableChar = findFirstEscapableChar(text); if (firstEscapableChar == -1) { return text; } StringBuilder sb = new StringBuilder(text.substring(0, firstEscapableChar)); int textLength = text.length(); for (int i = firstEscapableChar; i < textLength; i++) { char textCharacter = text.charAt(i); if (isEscapable(textCharacter)) { sb.append(PgCopyConstants.ESCAPE_CHAR); sb.append(textCharacter); } else { sb.append(textCharacter); } } return sb.toString(); } String escapeForStdIn(String text); } |
@Test public void testEscapeLineTerminationWithCarriageReturn() { String text = "Some text with \r\nmore than one line\r\n"; String escaped = escaper.escapeForStdIn(text); String expected = "Some text with " + ESCAPED_BY_CHAR + CARRIAGE_RETURN_CHAR + ESCAPED_BY_CHAR + LINE_TERMINATED_CHAR + "more than one line" + ESCAPED_BY_CHAR + CARRIAGE_RETURN_CHAR + ESCAPED_BY_CHAR + LINE_TERMINATED_CHAR; assertEquals(expected, escaped); logger.info("FROM:"); logger.info(text); logger.info("TO:"); logger.info(escaped); } | public String escapeForStdIn(String text) { if (text == null) { return null; } int firstEscapableChar = findFirstEscapableChar(text); if (firstEscapableChar == -1) { return text; } StringBuilder sb = new StringBuilder(text.substring(0, firstEscapableChar)); int textLength = text.length(); for (int i = firstEscapableChar; i < textLength; i++) { char textCharacter = text.charAt(i); if (isEscapable(textCharacter)) { sb.append(PgCopyConstants.ESCAPE_CHAR); sb.append(textCharacter); } else { sb.append(textCharacter); } } return sb.toString(); } | PgCopyEscaper { public String escapeForStdIn(String text) { if (text == null) { return null; } int firstEscapableChar = findFirstEscapableChar(text); if (firstEscapableChar == -1) { return text; } StringBuilder sb = new StringBuilder(text.substring(0, firstEscapableChar)); int textLength = text.length(); for (int i = firstEscapableChar; i < textLength; i++) { char textCharacter = text.charAt(i); if (isEscapable(textCharacter)) { sb.append(PgCopyConstants.ESCAPE_CHAR); sb.append(textCharacter); } else { sb.append(textCharacter); } } return sb.toString(); } } | PgCopyEscaper { public String escapeForStdIn(String text) { if (text == null) { return null; } int firstEscapableChar = findFirstEscapableChar(text); if (firstEscapableChar == -1) { return text; } StringBuilder sb = new StringBuilder(text.substring(0, firstEscapableChar)); int textLength = text.length(); for (int i = firstEscapableChar; i < textLength; i++) { char textCharacter = text.charAt(i); if (isEscapable(textCharacter)) { sb.append(PgCopyConstants.ESCAPE_CHAR); sb.append(textCharacter); } else { sb.append(textCharacter); } } return sb.toString(); } } | PgCopyEscaper { public String escapeForStdIn(String text) { if (text == null) { return null; } int firstEscapableChar = findFirstEscapableChar(text); if (firstEscapableChar == -1) { return text; } StringBuilder sb = new StringBuilder(text.substring(0, firstEscapableChar)); int textLength = text.length(); for (int i = firstEscapableChar; i < textLength; i++) { char textCharacter = text.charAt(i); if (isEscapable(textCharacter)) { sb.append(PgCopyConstants.ESCAPE_CHAR); sb.append(textCharacter); } else { sb.append(textCharacter); } } return sb.toString(); } String escapeForStdIn(String text); } | PgCopyEscaper { public String escapeForStdIn(String text) { if (text == null) { return null; } int firstEscapableChar = findFirstEscapableChar(text); if (firstEscapableChar == -1) { return text; } StringBuilder sb = new StringBuilder(text.substring(0, firstEscapableChar)); int textLength = text.length(); for (int i = firstEscapableChar; i < textLength; i++) { char textCharacter = text.charAt(i); if (isEscapable(textCharacter)) { sb.append(PgCopyConstants.ESCAPE_CHAR); sb.append(textCharacter); } else { sb.append(textCharacter); } } return sb.toString(); } String escapeForStdIn(String text); } |
@Test public void testCompleteQuery() { SqlBuilder sqlBuilder = new SqlBuilder(buildEntity()); String sql = sqlBuilder.build(); String expectedSql = "LOAD DATA LOCAL INFILE '' INTO TABLE simple_table " + "CHARACTER SET UTF8 FIELDS TERMINATED BY '\t' ENCLOSED BY '' " + "ESCAPED BY '\\\\' LINES TERMINATED BY '\n' STARTING BY '' " + "(column1, column2)"; assertEquals(expectedSql, sql); } | public String build() { addLoadDataIntoTable(); addFileConfig(); addColumnNames(); return getSql(); } | SqlBuilder { public String build() { addLoadDataIntoTable(); addFileConfig(); addColumnNames(); return getSql(); } } | SqlBuilder { public String build() { addLoadDataIntoTable(); addFileConfig(); addColumnNames(); return getSql(); } SqlBuilder(EntityInfo entityInfo); } | SqlBuilder { public String build() { addLoadDataIntoTable(); addFileConfig(); addColumnNames(); return getSql(); } SqlBuilder(EntityInfo entityInfo); String build(); void addLoadDataIntoTable(); void addFileConfig(); void addColumnNames(); String getSql(); } | SqlBuilder { public String build() { addLoadDataIntoTable(); addFileConfig(); addColumnNames(); return getSql(); } SqlBuilder(EntityInfo entityInfo); String build(); void addLoadDataIntoTable(); void addFileConfig(); void addColumnNames(); String getSql(); } |
@Test public void testNoEscapeNeeded() { String text = "Some text with no escape neeed"; String escaped = escaper.escapeForLoadFile(text); assertEquals(text, escaped); } | public String escapeForLoadFile(String text) { if (text == null) { return null; } int firstEscapableChar = findFirstEscapableChar(text); if (firstEscapableChar == -1) { return text; } StringBuilder sb = new StringBuilder(text.substring(0, firstEscapableChar)); int textLength = text.length(); for (int i = firstEscapableChar; i < textLength; i++) { char textCharacter = text.charAt(i); if (isEscapable(textCharacter)) { sb.append(ESCAPED_BY_CHAR); sb.append(textCharacter); } else { sb.append(textCharacter); } } return sb.toString(); } | LoadDataEscaper { public String escapeForLoadFile(String text) { if (text == null) { return null; } int firstEscapableChar = findFirstEscapableChar(text); if (firstEscapableChar == -1) { return text; } StringBuilder sb = new StringBuilder(text.substring(0, firstEscapableChar)); int textLength = text.length(); for (int i = firstEscapableChar; i < textLength; i++) { char textCharacter = text.charAt(i); if (isEscapable(textCharacter)) { sb.append(ESCAPED_BY_CHAR); sb.append(textCharacter); } else { sb.append(textCharacter); } } return sb.toString(); } } | LoadDataEscaper { public String escapeForLoadFile(String text) { if (text == null) { return null; } int firstEscapableChar = findFirstEscapableChar(text); if (firstEscapableChar == -1) { return text; } StringBuilder sb = new StringBuilder(text.substring(0, firstEscapableChar)); int textLength = text.length(); for (int i = firstEscapableChar; i < textLength; i++) { char textCharacter = text.charAt(i); if (isEscapable(textCharacter)) { sb.append(ESCAPED_BY_CHAR); sb.append(textCharacter); } else { sb.append(textCharacter); } } return sb.toString(); } } | LoadDataEscaper { public String escapeForLoadFile(String text) { if (text == null) { return null; } int firstEscapableChar = findFirstEscapableChar(text); if (firstEscapableChar == -1) { return text; } StringBuilder sb = new StringBuilder(text.substring(0, firstEscapableChar)); int textLength = text.length(); for (int i = firstEscapableChar; i < textLength; i++) { char textCharacter = text.charAt(i); if (isEscapable(textCharacter)) { sb.append(ESCAPED_BY_CHAR); sb.append(textCharacter); } else { sb.append(textCharacter); } } return sb.toString(); } String escapeForLoadFile(String text); } | LoadDataEscaper { public String escapeForLoadFile(String text) { if (text == null) { return null; } int firstEscapableChar = findFirstEscapableChar(text); if (firstEscapableChar == -1) { return text; } StringBuilder sb = new StringBuilder(text.substring(0, firstEscapableChar)); int textLength = text.length(); for (int i = firstEscapableChar; i < textLength; i++) { char textCharacter = text.charAt(i); if (isEscapable(textCharacter)) { sb.append(ESCAPED_BY_CHAR); sb.append(textCharacter); } else { sb.append(textCharacter); } } return sb.toString(); } String escapeForLoadFile(String text); } |
@Test public void testEscapeEscapedByChar() { String text = "Some text with some \\ escape char \\\\ to change"; String escaped = escaper.escapeForLoadFile(text); assertEquals("Some text with some " + ESCAPED_BY_CHAR + ESCAPED_BY_CHAR + " escape char " + ESCAPED_BY_CHAR + ESCAPED_BY_CHAR + ESCAPED_BY_CHAR + ESCAPED_BY_CHAR + " to change", escaped); logger.info("FROM:"); logger.info(text); logger.info("TO:"); logger.info(escaped); } | public String escapeForLoadFile(String text) { if (text == null) { return null; } int firstEscapableChar = findFirstEscapableChar(text); if (firstEscapableChar == -1) { return text; } StringBuilder sb = new StringBuilder(text.substring(0, firstEscapableChar)); int textLength = text.length(); for (int i = firstEscapableChar; i < textLength; i++) { char textCharacter = text.charAt(i); if (isEscapable(textCharacter)) { sb.append(ESCAPED_BY_CHAR); sb.append(textCharacter); } else { sb.append(textCharacter); } } return sb.toString(); } | LoadDataEscaper { public String escapeForLoadFile(String text) { if (text == null) { return null; } int firstEscapableChar = findFirstEscapableChar(text); if (firstEscapableChar == -1) { return text; } StringBuilder sb = new StringBuilder(text.substring(0, firstEscapableChar)); int textLength = text.length(); for (int i = firstEscapableChar; i < textLength; i++) { char textCharacter = text.charAt(i); if (isEscapable(textCharacter)) { sb.append(ESCAPED_BY_CHAR); sb.append(textCharacter); } else { sb.append(textCharacter); } } return sb.toString(); } } | LoadDataEscaper { public String escapeForLoadFile(String text) { if (text == null) { return null; } int firstEscapableChar = findFirstEscapableChar(text); if (firstEscapableChar == -1) { return text; } StringBuilder sb = new StringBuilder(text.substring(0, firstEscapableChar)); int textLength = text.length(); for (int i = firstEscapableChar; i < textLength; i++) { char textCharacter = text.charAt(i); if (isEscapable(textCharacter)) { sb.append(ESCAPED_BY_CHAR); sb.append(textCharacter); } else { sb.append(textCharacter); } } return sb.toString(); } } | LoadDataEscaper { public String escapeForLoadFile(String text) { if (text == null) { return null; } int firstEscapableChar = findFirstEscapableChar(text); if (firstEscapableChar == -1) { return text; } StringBuilder sb = new StringBuilder(text.substring(0, firstEscapableChar)); int textLength = text.length(); for (int i = firstEscapableChar; i < textLength; i++) { char textCharacter = text.charAt(i); if (isEscapable(textCharacter)) { sb.append(ESCAPED_BY_CHAR); sb.append(textCharacter); } else { sb.append(textCharacter); } } return sb.toString(); } String escapeForLoadFile(String text); } | LoadDataEscaper { public String escapeForLoadFile(String text) { if (text == null) { return null; } int firstEscapableChar = findFirstEscapableChar(text); if (firstEscapableChar == -1) { return text; } StringBuilder sb = new StringBuilder(text.substring(0, firstEscapableChar)); int textLength = text.length(); for (int i = firstEscapableChar; i < textLength; i++) { char textCharacter = text.charAt(i); if (isEscapable(textCharacter)) { sb.append(ESCAPED_BY_CHAR); sb.append(textCharacter); } else { sb.append(textCharacter); } } return sb.toString(); } String escapeForLoadFile(String text); } |
@Test public void testEscapeLineTermination() { String text = "Some text with \nmore than one line\n"; String escaped = escaper.escapeForLoadFile(text); assertEquals("Some text with " + ESCAPED_BY_CHAR + LINE_TERMINATED_CHAR + "more than one line" + ESCAPED_BY_CHAR + LINE_TERMINATED_CHAR, escaped); logger.info("FROM:"); logger.info(text); logger.info("TO:"); logger.info(escaped); } | public String escapeForLoadFile(String text) { if (text == null) { return null; } int firstEscapableChar = findFirstEscapableChar(text); if (firstEscapableChar == -1) { return text; } StringBuilder sb = new StringBuilder(text.substring(0, firstEscapableChar)); int textLength = text.length(); for (int i = firstEscapableChar; i < textLength; i++) { char textCharacter = text.charAt(i); if (isEscapable(textCharacter)) { sb.append(ESCAPED_BY_CHAR); sb.append(textCharacter); } else { sb.append(textCharacter); } } return sb.toString(); } | LoadDataEscaper { public String escapeForLoadFile(String text) { if (text == null) { return null; } int firstEscapableChar = findFirstEscapableChar(text); if (firstEscapableChar == -1) { return text; } StringBuilder sb = new StringBuilder(text.substring(0, firstEscapableChar)); int textLength = text.length(); for (int i = firstEscapableChar; i < textLength; i++) { char textCharacter = text.charAt(i); if (isEscapable(textCharacter)) { sb.append(ESCAPED_BY_CHAR); sb.append(textCharacter); } else { sb.append(textCharacter); } } return sb.toString(); } } | LoadDataEscaper { public String escapeForLoadFile(String text) { if (text == null) { return null; } int firstEscapableChar = findFirstEscapableChar(text); if (firstEscapableChar == -1) { return text; } StringBuilder sb = new StringBuilder(text.substring(0, firstEscapableChar)); int textLength = text.length(); for (int i = firstEscapableChar; i < textLength; i++) { char textCharacter = text.charAt(i); if (isEscapable(textCharacter)) { sb.append(ESCAPED_BY_CHAR); sb.append(textCharacter); } else { sb.append(textCharacter); } } return sb.toString(); } } | LoadDataEscaper { public String escapeForLoadFile(String text) { if (text == null) { return null; } int firstEscapableChar = findFirstEscapableChar(text); if (firstEscapableChar == -1) { return text; } StringBuilder sb = new StringBuilder(text.substring(0, firstEscapableChar)); int textLength = text.length(); for (int i = firstEscapableChar; i < textLength; i++) { char textCharacter = text.charAt(i); if (isEscapable(textCharacter)) { sb.append(ESCAPED_BY_CHAR); sb.append(textCharacter); } else { sb.append(textCharacter); } } return sb.toString(); } String escapeForLoadFile(String text); } | LoadDataEscaper { public String escapeForLoadFile(String text) { if (text == null) { return null; } int firstEscapableChar = findFirstEscapableChar(text); if (firstEscapableChar == -1) { return text; } StringBuilder sb = new StringBuilder(text.substring(0, firstEscapableChar)); int textLength = text.length(); for (int i = firstEscapableChar; i < textLength; i++) { char textCharacter = text.charAt(i); if (isEscapable(textCharacter)) { sb.append(ESCAPED_BY_CHAR); sb.append(textCharacter); } else { sb.append(textCharacter); } } return sb.toString(); } String escapeForLoadFile(String text); } |
@Test public void test() { final URI root1 = URI.create(INTERNAL_URI_PREFIX + "/"); assertNull("parent should be null", UriUtils.getParent(root1)); } | public static URI getParent(final URI uri) { if (isRoot(uri)) { return null; } else { final URI parent = uri.getPath().endsWith("/") ? uri.resolve("..") : uri.resolve("."); final String parentStr = parent.toString(); return isRoot(parent) ? parent : URI.create(parentStr.substring(0, parentStr.length() - 1)); } } | UriUtils { public static URI getParent(final URI uri) { if (isRoot(uri)) { return null; } else { final URI parent = uri.getPath().endsWith("/") ? uri.resolve("..") : uri.resolve("."); final String parentStr = parent.toString(); return isRoot(parent) ? parent : URI.create(parentStr.substring(0, parentStr.length() - 1)); } } } | UriUtils { public static URI getParent(final URI uri) { if (isRoot(uri)) { return null; } else { final URI parent = uri.getPath().endsWith("/") ? uri.resolve("..") : uri.resolve("."); final String parentStr = parent.toString(); return isRoot(parent) ? parent : URI.create(parentStr.substring(0, parentStr.length() - 1)); } } private UriUtils(); } | UriUtils { public static URI getParent(final URI uri) { if (isRoot(uri)) { return null; } else { final URI parent = uri.getPath().endsWith("/") ? uri.resolve("..") : uri.resolve("."); final String parentStr = parent.toString(); return isRoot(parent) ? parent : URI.create(parentStr.substring(0, parentStr.length() - 1)); } } private UriUtils(); static URI getParent(final URI uri); } | UriUtils { public static URI getParent(final URI uri) { if (isRoot(uri)) { return null; } else { final URI parent = uri.getPath().endsWith("/") ? uri.resolve("..") : uri.resolve("."); final String parentStr = parent.toString(); return isRoot(parent) ? parent : URI.create(parentStr.substring(0, parentStr.length() - 1)); } } private UriUtils(); static URI getParent(final URI uri); } |
@Test public void testChildOfRoot() { final URI uri = URI.create(INTERNAL_URI_PREFIX + "/test"); assertEquals("incorrect parent", URI.create(INTERNAL_URI_PREFIX + "/"), UriUtils.getParent(uri)); } | public static URI getParent(final URI uri) { if (isRoot(uri)) { return null; } else { final URI parent = uri.getPath().endsWith("/") ? uri.resolve("..") : uri.resolve("."); final String parentStr = parent.toString(); return isRoot(parent) ? parent : URI.create(parentStr.substring(0, parentStr.length() - 1)); } } | UriUtils { public static URI getParent(final URI uri) { if (isRoot(uri)) { return null; } else { final URI parent = uri.getPath().endsWith("/") ? uri.resolve("..") : uri.resolve("."); final String parentStr = parent.toString(); return isRoot(parent) ? parent : URI.create(parentStr.substring(0, parentStr.length() - 1)); } } } | UriUtils { public static URI getParent(final URI uri) { if (isRoot(uri)) { return null; } else { final URI parent = uri.getPath().endsWith("/") ? uri.resolve("..") : uri.resolve("."); final String parentStr = parent.toString(); return isRoot(parent) ? parent : URI.create(parentStr.substring(0, parentStr.length() - 1)); } } private UriUtils(); } | UriUtils { public static URI getParent(final URI uri) { if (isRoot(uri)) { return null; } else { final URI parent = uri.getPath().endsWith("/") ? uri.resolve("..") : uri.resolve("."); final String parentStr = parent.toString(); return isRoot(parent) ? parent : URI.create(parentStr.substring(0, parentStr.length() - 1)); } } private UriUtils(); static URI getParent(final URI uri); } | UriUtils { public static URI getParent(final URI uri) { if (isRoot(uri)) { return null; } else { final URI parent = uri.getPath().endsWith("/") ? uri.resolve("..") : uri.resolve("."); final String parentStr = parent.toString(); return isRoot(parent) ? parent : URI.create(parentStr.substring(0, parentStr.length() - 1)); } } private UriUtils(); static URI getParent(final URI uri); } |
@Test public void testGrandchildOfRoot() { final URI uri = URI.create(INTERNAL_URI_PREFIX + "/child/grandchild"); assertEquals("incorrect parent", URI.create(INTERNAL_URI_PREFIX + "/child"), UriUtils.getParent(uri)); } | public static URI getParent(final URI uri) { if (isRoot(uri)) { return null; } else { final URI parent = uri.getPath().endsWith("/") ? uri.resolve("..") : uri.resolve("."); final String parentStr = parent.toString(); return isRoot(parent) ? parent : URI.create(parentStr.substring(0, parentStr.length() - 1)); } } | UriUtils { public static URI getParent(final URI uri) { if (isRoot(uri)) { return null; } else { final URI parent = uri.getPath().endsWith("/") ? uri.resolve("..") : uri.resolve("."); final String parentStr = parent.toString(); return isRoot(parent) ? parent : URI.create(parentStr.substring(0, parentStr.length() - 1)); } } } | UriUtils { public static URI getParent(final URI uri) { if (isRoot(uri)) { return null; } else { final URI parent = uri.getPath().endsWith("/") ? uri.resolve("..") : uri.resolve("."); final String parentStr = parent.toString(); return isRoot(parent) ? parent : URI.create(parentStr.substring(0, parentStr.length() - 1)); } } private UriUtils(); } | UriUtils { public static URI getParent(final URI uri) { if (isRoot(uri)) { return null; } else { final URI parent = uri.getPath().endsWith("/") ? uri.resolve("..") : uri.resolve("."); final String parentStr = parent.toString(); return isRoot(parent) ? parent : URI.create(parentStr.substring(0, parentStr.length() - 1)); } } private UriUtils(); static URI getParent(final URI uri); } | UriUtils { public static URI getParent(final URI uri) { if (isRoot(uri)) { return null; } else { final URI parent = uri.getPath().endsWith("/") ? uri.resolve("..") : uri.resolve("."); final String parentStr = parent.toString(); return isRoot(parent) ? parent : URI.create(parentStr.substring(0, parentStr.length() - 1)); } } private UriUtils(); static URI getParent(final URI uri); } |
@Test void testFilterLetters() { List<Character> characters = filterLetters(asList('a', 'b', '1')); assertThat(characters).containsExactly('a', 'b'); } | public static List<Character> filterLetters(List<Character> characters) { return characters.stream().filter(Character::isLetter).collect(toList()); } | CharacterUtils { public static List<Character> filterLetters(List<Character> characters) { return characters.stream().filter(Character::isLetter).collect(toList()); } } | CharacterUtils { public static List<Character> filterLetters(List<Character> characters) { return characters.stream().filter(Character::isLetter).collect(toList()); } private CharacterUtils(); } | CharacterUtils { public static List<Character> filterLetters(List<Character> characters) { return characters.stream().filter(Character::isLetter).collect(toList()); } private CharacterUtils(); static List<Character> collectPrintableCharactersOf(Charset charset); static List<Character> filterLetters(List<Character> characters); } | CharacterUtils { public static List<Character> filterLetters(List<Character> characters) { return characters.stream().filter(Character::isLetter).collect(toList()); } private CharacterUtils(); static List<Character> collectPrintableCharactersOf(Charset charset); static List<Character> filterLetters(List<Character> characters); } |
@Test void generatedValueShouldBeWithinSpecifiedRange() { BigDecimal randomValue = randomizer.getRandomValue(); assertThat(randomValue.doubleValue()).isBetween(min, max); } | @Override public BigDecimal getRandomValue() { Double delegateRandomValue = delegate.getRandomValue(); BigDecimal randomValue = new BigDecimal(delegateRandomValue); if (scale != null) { randomValue = randomValue.setScale(this.scale, this.roundingMode); } return randomValue; } | BigDecimalRangeRandomizer implements Randomizer<BigDecimal> { @Override public BigDecimal getRandomValue() { Double delegateRandomValue = delegate.getRandomValue(); BigDecimal randomValue = new BigDecimal(delegateRandomValue); if (scale != null) { randomValue = randomValue.setScale(this.scale, this.roundingMode); } return randomValue; } } | BigDecimalRangeRandomizer implements Randomizer<BigDecimal> { @Override public BigDecimal getRandomValue() { Double delegateRandomValue = delegate.getRandomValue(); BigDecimal randomValue = new BigDecimal(delegateRandomValue); if (scale != null) { randomValue = randomValue.setScale(this.scale, this.roundingMode); } return randomValue; } BigDecimalRangeRandomizer(final Double min, final Double max); BigDecimalRangeRandomizer(final Double min, final Double max, final long seed); BigDecimalRangeRandomizer(final Double min, final Double max, final Integer scale); BigDecimalRangeRandomizer(final Double min, final Double max, final Integer scale, final RoundingMode roundingMode); BigDecimalRangeRandomizer(final Double min, final Double max, final long seed, final Integer scale); BigDecimalRangeRandomizer(final Double min, final Double max, final long seed, final Integer scale, final RoundingMode roundingMode); } | BigDecimalRangeRandomizer implements Randomizer<BigDecimal> { @Override public BigDecimal getRandomValue() { Double delegateRandomValue = delegate.getRandomValue(); BigDecimal randomValue = new BigDecimal(delegateRandomValue); if (scale != null) { randomValue = randomValue.setScale(this.scale, this.roundingMode); } return randomValue; } BigDecimalRangeRandomizer(final Double min, final Double max); BigDecimalRangeRandomizer(final Double min, final Double max, final long seed); BigDecimalRangeRandomizer(final Double min, final Double max, final Integer scale); BigDecimalRangeRandomizer(final Double min, final Double max, final Integer scale, final RoundingMode roundingMode); BigDecimalRangeRandomizer(final Double min, final Double max, final long seed, final Integer scale); BigDecimalRangeRandomizer(final Double min, final Double max, final long seed, final Integer scale, final RoundingMode roundingMode); static BigDecimalRangeRandomizer aNewBigDecimalRangeRandomizer(final Double min, final Double max); static BigDecimalRangeRandomizer aNewBigDecimalRangeRandomizer(final Double min, final Double max, final long seed); static BigDecimalRangeRandomizer aNewBigDecimalRangeRandomizer(final Double min, final Double max, final Integer scale); static BigDecimalRangeRandomizer aNewBigDecimalRangeRandomizer(final Double min, final Double max, final Integer scale, final RoundingMode roundingMode); static BigDecimalRangeRandomizer aNewBigDecimalRangeRandomizer(final Double min, final Double max, final long seed, final Integer scale); static BigDecimalRangeRandomizer aNewBigDecimalRangeRandomizer(final Double min, final Double max, final long seed, final Integer scale, final RoundingMode roundingMode); @Override BigDecimal getRandomValue(); } | BigDecimalRangeRandomizer implements Randomizer<BigDecimal> { @Override public BigDecimal getRandomValue() { Double delegateRandomValue = delegate.getRandomValue(); BigDecimal randomValue = new BigDecimal(delegateRandomValue); if (scale != null) { randomValue = randomValue.setScale(this.scale, this.roundingMode); } return randomValue; } BigDecimalRangeRandomizer(final Double min, final Double max); BigDecimalRangeRandomizer(final Double min, final Double max, final long seed); BigDecimalRangeRandomizer(final Double min, final Double max, final Integer scale); BigDecimalRangeRandomizer(final Double min, final Double max, final Integer scale, final RoundingMode roundingMode); BigDecimalRangeRandomizer(final Double min, final Double max, final long seed, final Integer scale); BigDecimalRangeRandomizer(final Double min, final Double max, final long seed, final Integer scale, final RoundingMode roundingMode); static BigDecimalRangeRandomizer aNewBigDecimalRangeRandomizer(final Double min, final Double max); static BigDecimalRangeRandomizer aNewBigDecimalRangeRandomizer(final Double min, final Double max, final long seed); static BigDecimalRangeRandomizer aNewBigDecimalRangeRandomizer(final Double min, final Double max, final Integer scale); static BigDecimalRangeRandomizer aNewBigDecimalRangeRandomizer(final Double min, final Double max, final Integer scale, final RoundingMode roundingMode); static BigDecimalRangeRandomizer aNewBigDecimalRangeRandomizer(final Double min, final Double max, final long seed, final Integer scale); static BigDecimalRangeRandomizer aNewBigDecimalRangeRandomizer(final Double min, final Double max, final long seed, final Integer scale, final RoundingMode roundingMode); @Override BigDecimal getRandomValue(); } |
@Test void whenSpecifiedMinValueIsAfterMaxValueThenThrowIllegalArgumentException() { assertThatThrownBy(() -> aNewBigDecimalRangeRandomizer(max, min)).isInstanceOf(IllegalArgumentException.class); } | public static BigDecimalRangeRandomizer aNewBigDecimalRangeRandomizer(final Double min, final Double max) { return new BigDecimalRangeRandomizer(min, max); } | BigDecimalRangeRandomizer implements Randomizer<BigDecimal> { public static BigDecimalRangeRandomizer aNewBigDecimalRangeRandomizer(final Double min, final Double max) { return new BigDecimalRangeRandomizer(min, max); } } | BigDecimalRangeRandomizer implements Randomizer<BigDecimal> { public static BigDecimalRangeRandomizer aNewBigDecimalRangeRandomizer(final Double min, final Double max) { return new BigDecimalRangeRandomizer(min, max); } BigDecimalRangeRandomizer(final Double min, final Double max); BigDecimalRangeRandomizer(final Double min, final Double max, final long seed); BigDecimalRangeRandomizer(final Double min, final Double max, final Integer scale); BigDecimalRangeRandomizer(final Double min, final Double max, final Integer scale, final RoundingMode roundingMode); BigDecimalRangeRandomizer(final Double min, final Double max, final long seed, final Integer scale); BigDecimalRangeRandomizer(final Double min, final Double max, final long seed, final Integer scale, final RoundingMode roundingMode); } | BigDecimalRangeRandomizer implements Randomizer<BigDecimal> { public static BigDecimalRangeRandomizer aNewBigDecimalRangeRandomizer(final Double min, final Double max) { return new BigDecimalRangeRandomizer(min, max); } BigDecimalRangeRandomizer(final Double min, final Double max); BigDecimalRangeRandomizer(final Double min, final Double max, final long seed); BigDecimalRangeRandomizer(final Double min, final Double max, final Integer scale); BigDecimalRangeRandomizer(final Double min, final Double max, final Integer scale, final RoundingMode roundingMode); BigDecimalRangeRandomizer(final Double min, final Double max, final long seed, final Integer scale); BigDecimalRangeRandomizer(final Double min, final Double max, final long seed, final Integer scale, final RoundingMode roundingMode); static BigDecimalRangeRandomizer aNewBigDecimalRangeRandomizer(final Double min, final Double max); static BigDecimalRangeRandomizer aNewBigDecimalRangeRandomizer(final Double min, final Double max, final long seed); static BigDecimalRangeRandomizer aNewBigDecimalRangeRandomizer(final Double min, final Double max, final Integer scale); static BigDecimalRangeRandomizer aNewBigDecimalRangeRandomizer(final Double min, final Double max, final Integer scale, final RoundingMode roundingMode); static BigDecimalRangeRandomizer aNewBigDecimalRangeRandomizer(final Double min, final Double max, final long seed, final Integer scale); static BigDecimalRangeRandomizer aNewBigDecimalRangeRandomizer(final Double min, final Double max, final long seed, final Integer scale, final RoundingMode roundingMode); @Override BigDecimal getRandomValue(); } | BigDecimalRangeRandomizer implements Randomizer<BigDecimal> { public static BigDecimalRangeRandomizer aNewBigDecimalRangeRandomizer(final Double min, final Double max) { return new BigDecimalRangeRandomizer(min, max); } BigDecimalRangeRandomizer(final Double min, final Double max); BigDecimalRangeRandomizer(final Double min, final Double max, final long seed); BigDecimalRangeRandomizer(final Double min, final Double max, final Integer scale); BigDecimalRangeRandomizer(final Double min, final Double max, final Integer scale, final RoundingMode roundingMode); BigDecimalRangeRandomizer(final Double min, final Double max, final long seed, final Integer scale); BigDecimalRangeRandomizer(final Double min, final Double max, final long seed, final Integer scale, final RoundingMode roundingMode); static BigDecimalRangeRandomizer aNewBigDecimalRangeRandomizer(final Double min, final Double max); static BigDecimalRangeRandomizer aNewBigDecimalRangeRandomizer(final Double min, final Double max, final long seed); static BigDecimalRangeRandomizer aNewBigDecimalRangeRandomizer(final Double min, final Double max, final Integer scale); static BigDecimalRangeRandomizer aNewBigDecimalRangeRandomizer(final Double min, final Double max, final Integer scale, final RoundingMode roundingMode); static BigDecimalRangeRandomizer aNewBigDecimalRangeRandomizer(final Double min, final Double max, final long seed, final Integer scale); static BigDecimalRangeRandomizer aNewBigDecimalRangeRandomizer(final Double min, final Double max, final long seed, final Integer scale, final RoundingMode roundingMode); @Override BigDecimal getRandomValue(); } |
@Test void generatedValueShouldBeWithinSpecifiedRange() { Float randomValue = randomizer.getRandomValue(); assertThat(randomValue).isBetween(min, max); } | @Override public Float getRandomValue() { return (float) nextDouble(min, max); } | FloatRangeRandomizer extends AbstractRangeRandomizer<Float> { @Override public Float getRandomValue() { return (float) nextDouble(min, max); } } | FloatRangeRandomizer extends AbstractRangeRandomizer<Float> { @Override public Float getRandomValue() { return (float) nextDouble(min, max); } FloatRangeRandomizer(final Float min, final Float max); FloatRangeRandomizer(final Float min, final Float max, final long seed); } | FloatRangeRandomizer extends AbstractRangeRandomizer<Float> { @Override public Float getRandomValue() { return (float) nextDouble(min, max); } FloatRangeRandomizer(final Float min, final Float max); FloatRangeRandomizer(final Float min, final Float max, final long seed); static FloatRangeRandomizer aNewFloatRangeRandomizer(final Float min, final Float max); static FloatRangeRandomizer aNewFloatRangeRandomizer(final Float min, final Float max, final long seed); @Override Float getRandomValue(); } | FloatRangeRandomizer extends AbstractRangeRandomizer<Float> { @Override public Float getRandomValue() { return (float) nextDouble(min, max); } FloatRangeRandomizer(final Float min, final Float max); FloatRangeRandomizer(final Float min, final Float max, final long seed); static FloatRangeRandomizer aNewFloatRangeRandomizer(final Float min, final Float max); static FloatRangeRandomizer aNewFloatRangeRandomizer(final Float min, final Float max, final long seed); @Override Float getRandomValue(); } |
@Test void whenSpecifiedMinValueIsAfterMaxValueThenThrowIllegalArgumentException() { assertThatThrownBy(() -> aNewFloatRangeRandomizer(max, min)).isInstanceOf(IllegalArgumentException.class); } | public static FloatRangeRandomizer aNewFloatRangeRandomizer(final Float min, final Float max) { return new FloatRangeRandomizer(min, max); } | FloatRangeRandomizer extends AbstractRangeRandomizer<Float> { public static FloatRangeRandomizer aNewFloatRangeRandomizer(final Float min, final Float max) { return new FloatRangeRandomizer(min, max); } } | FloatRangeRandomizer extends AbstractRangeRandomizer<Float> { public static FloatRangeRandomizer aNewFloatRangeRandomizer(final Float min, final Float max) { return new FloatRangeRandomizer(min, max); } FloatRangeRandomizer(final Float min, final Float max); FloatRangeRandomizer(final Float min, final Float max, final long seed); } | FloatRangeRandomizer extends AbstractRangeRandomizer<Float> { public static FloatRangeRandomizer aNewFloatRangeRandomizer(final Float min, final Float max) { return new FloatRangeRandomizer(min, max); } FloatRangeRandomizer(final Float min, final Float max); FloatRangeRandomizer(final Float min, final Float max, final long seed); static FloatRangeRandomizer aNewFloatRangeRandomizer(final Float min, final Float max); static FloatRangeRandomizer aNewFloatRangeRandomizer(final Float min, final Float max, final long seed); @Override Float getRandomValue(); } | FloatRangeRandomizer extends AbstractRangeRandomizer<Float> { public static FloatRangeRandomizer aNewFloatRangeRandomizer(final Float min, final Float max) { return new FloatRangeRandomizer(min, max); } FloatRangeRandomizer(final Float min, final Float max); FloatRangeRandomizer(final Float min, final Float max, final long seed); static FloatRangeRandomizer aNewFloatRangeRandomizer(final Float min, final Float max); static FloatRangeRandomizer aNewFloatRangeRandomizer(final Float min, final Float max, final long seed); @Override Float getRandomValue(); } |
@Test void generatedZonedDateTimeShouldNotBeNull() { assertThat(randomizer.getRandomValue()).isNotNull(); } | @Override public ZonedDateTime getRandomValue() { long minSeconds = min.toEpochSecond(); long maxSeconds = max.toEpochSecond(); long seconds = (long) nextDouble(minSeconds, maxSeconds); int minNanoSeconds = min.getNano(); int maxNanoSeconds = max.getNano(); long nanoSeconds = (long) nextDouble(minNanoSeconds, maxNanoSeconds); return ZonedDateTime.ofInstant(Instant.ofEpochSecond(seconds, nanoSeconds), min.getZone()); } | ZonedDateTimeRangeRandomizer extends AbstractRangeRandomizer<ZonedDateTime> { @Override public ZonedDateTime getRandomValue() { long minSeconds = min.toEpochSecond(); long maxSeconds = max.toEpochSecond(); long seconds = (long) nextDouble(minSeconds, maxSeconds); int minNanoSeconds = min.getNano(); int maxNanoSeconds = max.getNano(); long nanoSeconds = (long) nextDouble(minNanoSeconds, maxNanoSeconds); return ZonedDateTime.ofInstant(Instant.ofEpochSecond(seconds, nanoSeconds), min.getZone()); } } | ZonedDateTimeRangeRandomizer extends AbstractRangeRandomizer<ZonedDateTime> { @Override public ZonedDateTime getRandomValue() { long minSeconds = min.toEpochSecond(); long maxSeconds = max.toEpochSecond(); long seconds = (long) nextDouble(minSeconds, maxSeconds); int minNanoSeconds = min.getNano(); int maxNanoSeconds = max.getNano(); long nanoSeconds = (long) nextDouble(minNanoSeconds, maxNanoSeconds); return ZonedDateTime.ofInstant(Instant.ofEpochSecond(seconds, nanoSeconds), min.getZone()); } ZonedDateTimeRangeRandomizer(final ZonedDateTime min, final ZonedDateTime max); ZonedDateTimeRangeRandomizer(final ZonedDateTime min, final ZonedDateTime max, final long seed); } | ZonedDateTimeRangeRandomizer extends AbstractRangeRandomizer<ZonedDateTime> { @Override public ZonedDateTime getRandomValue() { long minSeconds = min.toEpochSecond(); long maxSeconds = max.toEpochSecond(); long seconds = (long) nextDouble(minSeconds, maxSeconds); int minNanoSeconds = min.getNano(); int maxNanoSeconds = max.getNano(); long nanoSeconds = (long) nextDouble(minNanoSeconds, maxNanoSeconds); return ZonedDateTime.ofInstant(Instant.ofEpochSecond(seconds, nanoSeconds), min.getZone()); } ZonedDateTimeRangeRandomizer(final ZonedDateTime min, final ZonedDateTime max); ZonedDateTimeRangeRandomizer(final ZonedDateTime min, final ZonedDateTime max, final long seed); static ZonedDateTimeRangeRandomizer aNewZonedDateTimeRangeRandomizer(final ZonedDateTime min, final ZonedDateTime max); static ZonedDateTimeRangeRandomizer aNewZonedDateTimeRangeRandomizer(final ZonedDateTime min, final ZonedDateTime max, final long seed); @Override ZonedDateTime getRandomValue(); } | ZonedDateTimeRangeRandomizer extends AbstractRangeRandomizer<ZonedDateTime> { @Override public ZonedDateTime getRandomValue() { long minSeconds = min.toEpochSecond(); long maxSeconds = max.toEpochSecond(); long seconds = (long) nextDouble(minSeconds, maxSeconds); int minNanoSeconds = min.getNano(); int maxNanoSeconds = max.getNano(); long nanoSeconds = (long) nextDouble(minNanoSeconds, maxNanoSeconds); return ZonedDateTime.ofInstant(Instant.ofEpochSecond(seconds, nanoSeconds), min.getZone()); } ZonedDateTimeRangeRandomizer(final ZonedDateTime min, final ZonedDateTime max); ZonedDateTimeRangeRandomizer(final ZonedDateTime min, final ZonedDateTime max, final long seed); static ZonedDateTimeRangeRandomizer aNewZonedDateTimeRangeRandomizer(final ZonedDateTime min, final ZonedDateTime max); static ZonedDateTimeRangeRandomizer aNewZonedDateTimeRangeRandomizer(final ZonedDateTime min, final ZonedDateTime max, final long seed); @Override ZonedDateTime getRandomValue(); } |
@Test void generatedZonedDateTimeShouldBeWithinSpecifiedRange() { assertThat(randomizer.getRandomValue()).isBetween(minZonedDateTime, maxZonedDateTime); } | @Override public ZonedDateTime getRandomValue() { long minSeconds = min.toEpochSecond(); long maxSeconds = max.toEpochSecond(); long seconds = (long) nextDouble(minSeconds, maxSeconds); int minNanoSeconds = min.getNano(); int maxNanoSeconds = max.getNano(); long nanoSeconds = (long) nextDouble(minNanoSeconds, maxNanoSeconds); return ZonedDateTime.ofInstant(Instant.ofEpochSecond(seconds, nanoSeconds), min.getZone()); } | ZonedDateTimeRangeRandomizer extends AbstractRangeRandomizer<ZonedDateTime> { @Override public ZonedDateTime getRandomValue() { long minSeconds = min.toEpochSecond(); long maxSeconds = max.toEpochSecond(); long seconds = (long) nextDouble(minSeconds, maxSeconds); int minNanoSeconds = min.getNano(); int maxNanoSeconds = max.getNano(); long nanoSeconds = (long) nextDouble(minNanoSeconds, maxNanoSeconds); return ZonedDateTime.ofInstant(Instant.ofEpochSecond(seconds, nanoSeconds), min.getZone()); } } | ZonedDateTimeRangeRandomizer extends AbstractRangeRandomizer<ZonedDateTime> { @Override public ZonedDateTime getRandomValue() { long minSeconds = min.toEpochSecond(); long maxSeconds = max.toEpochSecond(); long seconds = (long) nextDouble(minSeconds, maxSeconds); int minNanoSeconds = min.getNano(); int maxNanoSeconds = max.getNano(); long nanoSeconds = (long) nextDouble(minNanoSeconds, maxNanoSeconds); return ZonedDateTime.ofInstant(Instant.ofEpochSecond(seconds, nanoSeconds), min.getZone()); } ZonedDateTimeRangeRandomizer(final ZonedDateTime min, final ZonedDateTime max); ZonedDateTimeRangeRandomizer(final ZonedDateTime min, final ZonedDateTime max, final long seed); } | ZonedDateTimeRangeRandomizer extends AbstractRangeRandomizer<ZonedDateTime> { @Override public ZonedDateTime getRandomValue() { long minSeconds = min.toEpochSecond(); long maxSeconds = max.toEpochSecond(); long seconds = (long) nextDouble(minSeconds, maxSeconds); int minNanoSeconds = min.getNano(); int maxNanoSeconds = max.getNano(); long nanoSeconds = (long) nextDouble(minNanoSeconds, maxNanoSeconds); return ZonedDateTime.ofInstant(Instant.ofEpochSecond(seconds, nanoSeconds), min.getZone()); } ZonedDateTimeRangeRandomizer(final ZonedDateTime min, final ZonedDateTime max); ZonedDateTimeRangeRandomizer(final ZonedDateTime min, final ZonedDateTime max, final long seed); static ZonedDateTimeRangeRandomizer aNewZonedDateTimeRangeRandomizer(final ZonedDateTime min, final ZonedDateTime max); static ZonedDateTimeRangeRandomizer aNewZonedDateTimeRangeRandomizer(final ZonedDateTime min, final ZonedDateTime max, final long seed); @Override ZonedDateTime getRandomValue(); } | ZonedDateTimeRangeRandomizer extends AbstractRangeRandomizer<ZonedDateTime> { @Override public ZonedDateTime getRandomValue() { long minSeconds = min.toEpochSecond(); long maxSeconds = max.toEpochSecond(); long seconds = (long) nextDouble(minSeconds, maxSeconds); int minNanoSeconds = min.getNano(); int maxNanoSeconds = max.getNano(); long nanoSeconds = (long) nextDouble(minNanoSeconds, maxNanoSeconds); return ZonedDateTime.ofInstant(Instant.ofEpochSecond(seconds, nanoSeconds), min.getZone()); } ZonedDateTimeRangeRandomizer(final ZonedDateTime min, final ZonedDateTime max); ZonedDateTimeRangeRandomizer(final ZonedDateTime min, final ZonedDateTime max, final long seed); static ZonedDateTimeRangeRandomizer aNewZonedDateTimeRangeRandomizer(final ZonedDateTime min, final ZonedDateTime max); static ZonedDateTimeRangeRandomizer aNewZonedDateTimeRangeRandomizer(final ZonedDateTime min, final ZonedDateTime max, final long seed); @Override ZonedDateTime getRandomValue(); } |
@Test void whenSpecifiedMinZonedDateTimeIsAfterMaxZonedDateTime_thenShouldThrowIllegalArgumentException() { assertThatThrownBy(() -> aNewZonedDateTimeRangeRandomizer(maxZonedDateTime, minZonedDateTime)).isInstanceOf(IllegalArgumentException.class); } | public static ZonedDateTimeRangeRandomizer aNewZonedDateTimeRangeRandomizer(final ZonedDateTime min, final ZonedDateTime max) { return new ZonedDateTimeRangeRandomizer(min, max); } | ZonedDateTimeRangeRandomizer extends AbstractRangeRandomizer<ZonedDateTime> { public static ZonedDateTimeRangeRandomizer aNewZonedDateTimeRangeRandomizer(final ZonedDateTime min, final ZonedDateTime max) { return new ZonedDateTimeRangeRandomizer(min, max); } } | ZonedDateTimeRangeRandomizer extends AbstractRangeRandomizer<ZonedDateTime> { public static ZonedDateTimeRangeRandomizer aNewZonedDateTimeRangeRandomizer(final ZonedDateTime min, final ZonedDateTime max) { return new ZonedDateTimeRangeRandomizer(min, max); } ZonedDateTimeRangeRandomizer(final ZonedDateTime min, final ZonedDateTime max); ZonedDateTimeRangeRandomizer(final ZonedDateTime min, final ZonedDateTime max, final long seed); } | ZonedDateTimeRangeRandomizer extends AbstractRangeRandomizer<ZonedDateTime> { public static ZonedDateTimeRangeRandomizer aNewZonedDateTimeRangeRandomizer(final ZonedDateTime min, final ZonedDateTime max) { return new ZonedDateTimeRangeRandomizer(min, max); } ZonedDateTimeRangeRandomizer(final ZonedDateTime min, final ZonedDateTime max); ZonedDateTimeRangeRandomizer(final ZonedDateTime min, final ZonedDateTime max, final long seed); static ZonedDateTimeRangeRandomizer aNewZonedDateTimeRangeRandomizer(final ZonedDateTime min, final ZonedDateTime max); static ZonedDateTimeRangeRandomizer aNewZonedDateTimeRangeRandomizer(final ZonedDateTime min, final ZonedDateTime max, final long seed); @Override ZonedDateTime getRandomValue(); } | ZonedDateTimeRangeRandomizer extends AbstractRangeRandomizer<ZonedDateTime> { public static ZonedDateTimeRangeRandomizer aNewZonedDateTimeRangeRandomizer(final ZonedDateTime min, final ZonedDateTime max) { return new ZonedDateTimeRangeRandomizer(min, max); } ZonedDateTimeRangeRandomizer(final ZonedDateTime min, final ZonedDateTime max); ZonedDateTimeRangeRandomizer(final ZonedDateTime min, final ZonedDateTime max, final long seed); static ZonedDateTimeRangeRandomizer aNewZonedDateTimeRangeRandomizer(final ZonedDateTime min, final ZonedDateTime max); static ZonedDateTimeRangeRandomizer aNewZonedDateTimeRangeRandomizer(final ZonedDateTime min, final ZonedDateTime max, final long seed); @Override ZonedDateTime getRandomValue(); } |
@Test void generatedValueShouldBeWithinSpecifiedRange() { Short randomValue = randomizer.getRandomValue(); assertThat(randomValue).isBetween(min, max); } | @Override public Short getRandomValue() { return (short) nextDouble(min, max); } | ShortRangeRandomizer extends AbstractRangeRandomizer<Short> { @Override public Short getRandomValue() { return (short) nextDouble(min, max); } } | ShortRangeRandomizer extends AbstractRangeRandomizer<Short> { @Override public Short getRandomValue() { return (short) nextDouble(min, max); } ShortRangeRandomizer(final Short min, final Short max); ShortRangeRandomizer(final Short min, final Short max, final long seed); } | ShortRangeRandomizer extends AbstractRangeRandomizer<Short> { @Override public Short getRandomValue() { return (short) nextDouble(min, max); } ShortRangeRandomizer(final Short min, final Short max); ShortRangeRandomizer(final Short min, final Short max, final long seed); static ShortRangeRandomizer aNewShortRangeRandomizer(final Short min, final Short max); static ShortRangeRandomizer aNewShortRangeRandomizer(final Short min, final Short max, final long seed); @Override Short getRandomValue(); } | ShortRangeRandomizer extends AbstractRangeRandomizer<Short> { @Override public Short getRandomValue() { return (short) nextDouble(min, max); } ShortRangeRandomizer(final Short min, final Short max); ShortRangeRandomizer(final Short min, final Short max, final long seed); static ShortRangeRandomizer aNewShortRangeRandomizer(final Short min, final Short max); static ShortRangeRandomizer aNewShortRangeRandomizer(final Short min, final Short max, final long seed); @Override Short getRandomValue(); } |
@Test void whenSpecifiedMinValueIsAfterMaxValueThenThrowIllegalArgumentException() { assertThatThrownBy(() -> aNewShortRangeRandomizer(max, min)).isInstanceOf(IllegalArgumentException.class); } | public static ShortRangeRandomizer aNewShortRangeRandomizer(final Short min, final Short max) { return new ShortRangeRandomizer(min, max); } | ShortRangeRandomizer extends AbstractRangeRandomizer<Short> { public static ShortRangeRandomizer aNewShortRangeRandomizer(final Short min, final Short max) { return new ShortRangeRandomizer(min, max); } } | ShortRangeRandomizer extends AbstractRangeRandomizer<Short> { public static ShortRangeRandomizer aNewShortRangeRandomizer(final Short min, final Short max) { return new ShortRangeRandomizer(min, max); } ShortRangeRandomizer(final Short min, final Short max); ShortRangeRandomizer(final Short min, final Short max, final long seed); } | ShortRangeRandomizer extends AbstractRangeRandomizer<Short> { public static ShortRangeRandomizer aNewShortRangeRandomizer(final Short min, final Short max) { return new ShortRangeRandomizer(min, max); } ShortRangeRandomizer(final Short min, final Short max); ShortRangeRandomizer(final Short min, final Short max, final long seed); static ShortRangeRandomizer aNewShortRangeRandomizer(final Short min, final Short max); static ShortRangeRandomizer aNewShortRangeRandomizer(final Short min, final Short max, final long seed); @Override Short getRandomValue(); } | ShortRangeRandomizer extends AbstractRangeRandomizer<Short> { public static ShortRangeRandomizer aNewShortRangeRandomizer(final Short min, final Short max) { return new ShortRangeRandomizer(min, max); } ShortRangeRandomizer(final Short min, final Short max); ShortRangeRandomizer(final Short min, final Short max, final long seed); static ShortRangeRandomizer aNewShortRangeRandomizer(final Short min, final Short max); static ShortRangeRandomizer aNewShortRangeRandomizer(final Short min, final Short max, final long seed); @Override Short getRandomValue(); } |
@Test void generatedValueMustNotBeNull() { assertThat(randomizer.getRandomValue()).isNotNull(); } | @Override public String getRandomValue() { int length = (int) nextDouble(minLength, maxLength); char[] chars = new char[length]; for (int i = 0; i < length; i++) { chars[i] = characterRandomizer.getRandomValue(); } return new String(chars); } | StringRandomizer extends AbstractRandomizer<String> { @Override public String getRandomValue() { int length = (int) nextDouble(minLength, maxLength); char[] chars = new char[length]; for (int i = 0; i < length; i++) { chars[i] = characterRandomizer.getRandomValue(); } return new String(chars); } } | StringRandomizer extends AbstractRandomizer<String> { @Override public String getRandomValue() { int length = (int) nextDouble(minLength, maxLength); char[] chars = new char[length]; for (int i = 0; i < length; i++) { chars[i] = characterRandomizer.getRandomValue(); } return new String(chars); } StringRandomizer(); StringRandomizer(final Charset charset); StringRandomizer(int maxLength); StringRandomizer(long seed); StringRandomizer(final Charset charset, final long seed); StringRandomizer(final int maxLength, final long seed); StringRandomizer(final int minLength, final int maxLength, final long seed); StringRandomizer(final Charset charset, final int maxLength, final long seed); StringRandomizer(final Charset charset, final int minLength, final int maxLength, final long seed); } | StringRandomizer extends AbstractRandomizer<String> { @Override public String getRandomValue() { int length = (int) nextDouble(minLength, maxLength); char[] chars = new char[length]; for (int i = 0; i < length; i++) { chars[i] = characterRandomizer.getRandomValue(); } return new String(chars); } StringRandomizer(); StringRandomizer(final Charset charset); StringRandomizer(int maxLength); StringRandomizer(long seed); StringRandomizer(final Charset charset, final long seed); StringRandomizer(final int maxLength, final long seed); StringRandomizer(final int minLength, final int maxLength, final long seed); StringRandomizer(final Charset charset, final int maxLength, final long seed); StringRandomizer(final Charset charset, final int minLength, final int maxLength, final long seed); static StringRandomizer aNewStringRandomizer(); static StringRandomizer aNewStringRandomizer(final Charset charset); static StringRandomizer aNewStringRandomizer(final int maxLength); static StringRandomizer aNewStringRandomizer(final long seed); static StringRandomizer aNewStringRandomizer(final Charset charset, final long seed); static StringRandomizer aNewStringRandomizer(final int maxLength, final long seed); static StringRandomizer aNewStringRandomizer(final int minLength, final int maxLength, final long seed); static StringRandomizer aNewStringRandomizer(final Charset charset, final int maxLength, final long seed); static StringRandomizer aNewStringRandomizer(final Charset charset, final int minLength, final int maxLength, final long seed); @Override String getRandomValue(); } | StringRandomizer extends AbstractRandomizer<String> { @Override public String getRandomValue() { int length = (int) nextDouble(minLength, maxLength); char[] chars = new char[length]; for (int i = 0; i < length; i++) { chars[i] = characterRandomizer.getRandomValue(); } return new String(chars); } StringRandomizer(); StringRandomizer(final Charset charset); StringRandomizer(int maxLength); StringRandomizer(long seed); StringRandomizer(final Charset charset, final long seed); StringRandomizer(final int maxLength, final long seed); StringRandomizer(final int minLength, final int maxLength, final long seed); StringRandomizer(final Charset charset, final int maxLength, final long seed); StringRandomizer(final Charset charset, final int minLength, final int maxLength, final long seed); static StringRandomizer aNewStringRandomizer(); static StringRandomizer aNewStringRandomizer(final Charset charset); static StringRandomizer aNewStringRandomizer(final int maxLength); static StringRandomizer aNewStringRandomizer(final long seed); static StringRandomizer aNewStringRandomizer(final Charset charset, final long seed); static StringRandomizer aNewStringRandomizer(final int maxLength, final long seed); static StringRandomizer aNewStringRandomizer(final int minLength, final int maxLength, final long seed); static StringRandomizer aNewStringRandomizer(final Charset charset, final int maxLength, final long seed); static StringRandomizer aNewStringRandomizer(final Charset charset, final int minLength, final int maxLength, final long seed); @Override String getRandomValue(); } |
@Test void testIsMapType() { assertThat(ReflectionUtils.isMapType(CustomMap.class)).isTrue(); assertThat(ReflectionUtils.isMapType(Foo.class)).isFalse(); } | public static boolean isMapType(final Class<?> type) { return Map.class.isAssignableFrom(type); } | ReflectionUtils { public static boolean isMapType(final Class<?> type) { return Map.class.isAssignableFrom(type); } } | ReflectionUtils { public static boolean isMapType(final Class<?> type) { return Map.class.isAssignableFrom(type); } private ReflectionUtils(); } | ReflectionUtils { public static boolean isMapType(final Class<?> type) { return Map.class.isAssignableFrom(type); } private ReflectionUtils(); @SuppressWarnings("unchecked") static Randomizer<T> asRandomizer(final Supplier<T> supplier); static List<Field> getDeclaredFields(T type); static List<Field> getInheritedFields(Class<?> type); static void setProperty(final Object object, final Field field, final Object value); static void setFieldValue(final Object object, final Field field, final Object value); static Object getFieldValue(final Object object, final Field field); static Class<?> getWrapperType(Class<?> primitiveType); static boolean isPrimitiveFieldWithDefaultValue(final Object object, final Field field); static boolean isStatic(final Field field); static boolean isInterface(final Class<?> type); static boolean isAbstract(final Class<T> type); static boolean isPublic(final Class<T> type); static boolean isArrayType(final Class<?> type); static boolean isEnumType(final Class<?> type); static boolean isCollectionType(final Class<?> type); static boolean isCollectionType(final Type type); static boolean isPopulatable(final Type type); static boolean isIntrospectable(final Class<?> type); static boolean isMapType(final Class<?> type); static boolean isJdkBuiltIn(final Class<?> type); static boolean isParameterizedType(final Type type); static boolean isWildcardType(final Type type); static boolean isTypeVariable(final Type type); static List<Class<?>> getPublicConcreteSubTypesOf(final Class<T> type); static List<Class<?>> filterSameParameterizedTypes(final List<Class<?>> types, final Type type); static T getAnnotation(Field field, Class<T> annotationType); static boolean isAnnotationPresent(Field field, Class<? extends Annotation> annotationType); static Collection<?> getEmptyImplementationForCollectionInterface(final Class<?> collectionInterface); static Collection<?> createEmptyCollectionForType(Class<?> fieldType, int initialSize); static Map<?, ?> getEmptyImplementationForMapInterface(final Class<?> mapInterface); static Optional<Method> getReadMethod(Field field); @SuppressWarnings("unchecked") static Randomizer<T> newInstance(final Class<T> type, final RandomizerArgument[] randomizerArguments); } | ReflectionUtils { public static boolean isMapType(final Class<?> type) { return Map.class.isAssignableFrom(type); } private ReflectionUtils(); @SuppressWarnings("unchecked") static Randomizer<T> asRandomizer(final Supplier<T> supplier); static List<Field> getDeclaredFields(T type); static List<Field> getInheritedFields(Class<?> type); static void setProperty(final Object object, final Field field, final Object value); static void setFieldValue(final Object object, final Field field, final Object value); static Object getFieldValue(final Object object, final Field field); static Class<?> getWrapperType(Class<?> primitiveType); static boolean isPrimitiveFieldWithDefaultValue(final Object object, final Field field); static boolean isStatic(final Field field); static boolean isInterface(final Class<?> type); static boolean isAbstract(final Class<T> type); static boolean isPublic(final Class<T> type); static boolean isArrayType(final Class<?> type); static boolean isEnumType(final Class<?> type); static boolean isCollectionType(final Class<?> type); static boolean isCollectionType(final Type type); static boolean isPopulatable(final Type type); static boolean isIntrospectable(final Class<?> type); static boolean isMapType(final Class<?> type); static boolean isJdkBuiltIn(final Class<?> type); static boolean isParameterizedType(final Type type); static boolean isWildcardType(final Type type); static boolean isTypeVariable(final Type type); static List<Class<?>> getPublicConcreteSubTypesOf(final Class<T> type); static List<Class<?>> filterSameParameterizedTypes(final List<Class<?>> types, final Type type); static T getAnnotation(Field field, Class<T> annotationType); static boolean isAnnotationPresent(Field field, Class<? extends Annotation> annotationType); static Collection<?> getEmptyImplementationForCollectionInterface(final Class<?> collectionInterface); static Collection<?> createEmptyCollectionForType(Class<?> fieldType, int initialSize); static Map<?, ?> getEmptyImplementationForMapInterface(final Class<?> mapInterface); static Optional<Method> getReadMethod(Field field); @SuppressWarnings("unchecked") static Randomizer<T> newInstance(final Class<T> type, final RandomizerArgument[] randomizerArguments); } |
@Test void generatedValueShouldTheSameAs() { String actual = stringDelegatingRandomizer.getRandomValue(); assertThat(actual).isEqualTo(valueOf(object)); } | @Override public String getRandomValue() { return valueOf(delegate.getRandomValue()); } | StringDelegatingRandomizer implements Randomizer<String> { @Override public String getRandomValue() { return valueOf(delegate.getRandomValue()); } } | StringDelegatingRandomizer implements Randomizer<String> { @Override public String getRandomValue() { return valueOf(delegate.getRandomValue()); } StringDelegatingRandomizer(final Randomizer<?> delegate); } | StringDelegatingRandomizer implements Randomizer<String> { @Override public String getRandomValue() { return valueOf(delegate.getRandomValue()); } StringDelegatingRandomizer(final Randomizer<?> delegate); static StringDelegatingRandomizer aNewStringDelegatingRandomizer(final Randomizer<?> delegate); @Override String getRandomValue(); } | StringDelegatingRandomizer implements Randomizer<String> { @Override public String getRandomValue() { return valueOf(delegate.getRandomValue()); } StringDelegatingRandomizer(final Randomizer<?> delegate); static StringDelegatingRandomizer aNewStringDelegatingRandomizer(final Randomizer<?> delegate); @Override String getRandomValue(); } |
@Test void generatedValueMustNotBeNull() { assertThat(randomizer.getRandomValue()).isNotNull(); } | @Override public Character getRandomValue() { return characters.get(random.nextInt(characters.size())); } | CharacterRandomizer extends AbstractRandomizer<Character> { @Override public Character getRandomValue() { return characters.get(random.nextInt(characters.size())); } } | CharacterRandomizer extends AbstractRandomizer<Character> { @Override public Character getRandomValue() { return characters.get(random.nextInt(characters.size())); } CharacterRandomizer(); CharacterRandomizer(final Charset charset); CharacterRandomizer(final long seed); CharacterRandomizer(final Charset charset, final long seed); } | CharacterRandomizer extends AbstractRandomizer<Character> { @Override public Character getRandomValue() { return characters.get(random.nextInt(characters.size())); } CharacterRandomizer(); CharacterRandomizer(final Charset charset); CharacterRandomizer(final long seed); CharacterRandomizer(final Charset charset, final long seed); static CharacterRandomizer aNewCharacterRandomizer(); static CharacterRandomizer aNewCharacterRandomizer(final Charset charset); static CharacterRandomizer aNewCharacterRandomizer(final long seed); static CharacterRandomizer aNewCharacterRandomizer(final Charset charset, final long seed); @Override Character getRandomValue(); } | CharacterRandomizer extends AbstractRandomizer<Character> { @Override public Character getRandomValue() { return characters.get(random.nextInt(characters.size())); } CharacterRandomizer(); CharacterRandomizer(final Charset charset); CharacterRandomizer(final long seed); CharacterRandomizer(final Charset charset, final long seed); static CharacterRandomizer aNewCharacterRandomizer(); static CharacterRandomizer aNewCharacterRandomizer(final Charset charset); static CharacterRandomizer aNewCharacterRandomizer(final long seed); static CharacterRandomizer aNewCharacterRandomizer(final Charset charset, final long seed); @Override Character getRandomValue(); } |
@Test void shouldGenerateOnlyAlphabeticLetters() { assertThat(randomizer.getRandomValue()).isBetween('A', 'z'); } | @Override public Character getRandomValue() { return characters.get(random.nextInt(characters.size())); } | CharacterRandomizer extends AbstractRandomizer<Character> { @Override public Character getRandomValue() { return characters.get(random.nextInt(characters.size())); } } | CharacterRandomizer extends AbstractRandomizer<Character> { @Override public Character getRandomValue() { return characters.get(random.nextInt(characters.size())); } CharacterRandomizer(); CharacterRandomizer(final Charset charset); CharacterRandomizer(final long seed); CharacterRandomizer(final Charset charset, final long seed); } | CharacterRandomizer extends AbstractRandomizer<Character> { @Override public Character getRandomValue() { return characters.get(random.nextInt(characters.size())); } CharacterRandomizer(); CharacterRandomizer(final Charset charset); CharacterRandomizer(final long seed); CharacterRandomizer(final Charset charset, final long seed); static CharacterRandomizer aNewCharacterRandomizer(); static CharacterRandomizer aNewCharacterRandomizer(final Charset charset); static CharacterRandomizer aNewCharacterRandomizer(final long seed); static CharacterRandomizer aNewCharacterRandomizer(final Charset charset, final long seed); @Override Character getRandomValue(); } | CharacterRandomizer extends AbstractRandomizer<Character> { @Override public Character getRandomValue() { return characters.get(random.nextInt(characters.size())); } CharacterRandomizer(); CharacterRandomizer(final Charset charset); CharacterRandomizer(final long seed); CharacterRandomizer(final Charset charset, final long seed); static CharacterRandomizer aNewCharacterRandomizer(); static CharacterRandomizer aNewCharacterRandomizer(final Charset charset); static CharacterRandomizer aNewCharacterRandomizer(final long seed); static CharacterRandomizer aNewCharacterRandomizer(final Charset charset, final long seed); @Override Character getRandomValue(); } |
@Test void specifiedSizeShouldBePositive() { assertThatThrownBy(() -> aNewMapRandomizer(keyRandomizer, valueRandomizer, -3)).isInstanceOf(IllegalArgumentException.class); } | public static <K, V> MapRandomizer<K, V> aNewMapRandomizer(final Randomizer<K> keyRandomizer, final Randomizer<V> valueRandomizer) { return new MapRandomizer<>(keyRandomizer, valueRandomizer, getRandomSize()); } | MapRandomizer implements Randomizer<Map<K, V>> { public static <K, V> MapRandomizer<K, V> aNewMapRandomizer(final Randomizer<K> keyRandomizer, final Randomizer<V> valueRandomizer) { return new MapRandomizer<>(keyRandomizer, valueRandomizer, getRandomSize()); } } | MapRandomizer implements Randomizer<Map<K, V>> { public static <K, V> MapRandomizer<K, V> aNewMapRandomizer(final Randomizer<K> keyRandomizer, final Randomizer<V> valueRandomizer) { return new MapRandomizer<>(keyRandomizer, valueRandomizer, getRandomSize()); } MapRandomizer(final Randomizer<K> keyRandomizer, final Randomizer<V> valueRandomizer); MapRandomizer(final Randomizer<K> keyRandomizer, final Randomizer<V> valueRandomizer, final int nbEntries); } | MapRandomizer implements Randomizer<Map<K, V>> { public static <K, V> MapRandomizer<K, V> aNewMapRandomizer(final Randomizer<K> keyRandomizer, final Randomizer<V> valueRandomizer) { return new MapRandomizer<>(keyRandomizer, valueRandomizer, getRandomSize()); } MapRandomizer(final Randomizer<K> keyRandomizer, final Randomizer<V> valueRandomizer); MapRandomizer(final Randomizer<K> keyRandomizer, final Randomizer<V> valueRandomizer, final int nbEntries); static MapRandomizer<K, V> aNewMapRandomizer(final Randomizer<K> keyRandomizer, final Randomizer<V> valueRandomizer); static MapRandomizer<K, V> aNewMapRandomizer(final Randomizer<K> keyRandomizer, final Randomizer<V> valueRandomizer, final int nbEntries); @Override Map<K, V> getRandomValue(); } | MapRandomizer implements Randomizer<Map<K, V>> { public static <K, V> MapRandomizer<K, V> aNewMapRandomizer(final Randomizer<K> keyRandomizer, final Randomizer<V> valueRandomizer) { return new MapRandomizer<>(keyRandomizer, valueRandomizer, getRandomSize()); } MapRandomizer(final Randomizer<K> keyRandomizer, final Randomizer<V> valueRandomizer); MapRandomizer(final Randomizer<K> keyRandomizer, final Randomizer<V> valueRandomizer, final int nbEntries); static MapRandomizer<K, V> aNewMapRandomizer(final Randomizer<K> keyRandomizer, final Randomizer<V> valueRandomizer); static MapRandomizer<K, V> aNewMapRandomizer(final Randomizer<K> keyRandomizer, final Randomizer<V> valueRandomizer, final int nbEntries); @Override Map<K, V> getRandomValue(); } |
@Test void nullKeyRandomizer() { assertThatThrownBy(() -> aNewMapRandomizer(null, valueRandomizer, 3)).isInstanceOf(IllegalArgumentException.class); } | public static <K, V> MapRandomizer<K, V> aNewMapRandomizer(final Randomizer<K> keyRandomizer, final Randomizer<V> valueRandomizer) { return new MapRandomizer<>(keyRandomizer, valueRandomizer, getRandomSize()); } | MapRandomizer implements Randomizer<Map<K, V>> { public static <K, V> MapRandomizer<K, V> aNewMapRandomizer(final Randomizer<K> keyRandomizer, final Randomizer<V> valueRandomizer) { return new MapRandomizer<>(keyRandomizer, valueRandomizer, getRandomSize()); } } | MapRandomizer implements Randomizer<Map<K, V>> { public static <K, V> MapRandomizer<K, V> aNewMapRandomizer(final Randomizer<K> keyRandomizer, final Randomizer<V> valueRandomizer) { return new MapRandomizer<>(keyRandomizer, valueRandomizer, getRandomSize()); } MapRandomizer(final Randomizer<K> keyRandomizer, final Randomizer<V> valueRandomizer); MapRandomizer(final Randomizer<K> keyRandomizer, final Randomizer<V> valueRandomizer, final int nbEntries); } | MapRandomizer implements Randomizer<Map<K, V>> { public static <K, V> MapRandomizer<K, V> aNewMapRandomizer(final Randomizer<K> keyRandomizer, final Randomizer<V> valueRandomizer) { return new MapRandomizer<>(keyRandomizer, valueRandomizer, getRandomSize()); } MapRandomizer(final Randomizer<K> keyRandomizer, final Randomizer<V> valueRandomizer); MapRandomizer(final Randomizer<K> keyRandomizer, final Randomizer<V> valueRandomizer, final int nbEntries); static MapRandomizer<K, V> aNewMapRandomizer(final Randomizer<K> keyRandomizer, final Randomizer<V> valueRandomizer); static MapRandomizer<K, V> aNewMapRandomizer(final Randomizer<K> keyRandomizer, final Randomizer<V> valueRandomizer, final int nbEntries); @Override Map<K, V> getRandomValue(); } | MapRandomizer implements Randomizer<Map<K, V>> { public static <K, V> MapRandomizer<K, V> aNewMapRandomizer(final Randomizer<K> keyRandomizer, final Randomizer<V> valueRandomizer) { return new MapRandomizer<>(keyRandomizer, valueRandomizer, getRandomSize()); } MapRandomizer(final Randomizer<K> keyRandomizer, final Randomizer<V> valueRandomizer); MapRandomizer(final Randomizer<K> keyRandomizer, final Randomizer<V> valueRandomizer, final int nbEntries); static MapRandomizer<K, V> aNewMapRandomizer(final Randomizer<K> keyRandomizer, final Randomizer<V> valueRandomizer); static MapRandomizer<K, V> aNewMapRandomizer(final Randomizer<K> keyRandomizer, final Randomizer<V> valueRandomizer, final int nbEntries); @Override Map<K, V> getRandomValue(); } |
@Test void nullValueRandomizer() { assertThatThrownBy(() -> aNewMapRandomizer(keyRandomizer, null, 3)).isInstanceOf(IllegalArgumentException.class); } | public static <K, V> MapRandomizer<K, V> aNewMapRandomizer(final Randomizer<K> keyRandomizer, final Randomizer<V> valueRandomizer) { return new MapRandomizer<>(keyRandomizer, valueRandomizer, getRandomSize()); } | MapRandomizer implements Randomizer<Map<K, V>> { public static <K, V> MapRandomizer<K, V> aNewMapRandomizer(final Randomizer<K> keyRandomizer, final Randomizer<V> valueRandomizer) { return new MapRandomizer<>(keyRandomizer, valueRandomizer, getRandomSize()); } } | MapRandomizer implements Randomizer<Map<K, V>> { public static <K, V> MapRandomizer<K, V> aNewMapRandomizer(final Randomizer<K> keyRandomizer, final Randomizer<V> valueRandomizer) { return new MapRandomizer<>(keyRandomizer, valueRandomizer, getRandomSize()); } MapRandomizer(final Randomizer<K> keyRandomizer, final Randomizer<V> valueRandomizer); MapRandomizer(final Randomizer<K> keyRandomizer, final Randomizer<V> valueRandomizer, final int nbEntries); } | MapRandomizer implements Randomizer<Map<K, V>> { public static <K, V> MapRandomizer<K, V> aNewMapRandomizer(final Randomizer<K> keyRandomizer, final Randomizer<V> valueRandomizer) { return new MapRandomizer<>(keyRandomizer, valueRandomizer, getRandomSize()); } MapRandomizer(final Randomizer<K> keyRandomizer, final Randomizer<V> valueRandomizer); MapRandomizer(final Randomizer<K> keyRandomizer, final Randomizer<V> valueRandomizer, final int nbEntries); static MapRandomizer<K, V> aNewMapRandomizer(final Randomizer<K> keyRandomizer, final Randomizer<V> valueRandomizer); static MapRandomizer<K, V> aNewMapRandomizer(final Randomizer<K> keyRandomizer, final Randomizer<V> valueRandomizer, final int nbEntries); @Override Map<K, V> getRandomValue(); } | MapRandomizer implements Randomizer<Map<K, V>> { public static <K, V> MapRandomizer<K, V> aNewMapRandomizer(final Randomizer<K> keyRandomizer, final Randomizer<V> valueRandomizer) { return new MapRandomizer<>(keyRandomizer, valueRandomizer, getRandomSize()); } MapRandomizer(final Randomizer<K> keyRandomizer, final Randomizer<V> valueRandomizer); MapRandomizer(final Randomizer<K> keyRandomizer, final Randomizer<V> valueRandomizer, final int nbEntries); static MapRandomizer<K, V> aNewMapRandomizer(final Randomizer<K> keyRandomizer, final Randomizer<V> valueRandomizer); static MapRandomizer<K, V> aNewMapRandomizer(final Randomizer<K> keyRandomizer, final Randomizer<V> valueRandomizer, final int nbEntries); @Override Map<K, V> getRandomValue(); } |
@Test void generatedValueShouldNotBeNull() { assertThat(randomizer.getRandomValue()).isNotNull(); } | @Override public ZoneId getRandomValue() { List<Map.Entry<String, String>> zoneIds = new ArrayList<>(ZoneId.SHORT_IDS.entrySet()); Map.Entry<String, String> randomZoneId = zoneIds.get(random.nextInt(zoneIds.size())); return ZoneId.of(randomZoneId.getValue()); } | ZoneIdRandomizer extends AbstractRandomizer<ZoneId> { @Override public ZoneId getRandomValue() { List<Map.Entry<String, String>> zoneIds = new ArrayList<>(ZoneId.SHORT_IDS.entrySet()); Map.Entry<String, String> randomZoneId = zoneIds.get(random.nextInt(zoneIds.size())); return ZoneId.of(randomZoneId.getValue()); } } | ZoneIdRandomizer extends AbstractRandomizer<ZoneId> { @Override public ZoneId getRandomValue() { List<Map.Entry<String, String>> zoneIds = new ArrayList<>(ZoneId.SHORT_IDS.entrySet()); Map.Entry<String, String> randomZoneId = zoneIds.get(random.nextInt(zoneIds.size())); return ZoneId.of(randomZoneId.getValue()); } ZoneIdRandomizer(); ZoneIdRandomizer(long seed); } | ZoneIdRandomizer extends AbstractRandomizer<ZoneId> { @Override public ZoneId getRandomValue() { List<Map.Entry<String, String>> zoneIds = new ArrayList<>(ZoneId.SHORT_IDS.entrySet()); Map.Entry<String, String> randomZoneId = zoneIds.get(random.nextInt(zoneIds.size())); return ZoneId.of(randomZoneId.getValue()); } ZoneIdRandomizer(); ZoneIdRandomizer(long seed); static ZoneIdRandomizer aNewZoneIdRandomizer(); static ZoneIdRandomizer aNewZoneIdRandomizer(final long seed); @Override ZoneId getRandomValue(); } | ZoneIdRandomizer extends AbstractRandomizer<ZoneId> { @Override public ZoneId getRandomValue() { List<Map.Entry<String, String>> zoneIds = new ArrayList<>(ZoneId.SHORT_IDS.entrySet()); Map.Entry<String, String> randomZoneId = zoneIds.get(random.nextInt(zoneIds.size())); return ZoneId.of(randomZoneId.getValue()); } ZoneIdRandomizer(); ZoneIdRandomizer(long seed); static ZoneIdRandomizer aNewZoneIdRandomizer(); static ZoneIdRandomizer aNewZoneIdRandomizer(final long seed); @Override ZoneId getRandomValue(); } |
@Test void generatedValueShouldNotBeNull() { assertThat(randomizer.getRandomValue()).isNotNull(); } | @Override public TimeZone getRandomValue() { String[] timeZoneIds = TimeZone.getAvailableIDs(); return TimeZone.getTimeZone(timeZoneIds[random.nextInt(timeZoneIds.length)]); } | TimeZoneRandomizer extends AbstractRandomizer<TimeZone> { @Override public TimeZone getRandomValue() { String[] timeZoneIds = TimeZone.getAvailableIDs(); return TimeZone.getTimeZone(timeZoneIds[random.nextInt(timeZoneIds.length)]); } } | TimeZoneRandomizer extends AbstractRandomizer<TimeZone> { @Override public TimeZone getRandomValue() { String[] timeZoneIds = TimeZone.getAvailableIDs(); return TimeZone.getTimeZone(timeZoneIds[random.nextInt(timeZoneIds.length)]); } TimeZoneRandomizer(); TimeZoneRandomizer(final long seed); } | TimeZoneRandomizer extends AbstractRandomizer<TimeZone> { @Override public TimeZone getRandomValue() { String[] timeZoneIds = TimeZone.getAvailableIDs(); return TimeZone.getTimeZone(timeZoneIds[random.nextInt(timeZoneIds.length)]); } TimeZoneRandomizer(); TimeZoneRandomizer(final long seed); static TimeZoneRandomizer aNewTimeZoneRandomizer(); static TimeZoneRandomizer aNewTimeZoneRandomizer(final long seed); @Override TimeZone getRandomValue(); } | TimeZoneRandomizer extends AbstractRandomizer<TimeZone> { @Override public TimeZone getRandomValue() { String[] timeZoneIds = TimeZone.getAvailableIDs(); return TimeZone.getTimeZone(timeZoneIds[random.nextInt(timeZoneIds.length)]); } TimeZoneRandomizer(); TimeZoneRandomizer(final long seed); static TimeZoneRandomizer aNewTimeZoneRandomizer(); static TimeZoneRandomizer aNewTimeZoneRandomizer(final long seed); @Override TimeZone getRandomValue(); } |
@Test void getRandomArray() { when(context.getParameters()).thenReturn(new EasyRandomParameters().collectionSizeRange(INT, INT)); when(easyRandom.doPopulateBean(String.class, context)).thenReturn(STRING); String[] strings = (String[]) arrayPopulator.getRandomArray(String[].class, context); assertThat(strings).containsOnly(STRING); } | Object getRandomArray(final Class<?> fieldType, final RandomizationContext context) { Class<?> componentType = fieldType.getComponentType(); int randomSize = getRandomArraySize(context.getParameters()); Object result = Array.newInstance(componentType, randomSize); for (int i = 0; i < randomSize; i++) { Object randomElement = easyRandom.doPopulateBean(componentType, context); Array.set(result, i, randomElement); } return result; } | ArrayPopulator { Object getRandomArray(final Class<?> fieldType, final RandomizationContext context) { Class<?> componentType = fieldType.getComponentType(); int randomSize = getRandomArraySize(context.getParameters()); Object result = Array.newInstance(componentType, randomSize); for (int i = 0; i < randomSize; i++) { Object randomElement = easyRandom.doPopulateBean(componentType, context); Array.set(result, i, randomElement); } return result; } } | ArrayPopulator { Object getRandomArray(final Class<?> fieldType, final RandomizationContext context) { Class<?> componentType = fieldType.getComponentType(); int randomSize = getRandomArraySize(context.getParameters()); Object result = Array.newInstance(componentType, randomSize); for (int i = 0; i < randomSize; i++) { Object randomElement = easyRandom.doPopulateBean(componentType, context); Array.set(result, i, randomElement); } return result; } ArrayPopulator(final EasyRandom easyRandom); } | ArrayPopulator { Object getRandomArray(final Class<?> fieldType, final RandomizationContext context) { Class<?> componentType = fieldType.getComponentType(); int randomSize = getRandomArraySize(context.getParameters()); Object result = Array.newInstance(componentType, randomSize); for (int i = 0; i < randomSize; i++) { Object randomElement = easyRandom.doPopulateBean(componentType, context); Array.set(result, i, randomElement); } return result; } ArrayPopulator(final EasyRandom easyRandom); } | ArrayPopulator { Object getRandomArray(final Class<?> fieldType, final RandomizationContext context) { Class<?> componentType = fieldType.getComponentType(); int randomSize = getRandomArraySize(context.getParameters()); Object result = Array.newInstance(componentType, randomSize); for (int i = 0; i < randomSize; i++) { Object randomElement = easyRandom.doPopulateBean(componentType, context); Array.set(result, i, randomElement); } return result; } ArrayPopulator(final EasyRandom easyRandom); } |
@Test void leadingBoundaryMatcherIsRemoved() { RegularExpressionRandomizer randomizer = new RegularExpressionRandomizer("^A"); String actual = randomizer.getRandomValue(); then(actual).isEqualTo("A"); } | @Override public String getRandomValue() { return faker.regexify(removeLeadingAndTailingBoundaryMatchers(regularExpression)); } | RegularExpressionRandomizer extends FakerBasedRandomizer<String> { @Override public String getRandomValue() { return faker.regexify(removeLeadingAndTailingBoundaryMatchers(regularExpression)); } } | RegularExpressionRandomizer extends FakerBasedRandomizer<String> { @Override public String getRandomValue() { return faker.regexify(removeLeadingAndTailingBoundaryMatchers(regularExpression)); } RegularExpressionRandomizer(final String regularExpression); RegularExpressionRandomizer(final String regularExpression, final long seed); } | RegularExpressionRandomizer extends FakerBasedRandomizer<String> { @Override public String getRandomValue() { return faker.regexify(removeLeadingAndTailingBoundaryMatchers(regularExpression)); } RegularExpressionRandomizer(final String regularExpression); RegularExpressionRandomizer(final String regularExpression, final long seed); static RegularExpressionRandomizer aNewRegularExpressionRandomizer(final String regularExpression); static RegularExpressionRandomizer aNewRegularExpressionRandomizer(final String regularExpression, final long seed); @Override String getRandomValue(); } | RegularExpressionRandomizer extends FakerBasedRandomizer<String> { @Override public String getRandomValue() { return faker.regexify(removeLeadingAndTailingBoundaryMatchers(regularExpression)); } RegularExpressionRandomizer(final String regularExpression); RegularExpressionRandomizer(final String regularExpression, final long seed); static RegularExpressionRandomizer aNewRegularExpressionRandomizer(final String regularExpression); static RegularExpressionRandomizer aNewRegularExpressionRandomizer(final String regularExpression, final long seed); @Override String getRandomValue(); } |
@Test void testIsJdkBuiltIn() { assertThat(ReflectionUtils.isJdkBuiltIn(ArrayList.class)).isTrue(); assertThat(ReflectionUtils.isJdkBuiltIn(CustomList.class)).isFalse(); } | public static boolean isJdkBuiltIn(final Class<?> type) { return type.getName().startsWith("java.util"); } | ReflectionUtils { public static boolean isJdkBuiltIn(final Class<?> type) { return type.getName().startsWith("java.util"); } } | ReflectionUtils { public static boolean isJdkBuiltIn(final Class<?> type) { return type.getName().startsWith("java.util"); } private ReflectionUtils(); } | ReflectionUtils { public static boolean isJdkBuiltIn(final Class<?> type) { return type.getName().startsWith("java.util"); } private ReflectionUtils(); @SuppressWarnings("unchecked") static Randomizer<T> asRandomizer(final Supplier<T> supplier); static List<Field> getDeclaredFields(T type); static List<Field> getInheritedFields(Class<?> type); static void setProperty(final Object object, final Field field, final Object value); static void setFieldValue(final Object object, final Field field, final Object value); static Object getFieldValue(final Object object, final Field field); static Class<?> getWrapperType(Class<?> primitiveType); static boolean isPrimitiveFieldWithDefaultValue(final Object object, final Field field); static boolean isStatic(final Field field); static boolean isInterface(final Class<?> type); static boolean isAbstract(final Class<T> type); static boolean isPublic(final Class<T> type); static boolean isArrayType(final Class<?> type); static boolean isEnumType(final Class<?> type); static boolean isCollectionType(final Class<?> type); static boolean isCollectionType(final Type type); static boolean isPopulatable(final Type type); static boolean isIntrospectable(final Class<?> type); static boolean isMapType(final Class<?> type); static boolean isJdkBuiltIn(final Class<?> type); static boolean isParameterizedType(final Type type); static boolean isWildcardType(final Type type); static boolean isTypeVariable(final Type type); static List<Class<?>> getPublicConcreteSubTypesOf(final Class<T> type); static List<Class<?>> filterSameParameterizedTypes(final List<Class<?>> types, final Type type); static T getAnnotation(Field field, Class<T> annotationType); static boolean isAnnotationPresent(Field field, Class<? extends Annotation> annotationType); static Collection<?> getEmptyImplementationForCollectionInterface(final Class<?> collectionInterface); static Collection<?> createEmptyCollectionForType(Class<?> fieldType, int initialSize); static Map<?, ?> getEmptyImplementationForMapInterface(final Class<?> mapInterface); static Optional<Method> getReadMethod(Field field); @SuppressWarnings("unchecked") static Randomizer<T> newInstance(final Class<T> type, final RandomizerArgument[] randomizerArguments); } | ReflectionUtils { public static boolean isJdkBuiltIn(final Class<?> type) { return type.getName().startsWith("java.util"); } private ReflectionUtils(); @SuppressWarnings("unchecked") static Randomizer<T> asRandomizer(final Supplier<T> supplier); static List<Field> getDeclaredFields(T type); static List<Field> getInheritedFields(Class<?> type); static void setProperty(final Object object, final Field field, final Object value); static void setFieldValue(final Object object, final Field field, final Object value); static Object getFieldValue(final Object object, final Field field); static Class<?> getWrapperType(Class<?> primitiveType); static boolean isPrimitiveFieldWithDefaultValue(final Object object, final Field field); static boolean isStatic(final Field field); static boolean isInterface(final Class<?> type); static boolean isAbstract(final Class<T> type); static boolean isPublic(final Class<T> type); static boolean isArrayType(final Class<?> type); static boolean isEnumType(final Class<?> type); static boolean isCollectionType(final Class<?> type); static boolean isCollectionType(final Type type); static boolean isPopulatable(final Type type); static boolean isIntrospectable(final Class<?> type); static boolean isMapType(final Class<?> type); static boolean isJdkBuiltIn(final Class<?> type); static boolean isParameterizedType(final Type type); static boolean isWildcardType(final Type type); static boolean isTypeVariable(final Type type); static List<Class<?>> getPublicConcreteSubTypesOf(final Class<T> type); static List<Class<?>> filterSameParameterizedTypes(final List<Class<?>> types, final Type type); static T getAnnotation(Field field, Class<T> annotationType); static boolean isAnnotationPresent(Field field, Class<? extends Annotation> annotationType); static Collection<?> getEmptyImplementationForCollectionInterface(final Class<?> collectionInterface); static Collection<?> createEmptyCollectionForType(Class<?> fieldType, int initialSize); static Map<?, ?> getEmptyImplementationForMapInterface(final Class<?> mapInterface); static Optional<Method> getReadMethod(Field field); @SuppressWarnings("unchecked") static Randomizer<T> newInstance(final Class<T> type, final RandomizerArgument[] randomizerArguments); } |
@Test void tailingBoundaryMatcherIsRemoved() { RegularExpressionRandomizer randomizer = new RegularExpressionRandomizer("A$"); String actual = randomizer.getRandomValue(); then(actual).isEqualTo("A"); } | @Override public String getRandomValue() { return faker.regexify(removeLeadingAndTailingBoundaryMatchers(regularExpression)); } | RegularExpressionRandomizer extends FakerBasedRandomizer<String> { @Override public String getRandomValue() { return faker.regexify(removeLeadingAndTailingBoundaryMatchers(regularExpression)); } } | RegularExpressionRandomizer extends FakerBasedRandomizer<String> { @Override public String getRandomValue() { return faker.regexify(removeLeadingAndTailingBoundaryMatchers(regularExpression)); } RegularExpressionRandomizer(final String regularExpression); RegularExpressionRandomizer(final String regularExpression, final long seed); } | RegularExpressionRandomizer extends FakerBasedRandomizer<String> { @Override public String getRandomValue() { return faker.regexify(removeLeadingAndTailingBoundaryMatchers(regularExpression)); } RegularExpressionRandomizer(final String regularExpression); RegularExpressionRandomizer(final String regularExpression, final long seed); static RegularExpressionRandomizer aNewRegularExpressionRandomizer(final String regularExpression); static RegularExpressionRandomizer aNewRegularExpressionRandomizer(final String regularExpression, final long seed); @Override String getRandomValue(); } | RegularExpressionRandomizer extends FakerBasedRandomizer<String> { @Override public String getRandomValue() { return faker.regexify(removeLeadingAndTailingBoundaryMatchers(regularExpression)); } RegularExpressionRandomizer(final String regularExpression); RegularExpressionRandomizer(final String regularExpression, final long seed); static RegularExpressionRandomizer aNewRegularExpressionRandomizer(final String regularExpression); static RegularExpressionRandomizer aNewRegularExpressionRandomizer(final String regularExpression, final long seed); @Override String getRandomValue(); } |
@Test void leadingAndTailingBoundaryMatcherIsRemoved() { RegularExpressionRandomizer randomizer = new RegularExpressionRandomizer("^A$"); String actual = randomizer.getRandomValue(); then(actual).isEqualTo("A"); } | @Override public String getRandomValue() { return faker.regexify(removeLeadingAndTailingBoundaryMatchers(regularExpression)); } | RegularExpressionRandomizer extends FakerBasedRandomizer<String> { @Override public String getRandomValue() { return faker.regexify(removeLeadingAndTailingBoundaryMatchers(regularExpression)); } } | RegularExpressionRandomizer extends FakerBasedRandomizer<String> { @Override public String getRandomValue() { return faker.regexify(removeLeadingAndTailingBoundaryMatchers(regularExpression)); } RegularExpressionRandomizer(final String regularExpression); RegularExpressionRandomizer(final String regularExpression, final long seed); } | RegularExpressionRandomizer extends FakerBasedRandomizer<String> { @Override public String getRandomValue() { return faker.regexify(removeLeadingAndTailingBoundaryMatchers(regularExpression)); } RegularExpressionRandomizer(final String regularExpression); RegularExpressionRandomizer(final String regularExpression, final long seed); static RegularExpressionRandomizer aNewRegularExpressionRandomizer(final String regularExpression); static RegularExpressionRandomizer aNewRegularExpressionRandomizer(final String regularExpression, final long seed); @Override String getRandomValue(); } | RegularExpressionRandomizer extends FakerBasedRandomizer<String> { @Override public String getRandomValue() { return faker.regexify(removeLeadingAndTailingBoundaryMatchers(regularExpression)); } RegularExpressionRandomizer(final String regularExpression); RegularExpressionRandomizer(final String regularExpression, final long seed); static RegularExpressionRandomizer aNewRegularExpressionRandomizer(final String regularExpression); static RegularExpressionRandomizer aNewRegularExpressionRandomizer(final String regularExpression, final long seed); @Override String getRandomValue(); } |
@Test void getWrapperTypeTest() { assertThat(ReflectionUtils.getWrapperType(Byte.TYPE)).isEqualTo(Byte.class); assertThat(ReflectionUtils.getWrapperType(Short.TYPE)).isEqualTo(Short.class); assertThat(ReflectionUtils.getWrapperType(Integer.TYPE)).isEqualTo(Integer.class); assertThat(ReflectionUtils.getWrapperType(Long.TYPE)).isEqualTo(Long.class); assertThat(ReflectionUtils.getWrapperType(Double.TYPE)).isEqualTo(Double.class); assertThat(ReflectionUtils.getWrapperType(Float.TYPE)).isEqualTo(Float.class); assertThat(ReflectionUtils.getWrapperType(Boolean.TYPE)).isEqualTo(Boolean.class); assertThat(ReflectionUtils.getWrapperType(Character.TYPE)).isEqualTo(Character.class); assertThat(ReflectionUtils.getWrapperType(String.class)).isEqualTo(String.class); } | public static Class<?> getWrapperType(Class<?> primitiveType) { for(PrimitiveEnum p : PrimitiveEnum.values()) { if(p.getType().equals(primitiveType)) { return p.getClazz(); } } return primitiveType; } | ReflectionUtils { public static Class<?> getWrapperType(Class<?> primitiveType) { for(PrimitiveEnum p : PrimitiveEnum.values()) { if(p.getType().equals(primitiveType)) { return p.getClazz(); } } return primitiveType; } } | ReflectionUtils { public static Class<?> getWrapperType(Class<?> primitiveType) { for(PrimitiveEnum p : PrimitiveEnum.values()) { if(p.getType().equals(primitiveType)) { return p.getClazz(); } } return primitiveType; } private ReflectionUtils(); } | ReflectionUtils { public static Class<?> getWrapperType(Class<?> primitiveType) { for(PrimitiveEnum p : PrimitiveEnum.values()) { if(p.getType().equals(primitiveType)) { return p.getClazz(); } } return primitiveType; } private ReflectionUtils(); @SuppressWarnings("unchecked") static Randomizer<T> asRandomizer(final Supplier<T> supplier); static List<Field> getDeclaredFields(T type); static List<Field> getInheritedFields(Class<?> type); static void setProperty(final Object object, final Field field, final Object value); static void setFieldValue(final Object object, final Field field, final Object value); static Object getFieldValue(final Object object, final Field field); static Class<?> getWrapperType(Class<?> primitiveType); static boolean isPrimitiveFieldWithDefaultValue(final Object object, final Field field); static boolean isStatic(final Field field); static boolean isInterface(final Class<?> type); static boolean isAbstract(final Class<T> type); static boolean isPublic(final Class<T> type); static boolean isArrayType(final Class<?> type); static boolean isEnumType(final Class<?> type); static boolean isCollectionType(final Class<?> type); static boolean isCollectionType(final Type type); static boolean isPopulatable(final Type type); static boolean isIntrospectable(final Class<?> type); static boolean isMapType(final Class<?> type); static boolean isJdkBuiltIn(final Class<?> type); static boolean isParameterizedType(final Type type); static boolean isWildcardType(final Type type); static boolean isTypeVariable(final Type type); static List<Class<?>> getPublicConcreteSubTypesOf(final Class<T> type); static List<Class<?>> filterSameParameterizedTypes(final List<Class<?>> types, final Type type); static T getAnnotation(Field field, Class<T> annotationType); static boolean isAnnotationPresent(Field field, Class<? extends Annotation> annotationType); static Collection<?> getEmptyImplementationForCollectionInterface(final Class<?> collectionInterface); static Collection<?> createEmptyCollectionForType(Class<?> fieldType, int initialSize); static Map<?, ?> getEmptyImplementationForMapInterface(final Class<?> mapInterface); static Optional<Method> getReadMethod(Field field); @SuppressWarnings("unchecked") static Randomizer<T> newInstance(final Class<T> type, final RandomizerArgument[] randomizerArguments); } | ReflectionUtils { public static Class<?> getWrapperType(Class<?> primitiveType) { for(PrimitiveEnum p : PrimitiveEnum.values()) { if(p.getType().equals(primitiveType)) { return p.getClazz(); } } return primitiveType; } private ReflectionUtils(); @SuppressWarnings("unchecked") static Randomizer<T> asRandomizer(final Supplier<T> supplier); static List<Field> getDeclaredFields(T type); static List<Field> getInheritedFields(Class<?> type); static void setProperty(final Object object, final Field field, final Object value); static void setFieldValue(final Object object, final Field field, final Object value); static Object getFieldValue(final Object object, final Field field); static Class<?> getWrapperType(Class<?> primitiveType); static boolean isPrimitiveFieldWithDefaultValue(final Object object, final Field field); static boolean isStatic(final Field field); static boolean isInterface(final Class<?> type); static boolean isAbstract(final Class<T> type); static boolean isPublic(final Class<T> type); static boolean isArrayType(final Class<?> type); static boolean isEnumType(final Class<?> type); static boolean isCollectionType(final Class<?> type); static boolean isCollectionType(final Type type); static boolean isPopulatable(final Type type); static boolean isIntrospectable(final Class<?> type); static boolean isMapType(final Class<?> type); static boolean isJdkBuiltIn(final Class<?> type); static boolean isParameterizedType(final Type type); static boolean isWildcardType(final Type type); static boolean isTypeVariable(final Type type); static List<Class<?>> getPublicConcreteSubTypesOf(final Class<T> type); static List<Class<?>> filterSameParameterizedTypes(final List<Class<?>> types, final Type type); static T getAnnotation(Field field, Class<T> annotationType); static boolean isAnnotationPresent(Field field, Class<? extends Annotation> annotationType); static Collection<?> getEmptyImplementationForCollectionInterface(final Class<?> collectionInterface); static Collection<?> createEmptyCollectionForType(Class<?> fieldType, int initialSize); static Map<?, ?> getEmptyImplementationForMapInterface(final Class<?> mapInterface); static Optional<Method> getReadMethod(Field field); @SuppressWarnings("unchecked") static Randomizer<T> newInstance(final Class<T> type, final RandomizerArgument[] randomizerArguments); } |
@Test void testIsPrimitiveFieldWithDefaultValue() throws Exception { Class<PrimitiveFieldsWithDefaultValuesBean> defaultValueClass = PrimitiveFieldsWithDefaultValuesBean.class; PrimitiveFieldsWithDefaultValuesBean defaultValueBean = new PrimitiveFieldsWithDefaultValuesBean(); assertThat(ReflectionUtils.isPrimitiveFieldWithDefaultValue(defaultValueBean, defaultValueClass.getField("bool"))).isTrue(); assertThat(ReflectionUtils.isPrimitiveFieldWithDefaultValue(defaultValueBean, defaultValueClass.getField("b"))).isTrue(); assertThat(ReflectionUtils.isPrimitiveFieldWithDefaultValue(defaultValueBean, defaultValueClass.getField("s"))).isTrue(); assertThat(ReflectionUtils.isPrimitiveFieldWithDefaultValue(defaultValueBean, defaultValueClass.getField("i"))).isTrue(); assertThat(ReflectionUtils.isPrimitiveFieldWithDefaultValue(defaultValueBean, defaultValueClass.getField("l"))).isTrue(); assertThat(ReflectionUtils.isPrimitiveFieldWithDefaultValue(defaultValueBean, defaultValueClass.getField("f"))).isTrue(); assertThat(ReflectionUtils.isPrimitiveFieldWithDefaultValue(defaultValueBean, defaultValueClass.getField("d"))).isTrue(); assertThat(ReflectionUtils.isPrimitiveFieldWithDefaultValue(defaultValueBean, defaultValueClass.getField("c"))).isTrue(); Class<PrimitiveFieldsWithNonDefaultValuesBean> nonDefaultValueClass = PrimitiveFieldsWithNonDefaultValuesBean.class; PrimitiveFieldsWithNonDefaultValuesBean nonDefaultValueBean = new PrimitiveFieldsWithNonDefaultValuesBean(); assertThat(ReflectionUtils.isPrimitiveFieldWithDefaultValue(nonDefaultValueBean, nonDefaultValueClass.getField("bool"))).isFalse(); assertThat(ReflectionUtils.isPrimitiveFieldWithDefaultValue(nonDefaultValueBean, nonDefaultValueClass.getField("b"))).isFalse(); assertThat(ReflectionUtils.isPrimitiveFieldWithDefaultValue(nonDefaultValueBean, nonDefaultValueClass.getField("s"))).isFalse(); assertThat(ReflectionUtils.isPrimitiveFieldWithDefaultValue(nonDefaultValueBean, nonDefaultValueClass.getField("i"))).isFalse(); assertThat(ReflectionUtils.isPrimitiveFieldWithDefaultValue(nonDefaultValueBean, nonDefaultValueClass.getField("l"))).isFalse(); assertThat(ReflectionUtils.isPrimitiveFieldWithDefaultValue(nonDefaultValueBean, nonDefaultValueClass.getField("f"))).isFalse(); assertThat(ReflectionUtils.isPrimitiveFieldWithDefaultValue(nonDefaultValueBean, nonDefaultValueClass.getField("d"))).isFalse(); assertThat(ReflectionUtils.isPrimitiveFieldWithDefaultValue(nonDefaultValueBean, nonDefaultValueClass.getField("c"))).isFalse(); } | public static boolean isPrimitiveFieldWithDefaultValue(final Object object, final Field field) throws IllegalAccessException { Class<?> fieldType = field.getType(); if (!fieldType.isPrimitive()) { return false; } Object fieldValue = getFieldValue(object, field); if (fieldValue == null) { return false; } if (fieldType.equals(boolean.class) && (boolean) fieldValue == false) { return true; } if (fieldType.equals(byte.class) && (byte) fieldValue == (byte) 0) { return true; } if (fieldType.equals(short.class) && (short) fieldValue == (short) 0) { return true; } if (fieldType.equals(int.class) && (int) fieldValue == 0) { return true; } if (fieldType.equals(long.class) && (long) fieldValue == 0L) { return true; } if (fieldType.equals(float.class) && (float) fieldValue == 0.0F) { return true; } if (fieldType.equals(double.class) && (double) fieldValue == 0.0D) { return true; } if (fieldType.equals(char.class) && (char) fieldValue == '\u0000') { return true; } return false; } | ReflectionUtils { public static boolean isPrimitiveFieldWithDefaultValue(final Object object, final Field field) throws IllegalAccessException { Class<?> fieldType = field.getType(); if (!fieldType.isPrimitive()) { return false; } Object fieldValue = getFieldValue(object, field); if (fieldValue == null) { return false; } if (fieldType.equals(boolean.class) && (boolean) fieldValue == false) { return true; } if (fieldType.equals(byte.class) && (byte) fieldValue == (byte) 0) { return true; } if (fieldType.equals(short.class) && (short) fieldValue == (short) 0) { return true; } if (fieldType.equals(int.class) && (int) fieldValue == 0) { return true; } if (fieldType.equals(long.class) && (long) fieldValue == 0L) { return true; } if (fieldType.equals(float.class) && (float) fieldValue == 0.0F) { return true; } if (fieldType.equals(double.class) && (double) fieldValue == 0.0D) { return true; } if (fieldType.equals(char.class) && (char) fieldValue == '\u0000') { return true; } return false; } } | ReflectionUtils { public static boolean isPrimitiveFieldWithDefaultValue(final Object object, final Field field) throws IllegalAccessException { Class<?> fieldType = field.getType(); if (!fieldType.isPrimitive()) { return false; } Object fieldValue = getFieldValue(object, field); if (fieldValue == null) { return false; } if (fieldType.equals(boolean.class) && (boolean) fieldValue == false) { return true; } if (fieldType.equals(byte.class) && (byte) fieldValue == (byte) 0) { return true; } if (fieldType.equals(short.class) && (short) fieldValue == (short) 0) { return true; } if (fieldType.equals(int.class) && (int) fieldValue == 0) { return true; } if (fieldType.equals(long.class) && (long) fieldValue == 0L) { return true; } if (fieldType.equals(float.class) && (float) fieldValue == 0.0F) { return true; } if (fieldType.equals(double.class) && (double) fieldValue == 0.0D) { return true; } if (fieldType.equals(char.class) && (char) fieldValue == '\u0000') { return true; } return false; } private ReflectionUtils(); } | ReflectionUtils { public static boolean isPrimitiveFieldWithDefaultValue(final Object object, final Field field) throws IllegalAccessException { Class<?> fieldType = field.getType(); if (!fieldType.isPrimitive()) { return false; } Object fieldValue = getFieldValue(object, field); if (fieldValue == null) { return false; } if (fieldType.equals(boolean.class) && (boolean) fieldValue == false) { return true; } if (fieldType.equals(byte.class) && (byte) fieldValue == (byte) 0) { return true; } if (fieldType.equals(short.class) && (short) fieldValue == (short) 0) { return true; } if (fieldType.equals(int.class) && (int) fieldValue == 0) { return true; } if (fieldType.equals(long.class) && (long) fieldValue == 0L) { return true; } if (fieldType.equals(float.class) && (float) fieldValue == 0.0F) { return true; } if (fieldType.equals(double.class) && (double) fieldValue == 0.0D) { return true; } if (fieldType.equals(char.class) && (char) fieldValue == '\u0000') { return true; } return false; } private ReflectionUtils(); @SuppressWarnings("unchecked") static Randomizer<T> asRandomizer(final Supplier<T> supplier); static List<Field> getDeclaredFields(T type); static List<Field> getInheritedFields(Class<?> type); static void setProperty(final Object object, final Field field, final Object value); static void setFieldValue(final Object object, final Field field, final Object value); static Object getFieldValue(final Object object, final Field field); static Class<?> getWrapperType(Class<?> primitiveType); static boolean isPrimitiveFieldWithDefaultValue(final Object object, final Field field); static boolean isStatic(final Field field); static boolean isInterface(final Class<?> type); static boolean isAbstract(final Class<T> type); static boolean isPublic(final Class<T> type); static boolean isArrayType(final Class<?> type); static boolean isEnumType(final Class<?> type); static boolean isCollectionType(final Class<?> type); static boolean isCollectionType(final Type type); static boolean isPopulatable(final Type type); static boolean isIntrospectable(final Class<?> type); static boolean isMapType(final Class<?> type); static boolean isJdkBuiltIn(final Class<?> type); static boolean isParameterizedType(final Type type); static boolean isWildcardType(final Type type); static boolean isTypeVariable(final Type type); static List<Class<?>> getPublicConcreteSubTypesOf(final Class<T> type); static List<Class<?>> filterSameParameterizedTypes(final List<Class<?>> types, final Type type); static T getAnnotation(Field field, Class<T> annotationType); static boolean isAnnotationPresent(Field field, Class<? extends Annotation> annotationType); static Collection<?> getEmptyImplementationForCollectionInterface(final Class<?> collectionInterface); static Collection<?> createEmptyCollectionForType(Class<?> fieldType, int initialSize); static Map<?, ?> getEmptyImplementationForMapInterface(final Class<?> mapInterface); static Optional<Method> getReadMethod(Field field); @SuppressWarnings("unchecked") static Randomizer<T> newInstance(final Class<T> type, final RandomizerArgument[] randomizerArguments); } | ReflectionUtils { public static boolean isPrimitiveFieldWithDefaultValue(final Object object, final Field field) throws IllegalAccessException { Class<?> fieldType = field.getType(); if (!fieldType.isPrimitive()) { return false; } Object fieldValue = getFieldValue(object, field); if (fieldValue == null) { return false; } if (fieldType.equals(boolean.class) && (boolean) fieldValue == false) { return true; } if (fieldType.equals(byte.class) && (byte) fieldValue == (byte) 0) { return true; } if (fieldType.equals(short.class) && (short) fieldValue == (short) 0) { return true; } if (fieldType.equals(int.class) && (int) fieldValue == 0) { return true; } if (fieldType.equals(long.class) && (long) fieldValue == 0L) { return true; } if (fieldType.equals(float.class) && (float) fieldValue == 0.0F) { return true; } if (fieldType.equals(double.class) && (double) fieldValue == 0.0D) { return true; } if (fieldType.equals(char.class) && (char) fieldValue == '\u0000') { return true; } return false; } private ReflectionUtils(); @SuppressWarnings("unchecked") static Randomizer<T> asRandomizer(final Supplier<T> supplier); static List<Field> getDeclaredFields(T type); static List<Field> getInheritedFields(Class<?> type); static void setProperty(final Object object, final Field field, final Object value); static void setFieldValue(final Object object, final Field field, final Object value); static Object getFieldValue(final Object object, final Field field); static Class<?> getWrapperType(Class<?> primitiveType); static boolean isPrimitiveFieldWithDefaultValue(final Object object, final Field field); static boolean isStatic(final Field field); static boolean isInterface(final Class<?> type); static boolean isAbstract(final Class<T> type); static boolean isPublic(final Class<T> type); static boolean isArrayType(final Class<?> type); static boolean isEnumType(final Class<?> type); static boolean isCollectionType(final Class<?> type); static boolean isCollectionType(final Type type); static boolean isPopulatable(final Type type); static boolean isIntrospectable(final Class<?> type); static boolean isMapType(final Class<?> type); static boolean isJdkBuiltIn(final Class<?> type); static boolean isParameterizedType(final Type type); static boolean isWildcardType(final Type type); static boolean isTypeVariable(final Type type); static List<Class<?>> getPublicConcreteSubTypesOf(final Class<T> type); static List<Class<?>> filterSameParameterizedTypes(final List<Class<?>> types, final Type type); static T getAnnotation(Field field, Class<T> annotationType); static boolean isAnnotationPresent(Field field, Class<? extends Annotation> annotationType); static Collection<?> getEmptyImplementationForCollectionInterface(final Class<?> collectionInterface); static Collection<?> createEmptyCollectionForType(Class<?> fieldType, int initialSize); static Map<?, ?> getEmptyImplementationForMapInterface(final Class<?> mapInterface); static Optional<Method> getReadMethod(Field field); @SuppressWarnings("unchecked") static Randomizer<T> newInstance(final Class<T> type, final RandomizerArgument[] randomizerArguments); } |
@Test void testGetReadMethod() throws NoSuchFieldException { assertThat(ReflectionUtils.getReadMethod(PrimitiveFieldsWithDefaultValuesBean.class.getDeclaredField("b"))).isEmpty(); final Optional<Method> readMethod = ReflectionUtils.getReadMethod(Foo.class.getDeclaredField("bar")); assertThat(readMethod).isNotNull(); assertThat(readMethod.get().getName()).isEqualTo("getBar"); } | public static Optional<Method> getReadMethod(Field field) { String fieldName = field.getName(); Class<?> fieldClass = field.getDeclaringClass(); String capitalizedFieldName = fieldName.substring(0, 1).toUpperCase(ENGLISH) + fieldName.substring(1); Optional<Method> getter = getPublicMethod("get" + capitalizedFieldName, fieldClass); if (getter.isPresent()) { return getter; } return getPublicMethod("is" + capitalizedFieldName, fieldClass); } | ReflectionUtils { public static Optional<Method> getReadMethod(Field field) { String fieldName = field.getName(); Class<?> fieldClass = field.getDeclaringClass(); String capitalizedFieldName = fieldName.substring(0, 1).toUpperCase(ENGLISH) + fieldName.substring(1); Optional<Method> getter = getPublicMethod("get" + capitalizedFieldName, fieldClass); if (getter.isPresent()) { return getter; } return getPublicMethod("is" + capitalizedFieldName, fieldClass); } } | ReflectionUtils { public static Optional<Method> getReadMethod(Field field) { String fieldName = field.getName(); Class<?> fieldClass = field.getDeclaringClass(); String capitalizedFieldName = fieldName.substring(0, 1).toUpperCase(ENGLISH) + fieldName.substring(1); Optional<Method> getter = getPublicMethod("get" + capitalizedFieldName, fieldClass); if (getter.isPresent()) { return getter; } return getPublicMethod("is" + capitalizedFieldName, fieldClass); } private ReflectionUtils(); } | ReflectionUtils { public static Optional<Method> getReadMethod(Field field) { String fieldName = field.getName(); Class<?> fieldClass = field.getDeclaringClass(); String capitalizedFieldName = fieldName.substring(0, 1).toUpperCase(ENGLISH) + fieldName.substring(1); Optional<Method> getter = getPublicMethod("get" + capitalizedFieldName, fieldClass); if (getter.isPresent()) { return getter; } return getPublicMethod("is" + capitalizedFieldName, fieldClass); } private ReflectionUtils(); @SuppressWarnings("unchecked") static Randomizer<T> asRandomizer(final Supplier<T> supplier); static List<Field> getDeclaredFields(T type); static List<Field> getInheritedFields(Class<?> type); static void setProperty(final Object object, final Field field, final Object value); static void setFieldValue(final Object object, final Field field, final Object value); static Object getFieldValue(final Object object, final Field field); static Class<?> getWrapperType(Class<?> primitiveType); static boolean isPrimitiveFieldWithDefaultValue(final Object object, final Field field); static boolean isStatic(final Field field); static boolean isInterface(final Class<?> type); static boolean isAbstract(final Class<T> type); static boolean isPublic(final Class<T> type); static boolean isArrayType(final Class<?> type); static boolean isEnumType(final Class<?> type); static boolean isCollectionType(final Class<?> type); static boolean isCollectionType(final Type type); static boolean isPopulatable(final Type type); static boolean isIntrospectable(final Class<?> type); static boolean isMapType(final Class<?> type); static boolean isJdkBuiltIn(final Class<?> type); static boolean isParameterizedType(final Type type); static boolean isWildcardType(final Type type); static boolean isTypeVariable(final Type type); static List<Class<?>> getPublicConcreteSubTypesOf(final Class<T> type); static List<Class<?>> filterSameParameterizedTypes(final List<Class<?>> types, final Type type); static T getAnnotation(Field field, Class<T> annotationType); static boolean isAnnotationPresent(Field field, Class<? extends Annotation> annotationType); static Collection<?> getEmptyImplementationForCollectionInterface(final Class<?> collectionInterface); static Collection<?> createEmptyCollectionForType(Class<?> fieldType, int initialSize); static Map<?, ?> getEmptyImplementationForMapInterface(final Class<?> mapInterface); static Optional<Method> getReadMethod(Field field); @SuppressWarnings("unchecked") static Randomizer<T> newInstance(final Class<T> type, final RandomizerArgument[] randomizerArguments); } | ReflectionUtils { public static Optional<Method> getReadMethod(Field field) { String fieldName = field.getName(); Class<?> fieldClass = field.getDeclaringClass(); String capitalizedFieldName = fieldName.substring(0, 1).toUpperCase(ENGLISH) + fieldName.substring(1); Optional<Method> getter = getPublicMethod("get" + capitalizedFieldName, fieldClass); if (getter.isPresent()) { return getter; } return getPublicMethod("is" + capitalizedFieldName, fieldClass); } private ReflectionUtils(); @SuppressWarnings("unchecked") static Randomizer<T> asRandomizer(final Supplier<T> supplier); static List<Field> getDeclaredFields(T type); static List<Field> getInheritedFields(Class<?> type); static void setProperty(final Object object, final Field field, final Object value); static void setFieldValue(final Object object, final Field field, final Object value); static Object getFieldValue(final Object object, final Field field); static Class<?> getWrapperType(Class<?> primitiveType); static boolean isPrimitiveFieldWithDefaultValue(final Object object, final Field field); static boolean isStatic(final Field field); static boolean isInterface(final Class<?> type); static boolean isAbstract(final Class<T> type); static boolean isPublic(final Class<T> type); static boolean isArrayType(final Class<?> type); static boolean isEnumType(final Class<?> type); static boolean isCollectionType(final Class<?> type); static boolean isCollectionType(final Type type); static boolean isPopulatable(final Type type); static boolean isIntrospectable(final Class<?> type); static boolean isMapType(final Class<?> type); static boolean isJdkBuiltIn(final Class<?> type); static boolean isParameterizedType(final Type type); static boolean isWildcardType(final Type type); static boolean isTypeVariable(final Type type); static List<Class<?>> getPublicConcreteSubTypesOf(final Class<T> type); static List<Class<?>> filterSameParameterizedTypes(final List<Class<?>> types, final Type type); static T getAnnotation(Field field, Class<T> annotationType); static boolean isAnnotationPresent(Field field, Class<? extends Annotation> annotationType); static Collection<?> getEmptyImplementationForCollectionInterface(final Class<?> collectionInterface); static Collection<?> createEmptyCollectionForType(Class<?> fieldType, int initialSize); static Map<?, ?> getEmptyImplementationForMapInterface(final Class<?> mapInterface); static Optional<Method> getReadMethod(Field field); @SuppressWarnings("unchecked") static Randomizer<T> newInstance(final Class<T> type, final RandomizerArgument[] randomizerArguments); } |
@Test void testGetAnnotation() throws NoSuchFieldException { Field field = AnnotatedBean.class.getDeclaredField("fieldAnnotation"); assertThat(ReflectionUtils.getAnnotation(field, NotNull.class)).isInstanceOf(NotNull.class); field = AnnotatedBean.class.getDeclaredField("methodAnnotation"); assertThat(ReflectionUtils.getAnnotation(field, NotNull.class)).isInstanceOf(NotNull.class); field = AnnotatedBean.class.getDeclaredField("noAnnotation"); assertThat(ReflectionUtils.getAnnotation(field, NotNull.class)).isNull(); } | public static <T extends Annotation> T getAnnotation(Field field, Class<T> annotationType) { return field.getAnnotation(annotationType) == null ? getAnnotationFromReadMethod(getReadMethod(field).orElse(null), annotationType) : field.getAnnotation(annotationType); } | ReflectionUtils { public static <T extends Annotation> T getAnnotation(Field field, Class<T> annotationType) { return field.getAnnotation(annotationType) == null ? getAnnotationFromReadMethod(getReadMethod(field).orElse(null), annotationType) : field.getAnnotation(annotationType); } } | ReflectionUtils { public static <T extends Annotation> T getAnnotation(Field field, Class<T> annotationType) { return field.getAnnotation(annotationType) == null ? getAnnotationFromReadMethod(getReadMethod(field).orElse(null), annotationType) : field.getAnnotation(annotationType); } private ReflectionUtils(); } | ReflectionUtils { public static <T extends Annotation> T getAnnotation(Field field, Class<T> annotationType) { return field.getAnnotation(annotationType) == null ? getAnnotationFromReadMethod(getReadMethod(field).orElse(null), annotationType) : field.getAnnotation(annotationType); } private ReflectionUtils(); @SuppressWarnings("unchecked") static Randomizer<T> asRandomizer(final Supplier<T> supplier); static List<Field> getDeclaredFields(T type); static List<Field> getInheritedFields(Class<?> type); static void setProperty(final Object object, final Field field, final Object value); static void setFieldValue(final Object object, final Field field, final Object value); static Object getFieldValue(final Object object, final Field field); static Class<?> getWrapperType(Class<?> primitiveType); static boolean isPrimitiveFieldWithDefaultValue(final Object object, final Field field); static boolean isStatic(final Field field); static boolean isInterface(final Class<?> type); static boolean isAbstract(final Class<T> type); static boolean isPublic(final Class<T> type); static boolean isArrayType(final Class<?> type); static boolean isEnumType(final Class<?> type); static boolean isCollectionType(final Class<?> type); static boolean isCollectionType(final Type type); static boolean isPopulatable(final Type type); static boolean isIntrospectable(final Class<?> type); static boolean isMapType(final Class<?> type); static boolean isJdkBuiltIn(final Class<?> type); static boolean isParameterizedType(final Type type); static boolean isWildcardType(final Type type); static boolean isTypeVariable(final Type type); static List<Class<?>> getPublicConcreteSubTypesOf(final Class<T> type); static List<Class<?>> filterSameParameterizedTypes(final List<Class<?>> types, final Type type); static T getAnnotation(Field field, Class<T> annotationType); static boolean isAnnotationPresent(Field field, Class<? extends Annotation> annotationType); static Collection<?> getEmptyImplementationForCollectionInterface(final Class<?> collectionInterface); static Collection<?> createEmptyCollectionForType(Class<?> fieldType, int initialSize); static Map<?, ?> getEmptyImplementationForMapInterface(final Class<?> mapInterface); static Optional<Method> getReadMethod(Field field); @SuppressWarnings("unchecked") static Randomizer<T> newInstance(final Class<T> type, final RandomizerArgument[] randomizerArguments); } | ReflectionUtils { public static <T extends Annotation> T getAnnotation(Field field, Class<T> annotationType) { return field.getAnnotation(annotationType) == null ? getAnnotationFromReadMethod(getReadMethod(field).orElse(null), annotationType) : field.getAnnotation(annotationType); } private ReflectionUtils(); @SuppressWarnings("unchecked") static Randomizer<T> asRandomizer(final Supplier<T> supplier); static List<Field> getDeclaredFields(T type); static List<Field> getInheritedFields(Class<?> type); static void setProperty(final Object object, final Field field, final Object value); static void setFieldValue(final Object object, final Field field, final Object value); static Object getFieldValue(final Object object, final Field field); static Class<?> getWrapperType(Class<?> primitiveType); static boolean isPrimitiveFieldWithDefaultValue(final Object object, final Field field); static boolean isStatic(final Field field); static boolean isInterface(final Class<?> type); static boolean isAbstract(final Class<T> type); static boolean isPublic(final Class<T> type); static boolean isArrayType(final Class<?> type); static boolean isEnumType(final Class<?> type); static boolean isCollectionType(final Class<?> type); static boolean isCollectionType(final Type type); static boolean isPopulatable(final Type type); static boolean isIntrospectable(final Class<?> type); static boolean isMapType(final Class<?> type); static boolean isJdkBuiltIn(final Class<?> type); static boolean isParameterizedType(final Type type); static boolean isWildcardType(final Type type); static boolean isTypeVariable(final Type type); static List<Class<?>> getPublicConcreteSubTypesOf(final Class<T> type); static List<Class<?>> filterSameParameterizedTypes(final List<Class<?>> types, final Type type); static T getAnnotation(Field field, Class<T> annotationType); static boolean isAnnotationPresent(Field field, Class<? extends Annotation> annotationType); static Collection<?> getEmptyImplementationForCollectionInterface(final Class<?> collectionInterface); static Collection<?> createEmptyCollectionForType(Class<?> fieldType, int initialSize); static Map<?, ?> getEmptyImplementationForMapInterface(final Class<?> mapInterface); static Optional<Method> getReadMethod(Field field); @SuppressWarnings("unchecked") static Randomizer<T> newInstance(final Class<T> type, final RandomizerArgument[] randomizerArguments); } |
@Test void testIsAnnotationPresent() throws NoSuchFieldException { Field field = AnnotatedBean.class.getDeclaredField("fieldAnnotation"); assertThat(ReflectionUtils.isAnnotationPresent(field, NotNull.class)).isTrue(); field = AnnotatedBean.class.getDeclaredField("methodAnnotation"); assertThat(ReflectionUtils.isAnnotationPresent(field, NotNull.class)).isTrue(); field = AnnotatedBean.class.getDeclaredField("noAnnotation"); assertThat(ReflectionUtils.isAnnotationPresent(field, NotNull.class)).isFalse(); } | public static boolean isAnnotationPresent(Field field, Class<? extends Annotation> annotationType) { final Optional<Method> readMethod = getReadMethod(field); return field.isAnnotationPresent(annotationType) || readMethod.isPresent() && readMethod.get().isAnnotationPresent(annotationType); } | ReflectionUtils { public static boolean isAnnotationPresent(Field field, Class<? extends Annotation> annotationType) { final Optional<Method> readMethod = getReadMethod(field); return field.isAnnotationPresent(annotationType) || readMethod.isPresent() && readMethod.get().isAnnotationPresent(annotationType); } } | ReflectionUtils { public static boolean isAnnotationPresent(Field field, Class<? extends Annotation> annotationType) { final Optional<Method> readMethod = getReadMethod(field); return field.isAnnotationPresent(annotationType) || readMethod.isPresent() && readMethod.get().isAnnotationPresent(annotationType); } private ReflectionUtils(); } | ReflectionUtils { public static boolean isAnnotationPresent(Field field, Class<? extends Annotation> annotationType) { final Optional<Method> readMethod = getReadMethod(field); return field.isAnnotationPresent(annotationType) || readMethod.isPresent() && readMethod.get().isAnnotationPresent(annotationType); } private ReflectionUtils(); @SuppressWarnings("unchecked") static Randomizer<T> asRandomizer(final Supplier<T> supplier); static List<Field> getDeclaredFields(T type); static List<Field> getInheritedFields(Class<?> type); static void setProperty(final Object object, final Field field, final Object value); static void setFieldValue(final Object object, final Field field, final Object value); static Object getFieldValue(final Object object, final Field field); static Class<?> getWrapperType(Class<?> primitiveType); static boolean isPrimitiveFieldWithDefaultValue(final Object object, final Field field); static boolean isStatic(final Field field); static boolean isInterface(final Class<?> type); static boolean isAbstract(final Class<T> type); static boolean isPublic(final Class<T> type); static boolean isArrayType(final Class<?> type); static boolean isEnumType(final Class<?> type); static boolean isCollectionType(final Class<?> type); static boolean isCollectionType(final Type type); static boolean isPopulatable(final Type type); static boolean isIntrospectable(final Class<?> type); static boolean isMapType(final Class<?> type); static boolean isJdkBuiltIn(final Class<?> type); static boolean isParameterizedType(final Type type); static boolean isWildcardType(final Type type); static boolean isTypeVariable(final Type type); static List<Class<?>> getPublicConcreteSubTypesOf(final Class<T> type); static List<Class<?>> filterSameParameterizedTypes(final List<Class<?>> types, final Type type); static T getAnnotation(Field field, Class<T> annotationType); static boolean isAnnotationPresent(Field field, Class<? extends Annotation> annotationType); static Collection<?> getEmptyImplementationForCollectionInterface(final Class<?> collectionInterface); static Collection<?> createEmptyCollectionForType(Class<?> fieldType, int initialSize); static Map<?, ?> getEmptyImplementationForMapInterface(final Class<?> mapInterface); static Optional<Method> getReadMethod(Field field); @SuppressWarnings("unchecked") static Randomizer<T> newInstance(final Class<T> type, final RandomizerArgument[] randomizerArguments); } | ReflectionUtils { public static boolean isAnnotationPresent(Field field, Class<? extends Annotation> annotationType) { final Optional<Method> readMethod = getReadMethod(field); return field.isAnnotationPresent(annotationType) || readMethod.isPresent() && readMethod.get().isAnnotationPresent(annotationType); } private ReflectionUtils(); @SuppressWarnings("unchecked") static Randomizer<T> asRandomizer(final Supplier<T> supplier); static List<Field> getDeclaredFields(T type); static List<Field> getInheritedFields(Class<?> type); static void setProperty(final Object object, final Field field, final Object value); static void setFieldValue(final Object object, final Field field, final Object value); static Object getFieldValue(final Object object, final Field field); static Class<?> getWrapperType(Class<?> primitiveType); static boolean isPrimitiveFieldWithDefaultValue(final Object object, final Field field); static boolean isStatic(final Field field); static boolean isInterface(final Class<?> type); static boolean isAbstract(final Class<T> type); static boolean isPublic(final Class<T> type); static boolean isArrayType(final Class<?> type); static boolean isEnumType(final Class<?> type); static boolean isCollectionType(final Class<?> type); static boolean isCollectionType(final Type type); static boolean isPopulatable(final Type type); static boolean isIntrospectable(final Class<?> type); static boolean isMapType(final Class<?> type); static boolean isJdkBuiltIn(final Class<?> type); static boolean isParameterizedType(final Type type); static boolean isWildcardType(final Type type); static boolean isTypeVariable(final Type type); static List<Class<?>> getPublicConcreteSubTypesOf(final Class<T> type); static List<Class<?>> filterSameParameterizedTypes(final List<Class<?>> types, final Type type); static T getAnnotation(Field field, Class<T> annotationType); static boolean isAnnotationPresent(Field field, Class<? extends Annotation> annotationType); static Collection<?> getEmptyImplementationForCollectionInterface(final Class<?> collectionInterface); static Collection<?> createEmptyCollectionForType(Class<?> fieldType, int initialSize); static Map<?, ?> getEmptyImplementationForMapInterface(final Class<?> mapInterface); static Optional<Method> getReadMethod(Field field); @SuppressWarnings("unchecked") static Randomizer<T> newInstance(final Class<T> type, final RandomizerArgument[] randomizerArguments); } |
@Test void testGetEmptyImplementationForCollectionInterface() { Collection<?> collection = ReflectionUtils.getEmptyImplementationForCollectionInterface(List.class); assertThat(collection).isInstanceOf(ArrayList.class).isEmpty(); } | public static Collection<?> getEmptyImplementationForCollectionInterface(final Class<?> collectionInterface) { Collection<?> collection = new ArrayList<>(); if (List.class.isAssignableFrom(collectionInterface)) { collection = new ArrayList<>(); } else if (NavigableSet.class.isAssignableFrom(collectionInterface)) { collection = new TreeSet<>(); } else if (SortedSet.class.isAssignableFrom(collectionInterface)) { collection = new TreeSet<>(); } else if (Set.class.isAssignableFrom(collectionInterface)) { collection = new HashSet<>(); } else if (BlockingDeque.class.isAssignableFrom(collectionInterface)) { collection = new LinkedBlockingDeque<>(); } else if (Deque.class.isAssignableFrom(collectionInterface)) { collection = new ArrayDeque<>(); } else if (TransferQueue.class.isAssignableFrom(collectionInterface)) { collection = new LinkedTransferQueue<>(); } else if (BlockingQueue.class.isAssignableFrom(collectionInterface)) { collection = new LinkedBlockingQueue<>(); } else if (Queue.class.isAssignableFrom(collectionInterface)) { collection = new LinkedList<>(); } return collection; } | ReflectionUtils { public static Collection<?> getEmptyImplementationForCollectionInterface(final Class<?> collectionInterface) { Collection<?> collection = new ArrayList<>(); if (List.class.isAssignableFrom(collectionInterface)) { collection = new ArrayList<>(); } else if (NavigableSet.class.isAssignableFrom(collectionInterface)) { collection = new TreeSet<>(); } else if (SortedSet.class.isAssignableFrom(collectionInterface)) { collection = new TreeSet<>(); } else if (Set.class.isAssignableFrom(collectionInterface)) { collection = new HashSet<>(); } else if (BlockingDeque.class.isAssignableFrom(collectionInterface)) { collection = new LinkedBlockingDeque<>(); } else if (Deque.class.isAssignableFrom(collectionInterface)) { collection = new ArrayDeque<>(); } else if (TransferQueue.class.isAssignableFrom(collectionInterface)) { collection = new LinkedTransferQueue<>(); } else if (BlockingQueue.class.isAssignableFrom(collectionInterface)) { collection = new LinkedBlockingQueue<>(); } else if (Queue.class.isAssignableFrom(collectionInterface)) { collection = new LinkedList<>(); } return collection; } } | ReflectionUtils { public static Collection<?> getEmptyImplementationForCollectionInterface(final Class<?> collectionInterface) { Collection<?> collection = new ArrayList<>(); if (List.class.isAssignableFrom(collectionInterface)) { collection = new ArrayList<>(); } else if (NavigableSet.class.isAssignableFrom(collectionInterface)) { collection = new TreeSet<>(); } else if (SortedSet.class.isAssignableFrom(collectionInterface)) { collection = new TreeSet<>(); } else if (Set.class.isAssignableFrom(collectionInterface)) { collection = new HashSet<>(); } else if (BlockingDeque.class.isAssignableFrom(collectionInterface)) { collection = new LinkedBlockingDeque<>(); } else if (Deque.class.isAssignableFrom(collectionInterface)) { collection = new ArrayDeque<>(); } else if (TransferQueue.class.isAssignableFrom(collectionInterface)) { collection = new LinkedTransferQueue<>(); } else if (BlockingQueue.class.isAssignableFrom(collectionInterface)) { collection = new LinkedBlockingQueue<>(); } else if (Queue.class.isAssignableFrom(collectionInterface)) { collection = new LinkedList<>(); } return collection; } private ReflectionUtils(); } | ReflectionUtils { public static Collection<?> getEmptyImplementationForCollectionInterface(final Class<?> collectionInterface) { Collection<?> collection = new ArrayList<>(); if (List.class.isAssignableFrom(collectionInterface)) { collection = new ArrayList<>(); } else if (NavigableSet.class.isAssignableFrom(collectionInterface)) { collection = new TreeSet<>(); } else if (SortedSet.class.isAssignableFrom(collectionInterface)) { collection = new TreeSet<>(); } else if (Set.class.isAssignableFrom(collectionInterface)) { collection = new HashSet<>(); } else if (BlockingDeque.class.isAssignableFrom(collectionInterface)) { collection = new LinkedBlockingDeque<>(); } else if (Deque.class.isAssignableFrom(collectionInterface)) { collection = new ArrayDeque<>(); } else if (TransferQueue.class.isAssignableFrom(collectionInterface)) { collection = new LinkedTransferQueue<>(); } else if (BlockingQueue.class.isAssignableFrom(collectionInterface)) { collection = new LinkedBlockingQueue<>(); } else if (Queue.class.isAssignableFrom(collectionInterface)) { collection = new LinkedList<>(); } return collection; } private ReflectionUtils(); @SuppressWarnings("unchecked") static Randomizer<T> asRandomizer(final Supplier<T> supplier); static List<Field> getDeclaredFields(T type); static List<Field> getInheritedFields(Class<?> type); static void setProperty(final Object object, final Field field, final Object value); static void setFieldValue(final Object object, final Field field, final Object value); static Object getFieldValue(final Object object, final Field field); static Class<?> getWrapperType(Class<?> primitiveType); static boolean isPrimitiveFieldWithDefaultValue(final Object object, final Field field); static boolean isStatic(final Field field); static boolean isInterface(final Class<?> type); static boolean isAbstract(final Class<T> type); static boolean isPublic(final Class<T> type); static boolean isArrayType(final Class<?> type); static boolean isEnumType(final Class<?> type); static boolean isCollectionType(final Class<?> type); static boolean isCollectionType(final Type type); static boolean isPopulatable(final Type type); static boolean isIntrospectable(final Class<?> type); static boolean isMapType(final Class<?> type); static boolean isJdkBuiltIn(final Class<?> type); static boolean isParameterizedType(final Type type); static boolean isWildcardType(final Type type); static boolean isTypeVariable(final Type type); static List<Class<?>> getPublicConcreteSubTypesOf(final Class<T> type); static List<Class<?>> filterSameParameterizedTypes(final List<Class<?>> types, final Type type); static T getAnnotation(Field field, Class<T> annotationType); static boolean isAnnotationPresent(Field field, Class<? extends Annotation> annotationType); static Collection<?> getEmptyImplementationForCollectionInterface(final Class<?> collectionInterface); static Collection<?> createEmptyCollectionForType(Class<?> fieldType, int initialSize); static Map<?, ?> getEmptyImplementationForMapInterface(final Class<?> mapInterface); static Optional<Method> getReadMethod(Field field); @SuppressWarnings("unchecked") static Randomizer<T> newInstance(final Class<T> type, final RandomizerArgument[] randomizerArguments); } | ReflectionUtils { public static Collection<?> getEmptyImplementationForCollectionInterface(final Class<?> collectionInterface) { Collection<?> collection = new ArrayList<>(); if (List.class.isAssignableFrom(collectionInterface)) { collection = new ArrayList<>(); } else if (NavigableSet.class.isAssignableFrom(collectionInterface)) { collection = new TreeSet<>(); } else if (SortedSet.class.isAssignableFrom(collectionInterface)) { collection = new TreeSet<>(); } else if (Set.class.isAssignableFrom(collectionInterface)) { collection = new HashSet<>(); } else if (BlockingDeque.class.isAssignableFrom(collectionInterface)) { collection = new LinkedBlockingDeque<>(); } else if (Deque.class.isAssignableFrom(collectionInterface)) { collection = new ArrayDeque<>(); } else if (TransferQueue.class.isAssignableFrom(collectionInterface)) { collection = new LinkedTransferQueue<>(); } else if (BlockingQueue.class.isAssignableFrom(collectionInterface)) { collection = new LinkedBlockingQueue<>(); } else if (Queue.class.isAssignableFrom(collectionInterface)) { collection = new LinkedList<>(); } return collection; } private ReflectionUtils(); @SuppressWarnings("unchecked") static Randomizer<T> asRandomizer(final Supplier<T> supplier); static List<Field> getDeclaredFields(T type); static List<Field> getInheritedFields(Class<?> type); static void setProperty(final Object object, final Field field, final Object value); static void setFieldValue(final Object object, final Field field, final Object value); static Object getFieldValue(final Object object, final Field field); static Class<?> getWrapperType(Class<?> primitiveType); static boolean isPrimitiveFieldWithDefaultValue(final Object object, final Field field); static boolean isStatic(final Field field); static boolean isInterface(final Class<?> type); static boolean isAbstract(final Class<T> type); static boolean isPublic(final Class<T> type); static boolean isArrayType(final Class<?> type); static boolean isEnumType(final Class<?> type); static boolean isCollectionType(final Class<?> type); static boolean isCollectionType(final Type type); static boolean isPopulatable(final Type type); static boolean isIntrospectable(final Class<?> type); static boolean isMapType(final Class<?> type); static boolean isJdkBuiltIn(final Class<?> type); static boolean isParameterizedType(final Type type); static boolean isWildcardType(final Type type); static boolean isTypeVariable(final Type type); static List<Class<?>> getPublicConcreteSubTypesOf(final Class<T> type); static List<Class<?>> filterSameParameterizedTypes(final List<Class<?>> types, final Type type); static T getAnnotation(Field field, Class<T> annotationType); static boolean isAnnotationPresent(Field field, Class<? extends Annotation> annotationType); static Collection<?> getEmptyImplementationForCollectionInterface(final Class<?> collectionInterface); static Collection<?> createEmptyCollectionForType(Class<?> fieldType, int initialSize); static Map<?, ?> getEmptyImplementationForMapInterface(final Class<?> mapInterface); static Optional<Method> getReadMethod(Field field); @SuppressWarnings("unchecked") static Randomizer<T> newInstance(final Class<T> type, final RandomizerArgument[] randomizerArguments); } |
@Test void createEmptyCollectionForArrayBlockingQueue() { Collection<?> collection = ReflectionUtils.createEmptyCollectionForType(ArrayBlockingQueue.class, INITIAL_CAPACITY); assertThat(collection).isInstanceOf(ArrayBlockingQueue.class).isEmpty(); assertThat(((ArrayBlockingQueue<?>) collection).remainingCapacity()).isEqualTo(INITIAL_CAPACITY); } | public static Collection<?> createEmptyCollectionForType(Class<?> fieldType, int initialSize) { rejectUnsupportedTypes(fieldType); Collection<?> collection; try { collection = (Collection<?>) fieldType.newInstance(); } catch (InstantiationException | IllegalAccessException e) { if (fieldType.equals(ArrayBlockingQueue.class)) { collection = new ArrayBlockingQueue<>(initialSize); } else { collection = (Collection<?>) new ObjenesisStd().newInstance(fieldType); } } return collection; } | ReflectionUtils { public static Collection<?> createEmptyCollectionForType(Class<?> fieldType, int initialSize) { rejectUnsupportedTypes(fieldType); Collection<?> collection; try { collection = (Collection<?>) fieldType.newInstance(); } catch (InstantiationException | IllegalAccessException e) { if (fieldType.equals(ArrayBlockingQueue.class)) { collection = new ArrayBlockingQueue<>(initialSize); } else { collection = (Collection<?>) new ObjenesisStd().newInstance(fieldType); } } return collection; } } | ReflectionUtils { public static Collection<?> createEmptyCollectionForType(Class<?> fieldType, int initialSize) { rejectUnsupportedTypes(fieldType); Collection<?> collection; try { collection = (Collection<?>) fieldType.newInstance(); } catch (InstantiationException | IllegalAccessException e) { if (fieldType.equals(ArrayBlockingQueue.class)) { collection = new ArrayBlockingQueue<>(initialSize); } else { collection = (Collection<?>) new ObjenesisStd().newInstance(fieldType); } } return collection; } private ReflectionUtils(); } | ReflectionUtils { public static Collection<?> createEmptyCollectionForType(Class<?> fieldType, int initialSize) { rejectUnsupportedTypes(fieldType); Collection<?> collection; try { collection = (Collection<?>) fieldType.newInstance(); } catch (InstantiationException | IllegalAccessException e) { if (fieldType.equals(ArrayBlockingQueue.class)) { collection = new ArrayBlockingQueue<>(initialSize); } else { collection = (Collection<?>) new ObjenesisStd().newInstance(fieldType); } } return collection; } private ReflectionUtils(); @SuppressWarnings("unchecked") static Randomizer<T> asRandomizer(final Supplier<T> supplier); static List<Field> getDeclaredFields(T type); static List<Field> getInheritedFields(Class<?> type); static void setProperty(final Object object, final Field field, final Object value); static void setFieldValue(final Object object, final Field field, final Object value); static Object getFieldValue(final Object object, final Field field); static Class<?> getWrapperType(Class<?> primitiveType); static boolean isPrimitiveFieldWithDefaultValue(final Object object, final Field field); static boolean isStatic(final Field field); static boolean isInterface(final Class<?> type); static boolean isAbstract(final Class<T> type); static boolean isPublic(final Class<T> type); static boolean isArrayType(final Class<?> type); static boolean isEnumType(final Class<?> type); static boolean isCollectionType(final Class<?> type); static boolean isCollectionType(final Type type); static boolean isPopulatable(final Type type); static boolean isIntrospectable(final Class<?> type); static boolean isMapType(final Class<?> type); static boolean isJdkBuiltIn(final Class<?> type); static boolean isParameterizedType(final Type type); static boolean isWildcardType(final Type type); static boolean isTypeVariable(final Type type); static List<Class<?>> getPublicConcreteSubTypesOf(final Class<T> type); static List<Class<?>> filterSameParameterizedTypes(final List<Class<?>> types, final Type type); static T getAnnotation(Field field, Class<T> annotationType); static boolean isAnnotationPresent(Field field, Class<? extends Annotation> annotationType); static Collection<?> getEmptyImplementationForCollectionInterface(final Class<?> collectionInterface); static Collection<?> createEmptyCollectionForType(Class<?> fieldType, int initialSize); static Map<?, ?> getEmptyImplementationForMapInterface(final Class<?> mapInterface); static Optional<Method> getReadMethod(Field field); @SuppressWarnings("unchecked") static Randomizer<T> newInstance(final Class<T> type, final RandomizerArgument[] randomizerArguments); } | ReflectionUtils { public static Collection<?> createEmptyCollectionForType(Class<?> fieldType, int initialSize) { rejectUnsupportedTypes(fieldType); Collection<?> collection; try { collection = (Collection<?>) fieldType.newInstance(); } catch (InstantiationException | IllegalAccessException e) { if (fieldType.equals(ArrayBlockingQueue.class)) { collection = new ArrayBlockingQueue<>(initialSize); } else { collection = (Collection<?>) new ObjenesisStd().newInstance(fieldType); } } return collection; } private ReflectionUtils(); @SuppressWarnings("unchecked") static Randomizer<T> asRandomizer(final Supplier<T> supplier); static List<Field> getDeclaredFields(T type); static List<Field> getInheritedFields(Class<?> type); static void setProperty(final Object object, final Field field, final Object value); static void setFieldValue(final Object object, final Field field, final Object value); static Object getFieldValue(final Object object, final Field field); static Class<?> getWrapperType(Class<?> primitiveType); static boolean isPrimitiveFieldWithDefaultValue(final Object object, final Field field); static boolean isStatic(final Field field); static boolean isInterface(final Class<?> type); static boolean isAbstract(final Class<T> type); static boolean isPublic(final Class<T> type); static boolean isArrayType(final Class<?> type); static boolean isEnumType(final Class<?> type); static boolean isCollectionType(final Class<?> type); static boolean isCollectionType(final Type type); static boolean isPopulatable(final Type type); static boolean isIntrospectable(final Class<?> type); static boolean isMapType(final Class<?> type); static boolean isJdkBuiltIn(final Class<?> type); static boolean isParameterizedType(final Type type); static boolean isWildcardType(final Type type); static boolean isTypeVariable(final Type type); static List<Class<?>> getPublicConcreteSubTypesOf(final Class<T> type); static List<Class<?>> filterSameParameterizedTypes(final List<Class<?>> types, final Type type); static T getAnnotation(Field field, Class<T> annotationType); static boolean isAnnotationPresent(Field field, Class<? extends Annotation> annotationType); static Collection<?> getEmptyImplementationForCollectionInterface(final Class<?> collectionInterface); static Collection<?> createEmptyCollectionForType(Class<?> fieldType, int initialSize); static Map<?, ?> getEmptyImplementationForMapInterface(final Class<?> mapInterface); static Optional<Method> getReadMethod(Field field); @SuppressWarnings("unchecked") static Randomizer<T> newInstance(final Class<T> type, final RandomizerArgument[] randomizerArguments); } |
@Test void synchronousQueueShouldBeRejected() { assertThatThrownBy(() -> ReflectionUtils.createEmptyCollectionForType(SynchronousQueue.class, INITIAL_CAPACITY)).isInstanceOf(UnsupportedOperationException.class); } | public static Collection<?> createEmptyCollectionForType(Class<?> fieldType, int initialSize) { rejectUnsupportedTypes(fieldType); Collection<?> collection; try { collection = (Collection<?>) fieldType.newInstance(); } catch (InstantiationException | IllegalAccessException e) { if (fieldType.equals(ArrayBlockingQueue.class)) { collection = new ArrayBlockingQueue<>(initialSize); } else { collection = (Collection<?>) new ObjenesisStd().newInstance(fieldType); } } return collection; } | ReflectionUtils { public static Collection<?> createEmptyCollectionForType(Class<?> fieldType, int initialSize) { rejectUnsupportedTypes(fieldType); Collection<?> collection; try { collection = (Collection<?>) fieldType.newInstance(); } catch (InstantiationException | IllegalAccessException e) { if (fieldType.equals(ArrayBlockingQueue.class)) { collection = new ArrayBlockingQueue<>(initialSize); } else { collection = (Collection<?>) new ObjenesisStd().newInstance(fieldType); } } return collection; } } | ReflectionUtils { public static Collection<?> createEmptyCollectionForType(Class<?> fieldType, int initialSize) { rejectUnsupportedTypes(fieldType); Collection<?> collection; try { collection = (Collection<?>) fieldType.newInstance(); } catch (InstantiationException | IllegalAccessException e) { if (fieldType.equals(ArrayBlockingQueue.class)) { collection = new ArrayBlockingQueue<>(initialSize); } else { collection = (Collection<?>) new ObjenesisStd().newInstance(fieldType); } } return collection; } private ReflectionUtils(); } | ReflectionUtils { public static Collection<?> createEmptyCollectionForType(Class<?> fieldType, int initialSize) { rejectUnsupportedTypes(fieldType); Collection<?> collection; try { collection = (Collection<?>) fieldType.newInstance(); } catch (InstantiationException | IllegalAccessException e) { if (fieldType.equals(ArrayBlockingQueue.class)) { collection = new ArrayBlockingQueue<>(initialSize); } else { collection = (Collection<?>) new ObjenesisStd().newInstance(fieldType); } } return collection; } private ReflectionUtils(); @SuppressWarnings("unchecked") static Randomizer<T> asRandomizer(final Supplier<T> supplier); static List<Field> getDeclaredFields(T type); static List<Field> getInheritedFields(Class<?> type); static void setProperty(final Object object, final Field field, final Object value); static void setFieldValue(final Object object, final Field field, final Object value); static Object getFieldValue(final Object object, final Field field); static Class<?> getWrapperType(Class<?> primitiveType); static boolean isPrimitiveFieldWithDefaultValue(final Object object, final Field field); static boolean isStatic(final Field field); static boolean isInterface(final Class<?> type); static boolean isAbstract(final Class<T> type); static boolean isPublic(final Class<T> type); static boolean isArrayType(final Class<?> type); static boolean isEnumType(final Class<?> type); static boolean isCollectionType(final Class<?> type); static boolean isCollectionType(final Type type); static boolean isPopulatable(final Type type); static boolean isIntrospectable(final Class<?> type); static boolean isMapType(final Class<?> type); static boolean isJdkBuiltIn(final Class<?> type); static boolean isParameterizedType(final Type type); static boolean isWildcardType(final Type type); static boolean isTypeVariable(final Type type); static List<Class<?>> getPublicConcreteSubTypesOf(final Class<T> type); static List<Class<?>> filterSameParameterizedTypes(final List<Class<?>> types, final Type type); static T getAnnotation(Field field, Class<T> annotationType); static boolean isAnnotationPresent(Field field, Class<? extends Annotation> annotationType); static Collection<?> getEmptyImplementationForCollectionInterface(final Class<?> collectionInterface); static Collection<?> createEmptyCollectionForType(Class<?> fieldType, int initialSize); static Map<?, ?> getEmptyImplementationForMapInterface(final Class<?> mapInterface); static Optional<Method> getReadMethod(Field field); @SuppressWarnings("unchecked") static Randomizer<T> newInstance(final Class<T> type, final RandomizerArgument[] randomizerArguments); } | ReflectionUtils { public static Collection<?> createEmptyCollectionForType(Class<?> fieldType, int initialSize) { rejectUnsupportedTypes(fieldType); Collection<?> collection; try { collection = (Collection<?>) fieldType.newInstance(); } catch (InstantiationException | IllegalAccessException e) { if (fieldType.equals(ArrayBlockingQueue.class)) { collection = new ArrayBlockingQueue<>(initialSize); } else { collection = (Collection<?>) new ObjenesisStd().newInstance(fieldType); } } return collection; } private ReflectionUtils(); @SuppressWarnings("unchecked") static Randomizer<T> asRandomizer(final Supplier<T> supplier); static List<Field> getDeclaredFields(T type); static List<Field> getInheritedFields(Class<?> type); static void setProperty(final Object object, final Field field, final Object value); static void setFieldValue(final Object object, final Field field, final Object value); static Object getFieldValue(final Object object, final Field field); static Class<?> getWrapperType(Class<?> primitiveType); static boolean isPrimitiveFieldWithDefaultValue(final Object object, final Field field); static boolean isStatic(final Field field); static boolean isInterface(final Class<?> type); static boolean isAbstract(final Class<T> type); static boolean isPublic(final Class<T> type); static boolean isArrayType(final Class<?> type); static boolean isEnumType(final Class<?> type); static boolean isCollectionType(final Class<?> type); static boolean isCollectionType(final Type type); static boolean isPopulatable(final Type type); static boolean isIntrospectable(final Class<?> type); static boolean isMapType(final Class<?> type); static boolean isJdkBuiltIn(final Class<?> type); static boolean isParameterizedType(final Type type); static boolean isWildcardType(final Type type); static boolean isTypeVariable(final Type type); static List<Class<?>> getPublicConcreteSubTypesOf(final Class<T> type); static List<Class<?>> filterSameParameterizedTypes(final List<Class<?>> types, final Type type); static T getAnnotation(Field field, Class<T> annotationType); static boolean isAnnotationPresent(Field field, Class<? extends Annotation> annotationType); static Collection<?> getEmptyImplementationForCollectionInterface(final Class<?> collectionInterface); static Collection<?> createEmptyCollectionForType(Class<?> fieldType, int initialSize); static Map<?, ?> getEmptyImplementationForMapInterface(final Class<?> mapInterface); static Optional<Method> getReadMethod(Field field); @SuppressWarnings("unchecked") static Randomizer<T> newInstance(final Class<T> type, final RandomizerArgument[] randomizerArguments); } |
@Test void testGetDeclaredFields() { BigDecimal javaVersion = new BigDecimal(System.getProperty("java.specification.version")); if (javaVersion.compareTo(new BigDecimal("12")) >= 0) { assertThat(ReflectionUtils.getDeclaredFields(Street.class)).hasSize(21); } else if (javaVersion.compareTo(new BigDecimal("9")) >= 0) { assertThat(ReflectionUtils.getDeclaredFields(Street.class)).hasSize(22); } else { assertThat(ReflectionUtils.getDeclaredFields(Street.class)).hasSize(20); } } | public static <T> List<Field> getDeclaredFields(T type) { return new ArrayList<>(asList(type.getClass().getDeclaredFields())); } | ReflectionUtils { public static <T> List<Field> getDeclaredFields(T type) { return new ArrayList<>(asList(type.getClass().getDeclaredFields())); } } | ReflectionUtils { public static <T> List<Field> getDeclaredFields(T type) { return new ArrayList<>(asList(type.getClass().getDeclaredFields())); } private ReflectionUtils(); } | ReflectionUtils { public static <T> List<Field> getDeclaredFields(T type) { return new ArrayList<>(asList(type.getClass().getDeclaredFields())); } private ReflectionUtils(); @SuppressWarnings("unchecked") static Randomizer<T> asRandomizer(final Supplier<T> supplier); static List<Field> getDeclaredFields(T type); static List<Field> getInheritedFields(Class<?> type); static void setProperty(final Object object, final Field field, final Object value); static void setFieldValue(final Object object, final Field field, final Object value); static Object getFieldValue(final Object object, final Field field); static Class<?> getWrapperType(Class<?> primitiveType); static boolean isPrimitiveFieldWithDefaultValue(final Object object, final Field field); static boolean isStatic(final Field field); static boolean isInterface(final Class<?> type); static boolean isAbstract(final Class<T> type); static boolean isPublic(final Class<T> type); static boolean isArrayType(final Class<?> type); static boolean isEnumType(final Class<?> type); static boolean isCollectionType(final Class<?> type); static boolean isCollectionType(final Type type); static boolean isPopulatable(final Type type); static boolean isIntrospectable(final Class<?> type); static boolean isMapType(final Class<?> type); static boolean isJdkBuiltIn(final Class<?> type); static boolean isParameterizedType(final Type type); static boolean isWildcardType(final Type type); static boolean isTypeVariable(final Type type); static List<Class<?>> getPublicConcreteSubTypesOf(final Class<T> type); static List<Class<?>> filterSameParameterizedTypes(final List<Class<?>> types, final Type type); static T getAnnotation(Field field, Class<T> annotationType); static boolean isAnnotationPresent(Field field, Class<? extends Annotation> annotationType); static Collection<?> getEmptyImplementationForCollectionInterface(final Class<?> collectionInterface); static Collection<?> createEmptyCollectionForType(Class<?> fieldType, int initialSize); static Map<?, ?> getEmptyImplementationForMapInterface(final Class<?> mapInterface); static Optional<Method> getReadMethod(Field field); @SuppressWarnings("unchecked") static Randomizer<T> newInstance(final Class<T> type, final RandomizerArgument[] randomizerArguments); } | ReflectionUtils { public static <T> List<Field> getDeclaredFields(T type) { return new ArrayList<>(asList(type.getClass().getDeclaredFields())); } private ReflectionUtils(); @SuppressWarnings("unchecked") static Randomizer<T> asRandomizer(final Supplier<T> supplier); static List<Field> getDeclaredFields(T type); static List<Field> getInheritedFields(Class<?> type); static void setProperty(final Object object, final Field field, final Object value); static void setFieldValue(final Object object, final Field field, final Object value); static Object getFieldValue(final Object object, final Field field); static Class<?> getWrapperType(Class<?> primitiveType); static boolean isPrimitiveFieldWithDefaultValue(final Object object, final Field field); static boolean isStatic(final Field field); static boolean isInterface(final Class<?> type); static boolean isAbstract(final Class<T> type); static boolean isPublic(final Class<T> type); static boolean isArrayType(final Class<?> type); static boolean isEnumType(final Class<?> type); static boolean isCollectionType(final Class<?> type); static boolean isCollectionType(final Type type); static boolean isPopulatable(final Type type); static boolean isIntrospectable(final Class<?> type); static boolean isMapType(final Class<?> type); static boolean isJdkBuiltIn(final Class<?> type); static boolean isParameterizedType(final Type type); static boolean isWildcardType(final Type type); static boolean isTypeVariable(final Type type); static List<Class<?>> getPublicConcreteSubTypesOf(final Class<T> type); static List<Class<?>> filterSameParameterizedTypes(final List<Class<?>> types, final Type type); static T getAnnotation(Field field, Class<T> annotationType); static boolean isAnnotationPresent(Field field, Class<? extends Annotation> annotationType); static Collection<?> getEmptyImplementationForCollectionInterface(final Class<?> collectionInterface); static Collection<?> createEmptyCollectionForType(Class<?> fieldType, int initialSize); static Map<?, ?> getEmptyImplementationForMapInterface(final Class<?> mapInterface); static Optional<Method> getReadMethod(Field field); @SuppressWarnings("unchecked") static Randomizer<T> newInstance(final Class<T> type, final RandomizerArgument[] randomizerArguments); } |
@Test void delayQueueShouldBeRejected() { assertThatThrownBy(() -> ReflectionUtils.createEmptyCollectionForType(DelayQueue.class, INITIAL_CAPACITY)).isInstanceOf(UnsupportedOperationException.class); } | public static Collection<?> createEmptyCollectionForType(Class<?> fieldType, int initialSize) { rejectUnsupportedTypes(fieldType); Collection<?> collection; try { collection = (Collection<?>) fieldType.newInstance(); } catch (InstantiationException | IllegalAccessException e) { if (fieldType.equals(ArrayBlockingQueue.class)) { collection = new ArrayBlockingQueue<>(initialSize); } else { collection = (Collection<?>) new ObjenesisStd().newInstance(fieldType); } } return collection; } | ReflectionUtils { public static Collection<?> createEmptyCollectionForType(Class<?> fieldType, int initialSize) { rejectUnsupportedTypes(fieldType); Collection<?> collection; try { collection = (Collection<?>) fieldType.newInstance(); } catch (InstantiationException | IllegalAccessException e) { if (fieldType.equals(ArrayBlockingQueue.class)) { collection = new ArrayBlockingQueue<>(initialSize); } else { collection = (Collection<?>) new ObjenesisStd().newInstance(fieldType); } } return collection; } } | ReflectionUtils { public static Collection<?> createEmptyCollectionForType(Class<?> fieldType, int initialSize) { rejectUnsupportedTypes(fieldType); Collection<?> collection; try { collection = (Collection<?>) fieldType.newInstance(); } catch (InstantiationException | IllegalAccessException e) { if (fieldType.equals(ArrayBlockingQueue.class)) { collection = new ArrayBlockingQueue<>(initialSize); } else { collection = (Collection<?>) new ObjenesisStd().newInstance(fieldType); } } return collection; } private ReflectionUtils(); } | ReflectionUtils { public static Collection<?> createEmptyCollectionForType(Class<?> fieldType, int initialSize) { rejectUnsupportedTypes(fieldType); Collection<?> collection; try { collection = (Collection<?>) fieldType.newInstance(); } catch (InstantiationException | IllegalAccessException e) { if (fieldType.equals(ArrayBlockingQueue.class)) { collection = new ArrayBlockingQueue<>(initialSize); } else { collection = (Collection<?>) new ObjenesisStd().newInstance(fieldType); } } return collection; } private ReflectionUtils(); @SuppressWarnings("unchecked") static Randomizer<T> asRandomizer(final Supplier<T> supplier); static List<Field> getDeclaredFields(T type); static List<Field> getInheritedFields(Class<?> type); static void setProperty(final Object object, final Field field, final Object value); static void setFieldValue(final Object object, final Field field, final Object value); static Object getFieldValue(final Object object, final Field field); static Class<?> getWrapperType(Class<?> primitiveType); static boolean isPrimitiveFieldWithDefaultValue(final Object object, final Field field); static boolean isStatic(final Field field); static boolean isInterface(final Class<?> type); static boolean isAbstract(final Class<T> type); static boolean isPublic(final Class<T> type); static boolean isArrayType(final Class<?> type); static boolean isEnumType(final Class<?> type); static boolean isCollectionType(final Class<?> type); static boolean isCollectionType(final Type type); static boolean isPopulatable(final Type type); static boolean isIntrospectable(final Class<?> type); static boolean isMapType(final Class<?> type); static boolean isJdkBuiltIn(final Class<?> type); static boolean isParameterizedType(final Type type); static boolean isWildcardType(final Type type); static boolean isTypeVariable(final Type type); static List<Class<?>> getPublicConcreteSubTypesOf(final Class<T> type); static List<Class<?>> filterSameParameterizedTypes(final List<Class<?>> types, final Type type); static T getAnnotation(Field field, Class<T> annotationType); static boolean isAnnotationPresent(Field field, Class<? extends Annotation> annotationType); static Collection<?> getEmptyImplementationForCollectionInterface(final Class<?> collectionInterface); static Collection<?> createEmptyCollectionForType(Class<?> fieldType, int initialSize); static Map<?, ?> getEmptyImplementationForMapInterface(final Class<?> mapInterface); static Optional<Method> getReadMethod(Field field); @SuppressWarnings("unchecked") static Randomizer<T> newInstance(final Class<T> type, final RandomizerArgument[] randomizerArguments); } | ReflectionUtils { public static Collection<?> createEmptyCollectionForType(Class<?> fieldType, int initialSize) { rejectUnsupportedTypes(fieldType); Collection<?> collection; try { collection = (Collection<?>) fieldType.newInstance(); } catch (InstantiationException | IllegalAccessException e) { if (fieldType.equals(ArrayBlockingQueue.class)) { collection = new ArrayBlockingQueue<>(initialSize); } else { collection = (Collection<?>) new ObjenesisStd().newInstance(fieldType); } } return collection; } private ReflectionUtils(); @SuppressWarnings("unchecked") static Randomizer<T> asRandomizer(final Supplier<T> supplier); static List<Field> getDeclaredFields(T type); static List<Field> getInheritedFields(Class<?> type); static void setProperty(final Object object, final Field field, final Object value); static void setFieldValue(final Object object, final Field field, final Object value); static Object getFieldValue(final Object object, final Field field); static Class<?> getWrapperType(Class<?> primitiveType); static boolean isPrimitiveFieldWithDefaultValue(final Object object, final Field field); static boolean isStatic(final Field field); static boolean isInterface(final Class<?> type); static boolean isAbstract(final Class<T> type); static boolean isPublic(final Class<T> type); static boolean isArrayType(final Class<?> type); static boolean isEnumType(final Class<?> type); static boolean isCollectionType(final Class<?> type); static boolean isCollectionType(final Type type); static boolean isPopulatable(final Type type); static boolean isIntrospectable(final Class<?> type); static boolean isMapType(final Class<?> type); static boolean isJdkBuiltIn(final Class<?> type); static boolean isParameterizedType(final Type type); static boolean isWildcardType(final Type type); static boolean isTypeVariable(final Type type); static List<Class<?>> getPublicConcreteSubTypesOf(final Class<T> type); static List<Class<?>> filterSameParameterizedTypes(final List<Class<?>> types, final Type type); static T getAnnotation(Field field, Class<T> annotationType); static boolean isAnnotationPresent(Field field, Class<? extends Annotation> annotationType); static Collection<?> getEmptyImplementationForCollectionInterface(final Class<?> collectionInterface); static Collection<?> createEmptyCollectionForType(Class<?> fieldType, int initialSize); static Map<?, ?> getEmptyImplementationForMapInterface(final Class<?> mapInterface); static Optional<Method> getReadMethod(Field field); @SuppressWarnings("unchecked") static Randomizer<T> newInstance(final Class<T> type, final RandomizerArgument[] randomizerArguments); } |
@Test void getEmptyImplementationForMapInterface() { Map<?, ?> map = ReflectionUtils.getEmptyImplementationForMapInterface(SortedMap.class); assertThat(map).isInstanceOf(TreeMap.class).isEmpty(); } | public static Map<?, ?> getEmptyImplementationForMapInterface(final Class<?> mapInterface) { Map<?, ?> map = new HashMap<>(); if (ConcurrentNavigableMap.class.isAssignableFrom(mapInterface)) { map = new ConcurrentSkipListMap<>(); } else if (ConcurrentMap.class.isAssignableFrom(mapInterface)) { map = new ConcurrentHashMap<>(); } else if (NavigableMap.class.isAssignableFrom(mapInterface)) { map = new TreeMap<>(); } else if (SortedMap.class.isAssignableFrom(mapInterface)) { map = new TreeMap<>(); } return map; } | ReflectionUtils { public static Map<?, ?> getEmptyImplementationForMapInterface(final Class<?> mapInterface) { Map<?, ?> map = new HashMap<>(); if (ConcurrentNavigableMap.class.isAssignableFrom(mapInterface)) { map = new ConcurrentSkipListMap<>(); } else if (ConcurrentMap.class.isAssignableFrom(mapInterface)) { map = new ConcurrentHashMap<>(); } else if (NavigableMap.class.isAssignableFrom(mapInterface)) { map = new TreeMap<>(); } else if (SortedMap.class.isAssignableFrom(mapInterface)) { map = new TreeMap<>(); } return map; } } | ReflectionUtils { public static Map<?, ?> getEmptyImplementationForMapInterface(final Class<?> mapInterface) { Map<?, ?> map = new HashMap<>(); if (ConcurrentNavigableMap.class.isAssignableFrom(mapInterface)) { map = new ConcurrentSkipListMap<>(); } else if (ConcurrentMap.class.isAssignableFrom(mapInterface)) { map = new ConcurrentHashMap<>(); } else if (NavigableMap.class.isAssignableFrom(mapInterface)) { map = new TreeMap<>(); } else if (SortedMap.class.isAssignableFrom(mapInterface)) { map = new TreeMap<>(); } return map; } private ReflectionUtils(); } | ReflectionUtils { public static Map<?, ?> getEmptyImplementationForMapInterface(final Class<?> mapInterface) { Map<?, ?> map = new HashMap<>(); if (ConcurrentNavigableMap.class.isAssignableFrom(mapInterface)) { map = new ConcurrentSkipListMap<>(); } else if (ConcurrentMap.class.isAssignableFrom(mapInterface)) { map = new ConcurrentHashMap<>(); } else if (NavigableMap.class.isAssignableFrom(mapInterface)) { map = new TreeMap<>(); } else if (SortedMap.class.isAssignableFrom(mapInterface)) { map = new TreeMap<>(); } return map; } private ReflectionUtils(); @SuppressWarnings("unchecked") static Randomizer<T> asRandomizer(final Supplier<T> supplier); static List<Field> getDeclaredFields(T type); static List<Field> getInheritedFields(Class<?> type); static void setProperty(final Object object, final Field field, final Object value); static void setFieldValue(final Object object, final Field field, final Object value); static Object getFieldValue(final Object object, final Field field); static Class<?> getWrapperType(Class<?> primitiveType); static boolean isPrimitiveFieldWithDefaultValue(final Object object, final Field field); static boolean isStatic(final Field field); static boolean isInterface(final Class<?> type); static boolean isAbstract(final Class<T> type); static boolean isPublic(final Class<T> type); static boolean isArrayType(final Class<?> type); static boolean isEnumType(final Class<?> type); static boolean isCollectionType(final Class<?> type); static boolean isCollectionType(final Type type); static boolean isPopulatable(final Type type); static boolean isIntrospectable(final Class<?> type); static boolean isMapType(final Class<?> type); static boolean isJdkBuiltIn(final Class<?> type); static boolean isParameterizedType(final Type type); static boolean isWildcardType(final Type type); static boolean isTypeVariable(final Type type); static List<Class<?>> getPublicConcreteSubTypesOf(final Class<T> type); static List<Class<?>> filterSameParameterizedTypes(final List<Class<?>> types, final Type type); static T getAnnotation(Field field, Class<T> annotationType); static boolean isAnnotationPresent(Field field, Class<? extends Annotation> annotationType); static Collection<?> getEmptyImplementationForCollectionInterface(final Class<?> collectionInterface); static Collection<?> createEmptyCollectionForType(Class<?> fieldType, int initialSize); static Map<?, ?> getEmptyImplementationForMapInterface(final Class<?> mapInterface); static Optional<Method> getReadMethod(Field field); @SuppressWarnings("unchecked") static Randomizer<T> newInstance(final Class<T> type, final RandomizerArgument[] randomizerArguments); } | ReflectionUtils { public static Map<?, ?> getEmptyImplementationForMapInterface(final Class<?> mapInterface) { Map<?, ?> map = new HashMap<>(); if (ConcurrentNavigableMap.class.isAssignableFrom(mapInterface)) { map = new ConcurrentSkipListMap<>(); } else if (ConcurrentMap.class.isAssignableFrom(mapInterface)) { map = new ConcurrentHashMap<>(); } else if (NavigableMap.class.isAssignableFrom(mapInterface)) { map = new TreeMap<>(); } else if (SortedMap.class.isAssignableFrom(mapInterface)) { map = new TreeMap<>(); } return map; } private ReflectionUtils(); @SuppressWarnings("unchecked") static Randomizer<T> asRandomizer(final Supplier<T> supplier); static List<Field> getDeclaredFields(T type); static List<Field> getInheritedFields(Class<?> type); static void setProperty(final Object object, final Field field, final Object value); static void setFieldValue(final Object object, final Field field, final Object value); static Object getFieldValue(final Object object, final Field field); static Class<?> getWrapperType(Class<?> primitiveType); static boolean isPrimitiveFieldWithDefaultValue(final Object object, final Field field); static boolean isStatic(final Field field); static boolean isInterface(final Class<?> type); static boolean isAbstract(final Class<T> type); static boolean isPublic(final Class<T> type); static boolean isArrayType(final Class<?> type); static boolean isEnumType(final Class<?> type); static boolean isCollectionType(final Class<?> type); static boolean isCollectionType(final Type type); static boolean isPopulatable(final Type type); static boolean isIntrospectable(final Class<?> type); static boolean isMapType(final Class<?> type); static boolean isJdkBuiltIn(final Class<?> type); static boolean isParameterizedType(final Type type); static boolean isWildcardType(final Type type); static boolean isTypeVariable(final Type type); static List<Class<?>> getPublicConcreteSubTypesOf(final Class<T> type); static List<Class<?>> filterSameParameterizedTypes(final List<Class<?>> types, final Type type); static T getAnnotation(Field field, Class<T> annotationType); static boolean isAnnotationPresent(Field field, Class<? extends Annotation> annotationType); static Collection<?> getEmptyImplementationForCollectionInterface(final Class<?> collectionInterface); static Collection<?> createEmptyCollectionForType(Class<?> fieldType, int initialSize); static Map<?, ?> getEmptyImplementationForMapInterface(final Class<?> mapInterface); static Optional<Method> getReadMethod(Field field); @SuppressWarnings("unchecked") static Randomizer<T> newInstance(final Class<T> type, final RandomizerArgument[] randomizerArguments); } |
@Test void testRandomElementOf() { String[] elements = {"foo", "bar"}; String element = CollectionUtils.randomElementOf(asList(elements)); assertThat(element).isIn(elements); } | public static <T> T randomElementOf(final List<T> list) { if (list.isEmpty()) { return null; } return list.get(nextInt(0, list.size())); } | CollectionUtils { public static <T> T randomElementOf(final List<T> list) { if (list.isEmpty()) { return null; } return list.get(nextInt(0, list.size())); } } | CollectionUtils { public static <T> T randomElementOf(final List<T> list) { if (list.isEmpty()) { return null; } return list.get(nextInt(0, list.size())); } private CollectionUtils(); } | CollectionUtils { public static <T> T randomElementOf(final List<T> list) { if (list.isEmpty()) { return null; } return list.get(nextInt(0, list.size())); } private CollectionUtils(); static T randomElementOf(final List<T> list); } | CollectionUtils { public static <T> T randomElementOf(final List<T> list) { if (list.isEmpty()) { return null; } return list.get(nextInt(0, list.size())); } private CollectionUtils(); static T randomElementOf(final List<T> list); } |
@Test void generatedBeansShouldBeCorrectlyPopulated() { Person person = easyRandom.nextObject(Person.class); validatePerson(person); } | public <T> T nextObject(final Class<T> type) { return doPopulateBean(type, new RandomizationContext(type, parameters)); } | EasyRandom extends Random { public <T> T nextObject(final Class<T> type) { return doPopulateBean(type, new RandomizationContext(type, parameters)); } } | EasyRandom extends Random { public <T> T nextObject(final Class<T> type) { return doPopulateBean(type, new RandomizationContext(type, parameters)); } EasyRandom(); EasyRandom(final EasyRandomParameters easyRandomParameters); } | EasyRandom extends Random { public <T> T nextObject(final Class<T> type) { return doPopulateBean(type, new RandomizationContext(type, parameters)); } EasyRandom(); EasyRandom(final EasyRandomParameters easyRandomParameters); T nextObject(final Class<T> type); Stream<T> objects(final Class<T> type, final int streamSize); } | EasyRandom extends Random { public <T> T nextObject(final Class<T> type) { return doPopulateBean(type, new RandomizationContext(type, parameters)); } EasyRandom(); EasyRandom(final EasyRandomParameters easyRandomParameters); T nextObject(final Class<T> type); Stream<T> objects(final Class<T> type, final int streamSize); } |
@Test void shouldFailIfSetterInvocationFails() { EasyRandom easyRandom = new EasyRandom(); Throwable thrown = catchThrowable(() -> easyRandom.nextObject(Salary.class)); assertThat(thrown).isInstanceOf(ObjectCreationException.class) .hasMessageContaining("Unable to create a random instance of type class org.jeasy.random.beans.Salary"); Throwable cause = thrown.getCause(); assertThat(cause).isInstanceOf(ObjectCreationException.class) .hasMessageContaining("Unable to invoke setter for field amount of class org.jeasy.random.beans.Salary"); Throwable rootCause = cause.getCause(); assertThat(rootCause).isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("Amount must be positive"); } | public <T> T nextObject(final Class<T> type) { return doPopulateBean(type, new RandomizationContext(type, parameters)); } | EasyRandom extends Random { public <T> T nextObject(final Class<T> type) { return doPopulateBean(type, new RandomizationContext(type, parameters)); } } | EasyRandom extends Random { public <T> T nextObject(final Class<T> type) { return doPopulateBean(type, new RandomizationContext(type, parameters)); } EasyRandom(); EasyRandom(final EasyRandomParameters easyRandomParameters); } | EasyRandom extends Random { public <T> T nextObject(final Class<T> type) { return doPopulateBean(type, new RandomizationContext(type, parameters)); } EasyRandom(); EasyRandom(final EasyRandomParameters easyRandomParameters); T nextObject(final Class<T> type); Stream<T> objects(final Class<T> type, final int streamSize); } | EasyRandom extends Random { public <T> T nextObject(final Class<T> type) { return doPopulateBean(type, new RandomizationContext(type, parameters)); } EasyRandom(); EasyRandom(final EasyRandomParameters easyRandomParameters); T nextObject(final Class<T> type); Stream<T> objects(final Class<T> type, final int streamSize); } |
@Test void finalFieldsShouldBePopulated() { Person person = easyRandom.nextObject(Person.class); assertThat(person).isNotNull(); assertThat(person.getId()).isNotNull(); } | public <T> T nextObject(final Class<T> type) { return doPopulateBean(type, new RandomizationContext(type, parameters)); } | EasyRandom extends Random { public <T> T nextObject(final Class<T> type) { return doPopulateBean(type, new RandomizationContext(type, parameters)); } } | EasyRandom extends Random { public <T> T nextObject(final Class<T> type) { return doPopulateBean(type, new RandomizationContext(type, parameters)); } EasyRandom(); EasyRandom(final EasyRandomParameters easyRandomParameters); } | EasyRandom extends Random { public <T> T nextObject(final Class<T> type) { return doPopulateBean(type, new RandomizationContext(type, parameters)); } EasyRandom(); EasyRandom(final EasyRandomParameters easyRandomParameters); T nextObject(final Class<T> type); Stream<T> objects(final Class<T> type, final int streamSize); } | EasyRandom extends Random { public <T> T nextObject(final Class<T> type) { return doPopulateBean(type, new RandomizationContext(type, parameters)); } EasyRandom(); EasyRandom(final EasyRandomParameters easyRandomParameters); T nextObject(final Class<T> type); Stream<T> objects(final Class<T> type, final int streamSize); } |
@Test void staticFieldsShouldNotBePopulated() { try { Human human = easyRandom.nextObject(Human.class); assertThat(human).isNotNull(); } catch (Exception e) { fail("Should be able to populate types with private static final fields.", e); } } | public <T> T nextObject(final Class<T> type) { return doPopulateBean(type, new RandomizationContext(type, parameters)); } | EasyRandom extends Random { public <T> T nextObject(final Class<T> type) { return doPopulateBean(type, new RandomizationContext(type, parameters)); } } | EasyRandom extends Random { public <T> T nextObject(final Class<T> type) { return doPopulateBean(type, new RandomizationContext(type, parameters)); } EasyRandom(); EasyRandom(final EasyRandomParameters easyRandomParameters); } | EasyRandom extends Random { public <T> T nextObject(final Class<T> type) { return doPopulateBean(type, new RandomizationContext(type, parameters)); } EasyRandom(); EasyRandom(final EasyRandomParameters easyRandomParameters); T nextObject(final Class<T> type); Stream<T> objects(final Class<T> type, final int streamSize); } | EasyRandom extends Random { public <T> T nextObject(final Class<T> type) { return doPopulateBean(type, new RandomizationContext(type, parameters)); } EasyRandom(); EasyRandom(final EasyRandomParameters easyRandomParameters); T nextObject(final Class<T> type); Stream<T> objects(final Class<T> type, final int streamSize); } |
@Test void immutableBeansShouldBePopulated() { final ImmutableBean immutableBean = easyRandom.nextObject(ImmutableBean.class); assertThat(immutableBean).hasNoNullFieldsOrProperties(); } | public <T> T nextObject(final Class<T> type) { return doPopulateBean(type, new RandomizationContext(type, parameters)); } | EasyRandom extends Random { public <T> T nextObject(final Class<T> type) { return doPopulateBean(type, new RandomizationContext(type, parameters)); } } | EasyRandom extends Random { public <T> T nextObject(final Class<T> type) { return doPopulateBean(type, new RandomizationContext(type, parameters)); } EasyRandom(); EasyRandom(final EasyRandomParameters easyRandomParameters); } | EasyRandom extends Random { public <T> T nextObject(final Class<T> type) { return doPopulateBean(type, new RandomizationContext(type, parameters)); } EasyRandom(); EasyRandom(final EasyRandomParameters easyRandomParameters); T nextObject(final Class<T> type); Stream<T> objects(final Class<T> type, final int streamSize); } | EasyRandom extends Random { public <T> T nextObject(final Class<T> type) { return doPopulateBean(type, new RandomizationContext(type, parameters)); } EasyRandom(); EasyRandom(final EasyRandomParameters easyRandomParameters); T nextObject(final Class<T> type); Stream<T> objects(final Class<T> type, final int streamSize); } |
Subsets and Splits